home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / BOCOLE.PAK / OLEDEBUG.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  8KB  |  240 lines

  1. //
  2. //**************************************************************************
  3. //
  4. // OleDebug.h -- Some debugging utilities for getting symbolic output
  5. //               from the OLE2 error codes and enums
  6. //
  7. // Copyright (c) 1993,94 by Borland International, Inc. All rights reserved
  8. //
  9. //**************************************************************************
  10.  
  11. #ifndef _OLEDEBUG_H
  12. #define _OLEDEBUG_H
  13.  
  14. #undef OLEDBG
  15. // to enable the OLEDBG stuff, #define OLEDBG and add oledebug.obj in
  16. // the makefile.
  17.  
  18. class IUnknownWatcher : public IUnknown 
  19. {
  20.     public:
  21.  
  22.         IUnknownWatcher( IUnknown *Data, char *Name );
  23.         // IUnknown
  24.         virtual HRESULT _IFUNC QueryInterface(REFIID iid, void FAR* FAR* pif);
  25.         virtual ULONG _IFUNC AddRef();
  26.         virtual ULONG _IFUNC Release();
  27.  
  28.     protected:
  29.  
  30.         int      nRef();
  31.         IUnknown *pUnk;
  32.         char     Name[40];
  33. };
  34.  
  35. class IMonikerWatcher : public IMoniker 
  36. {
  37. public:
  38.     IMonikerWatcher( IMoniker *pMoniker, char *Name );
  39.     
  40.     // *** IUnknown methods ***
  41.     virtual HRESULT _IFUNC QueryInterface(REFIID riid, LPVOID FAR* ppvObj);
  42.     virtual ULONG _IFUNC AddRef();
  43.     virtual ULONG _IFUNC Release();
  44.  
  45.     // *** IPersist methods ***
  46.     virtual HRESULT _IFUNC GetClassID(LPCLSID lpClassID);
  47.  
  48.     // *** IPersistStream methods ***
  49.     virtual HRESULT _IFUNC IsDirty();
  50.     virtual HRESULT _IFUNC Load(LPSTREAM pStm);
  51.     virtual HRESULT _IFUNC Save(LPSTREAM pStm, BOOL fClearDirty);
  52.     virtual HRESULT _IFUNC GetSizeMax(ULARGE_INTEGER FAR * pcbSize);
  53.  
  54.     // *** IMoniker methods ***
  55.     virtual HRESULT _IFUNC BindToObject(LPBC pbc, LPMONIKER pmkToLeft,
  56.         REFIID riidResult, LPVOID FAR* ppvResult);
  57.     virtual HRESULT _IFUNC BindToStorage(LPBC pbc, LPMONIKER pmkToLeft,
  58.         REFIID riid, LPVOID FAR* ppvObj);
  59.     virtual HRESULT _IFUNC Reduce(LPBC pbc, DWORD dwReduceHowFar, LPMONIKER FAR*
  60.         ppmkToLeft, LPMONIKER FAR * ppmkReduced);
  61.     virtual HRESULT _IFUNC ComposeWith(LPMONIKER pmkRight, BOOL fOnlyIfNotGeneric,
  62.         LPMONIKER FAR* ppmkComposite);
  63.     virtual HRESULT _IFUNC Enum(BOOL fForward, LPENUMMONIKER FAR* ppenumMoniker);
  64.     virtual HRESULT _IFUNC IsEqual(LPMONIKER pmkOtherMoniker);
  65.     virtual HRESULT _IFUNC Hash(LPDWORD pdwHash);
  66.     virtual HRESULT _IFUNC IsRunning(LPBC pbc, LPMONIKER pmkToLeft, LPMONIKER
  67.         pmkNewlyRunning);
  68.     virtual HRESULT _IFUNC GetTimeOfLastChange(LPBC pbc, LPMONIKER pmkToLeft,
  69.         FILETIME FAR* pfiletime);
  70.     virtual HRESULT _IFUNC Inverse(LPMONIKER FAR* ppmk);
  71.     virtual HRESULT _IFUNC CommonPrefixWith(LPMONIKER pmkOther, LPMONIKER FAR*
  72.         ppmkPrefix);
  73.     virtual HRESULT _IFUNC RelativePathTo(LPMONIKER pmkOther, LPMONIKER FAR*
  74.         ppmkRelPath);
  75.     virtual HRESULT _IFUNC GetDisplayName(LPBC pbc, LPMONIKER pmkToLeft,
  76.         LPSTR FAR* lplpszDisplayName);
  77.     virtual HRESULT _IFUNC ParseDisplayName(LPBC pbc, LPMONIKER pmkToLeft,
  78.         LPSTR lpszDisplayName, ULONG FAR* pchEaten,
  79.         LPMONIKER FAR* ppmkOut);
  80.     virtual HRESULT _IFUNC IsSystemMoniker(LPDWORD pdwMksys);
  81.  
  82.  protected:
  83.  
  84.     IMoniker *     pMoniker;
  85.     char        Name[40];
  86. };
  87.  
  88. class ReleaseWatcher : public IUnknown 
  89. {
  90.     public:
  91.  
  92.         ReleaseWatcher( IUnknown *watched ) : Watched( watched ), nRef( 1 ){}
  93.         virtual HRESULT _IFUNC QueryInterface(REFIID, LPVOID FAR *);
  94.         virtual ULONG   _IFUNC AddRef();
  95.         virtual ULONG   _IFUNC Release();
  96.         IUnknown *Watched;
  97.         ULONG nRef;
  98. };
  99.  
  100. #include <assert.h>
  101.  
  102. #ifdef OLEDBG  /* put at end of class in order to not change member offsets */
  103.  
  104. class _ICLASS cDebug 
  105. {
  106.     protected:
  107.  
  108.         int          DebugMode;
  109.         char*        DebugClass;
  110.         char*        DebugFunc;
  111.         void         DebugEnter(char * dc, char * df, LPOLESTR s);
  112.         SCODE        DebugReturn(char * dc, char * df, SCODE);
  113.         HRESULT      DebugReturn(char * dc, char * df, HRESULT);
  114.         BOOL         DebugReturn(char * dc, char * df, BOOL);
  115.         ULONG        DebugReturn(char * dc, char * df, LPOLESTR s, ULONG);
  116.         void         DebugReturn(char * dc, char * df, REFIID, void *);
  117.         void         DebugExit(char * dc, char * df);
  118.         HRESULT      DebugHResult(LPOLESTR, HRESULT);
  119.         ULONG        DebugRefCnt (LPOLESTR, ULONG);
  120.         void         cdecl DebugPrintf(LPOLESTR, ...);
  121.         int          SetDebugMode(int m){DebugMode = m; return 1;}
  122.         char *       prepareBuf (char *);
  123.         void         DebugPrint (REFIID riid);
  124.         void         DebugPrint (LPOLESTR pS, const RECT FAR * pR);
  125.         void         DebugPrint (LPOLESTR pS, const SIZEL FAR * pL);
  126.         void         DebugPrint (LPOLESTR pS, BOOL f);
  127.         cDebug() : DebugMode (1) {}
  128. };
  129.  
  130. struct cDebugEnumRecord
  131. {
  132.     LPOLESTR pEnumS;
  133.     WORD    eValue;
  134. };
  135.  
  136. class _ICLASS cDebugEnum
  137. {
  138.     cDebugEnumRecord * pEnumRecs;
  139.     WORD count;
  140.     LPOLESTR pEnumName;
  141.     static char enumBuf [200];
  142. public:
  143.     cDebugEnum (LPOLESTR pN, cDebugEnumRecord *pR, WORD c) : pEnumName (pN), pEnumRecs (pR), count (c) {}
  144.  
  145.     void Print (DWORD e);
  146.  
  147.     LPOLESTR buf () { return enumBuf; }
  148. };
  149.  
  150. extern cDebugEnum cOLERENDER;
  151. extern cDebugEnum cOLEVERBATTRIB;
  152. extern cDebugEnum cUSERCLASSTYPE;
  153. extern cDebugEnum cOLEMISC;
  154. extern cDebugEnum cOLECLOSE;
  155. extern cDebugEnum cOLEGETMONIKER;
  156. extern cDebugEnum cOLEWHICHMK;
  157. extern cDebugEnum cBINDSPEED;
  158. extern cDebugEnum cOLECONTF;
  159. extern cDebugEnum cOLEUPDATE;
  160. extern cDebugEnum cOLELINKBIND;
  161. extern cDebugEnum cDVASPECT;
  162. extern cDebugEnum cTYMED;
  163. extern cDebugEnum cDATADIR;
  164. extern cDebugEnum cADVF;
  165. extern cDebugEnum cMEMCTX;
  166. extern cDebugEnum cCLSCTX;
  167. extern cDebugEnum cREGCLS;
  168. extern cDebugEnum cMSHLFLAGS;
  169. extern cDebugEnum cMSHCTX;
  170. extern cDebugEnum cCALLTYPE;
  171. extern cDebugEnum cSERVERCALL;
  172. extern cDebugEnum cPENDINGTYPE;
  173. extern cDebugEnum cPENDINGMSG;
  174. extern cDebugEnum cBIND_FLAGS;
  175. extern cDebugEnum cKSYS;
  176. extern cDebugEnum cMKRREDUCE;
  177. extern cDebugEnum cSTGC;
  178. extern cDebugEnum cSTGTY;
  179. extern cDebugEnum cSTREAM_SEEK;
  180. extern cDebugEnum cLOCKTYPE;
  181. extern cDebugEnum cSTGMOVE;
  182. extern cDebugEnum cSTATFLAG;
  183. extern cDebugEnum cOLEUIPASTEFLAG;
  184.  
  185. #else
  186. class _ICLASS cDebug;
  187. class _ICLASS cDebugEnum;
  188. #endif
  189.  
  190. #ifdef OLEDBG
  191. #  define OLEIMP(m,a) HRESULT _IFUNC _export OLE_IMPLEMENTATION::m a { \
  192.                          DebugClass=OLE_INTERFACE; DebugFunc=#m; DebugEnter(OLE_INTERFACE,#m,0);
  193. #  define OLEIMPRET(r,m,a) r _IFUNC OLE_IMPLEMENTATION::m a { \
  194.                          DebugClass=OLE_INTERFACE; DebugFunc=#m; DebugEnter(OLE_INTERFACE,#m,0);
  195. #    define OLEENTER DebugEnter(OLE_INTERFACE, OLE_FUNC, NULL);
  196. #    define OLEENTERS(s) DebugEnter(OLE_INTERFACE, OLE_FUNC, s);
  197. #  define OLERET(s) return ResultFromScode (DebugReturn(OLE_INTERFACE, OLE_FUNC, s))
  198. #  define OLERES(r) return DebugReturn(OLE_INTERFACE, OLE_FUNC, r)
  199. #  define OLEREF(s, r) return DebugReturn(OLE_INTERFACE, OLE_FUNC, s, r)
  200. #    define OLEBRET(b) return DebugReturn(OLE_INTERFACE, OLE_FUNC, b)
  201. #    define OLEPRET(id,p) return DebugReturn(OLE_INTERFACE, OLE_FUNC, id, p),p
  202. #    define OLEEXIT DebugExit(OLE_INTERFACE, OLE_FUNC)
  203. #    define OLEIID(id) DebugPrint (id)
  204. #    define OLEHRES(s,r)    DebugHResult (s, r)
  205. #    define OLEREFCNT(s,r) DebugRefCnt (s,r)
  206. #    define OLEPRINTF1(l) DebugPrintf(l)
  207. #    define OLEPRINTF2(l1,l2) DebugPrintf(l1,l2)
  208. #    define OLEPRINTF3(l1,l2,l3) DebugPrintf(l1,l2,l3)
  209. #    define OLEPRINTF4(l1,l2,l3,l4) DebugPrintf(l1,l2,l3,l4)
  210. #    define OLEPRINTF5(l1,l2,l3,l4,l5) DebugPrintf(l1,l2,l3,l4,l5)
  211. #    define OLEENUM(E,v) E.Print(v);DebugPrintf(E.buf())
  212. #else
  213. #  define OLEIMP(m,a) HRESULT _IFUNC _export OLE_IMPLEMENTATION::m a {
  214. #  define OLEIMPRET(r,m,a) r _IFUNC OLE_IMPLEMENTATION::m a {
  215. // #    define OLEENTER
  216.  
  217. #    define OLEENTER(s)
  218. #    define OLEPRINTF1(l) 
  219. #    define OLEPRINTF2(l1,l2) 
  220. #    define OLEPRINTF3(l1,l2,l3) 
  221. #    define OLEPRINTF4(l1,l2,l3,l4) 
  222. #    define OLEPRINTF5(l1,l2,l3,l4,l5) 
  223. #    define OLEIID(id)
  224. #    define OLEHRES(s,r) (r)
  225. #  define OLERET(s) return ResultFromScode (s)
  226. #  define OLERES(r) return r
  227. #  define OLEREF(s, r) return r
  228. #    define OLEREFCNT(s,r) (r)
  229. #    define OLEEXIT
  230. #    define OLEBRET(b) return b
  231. #    define OLEPRET(id,p) return p
  232. #    define OLEENUM(E,v)
  233. #endif
  234.  
  235. #define OLE_INTERFACE DebugClass
  236. #define OLE_FUNC DebugFunc
  237.  
  238. #endif
  239.  
  240.