home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / BOCOLE.PAK / OLEDEBUG.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  7.8 KB  |  238 lines

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