home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / inc / inole.h < prev    next >
C/C++ Source or Header  |  1996-05-23  |  11KB  |  452 lines

  1. /*
  2.  * INOLE.H
  3.  *
  4.  * Master header file for all Inside OLE samples.
  5.  *
  6.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Microsoft
  9.  * Internet  :  kraigb@microsoft.com
  10.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  11.  */
  12.  
  13.  
  14. #ifndef _INOLE_H_
  15. #define _INOLE_H_
  16.  
  17. #define INC_OLE2
  18. #include <windows.h>
  19. #include <ole2.h>
  20. #include <ole2ver.h>
  21.  
  22. #ifdef INC_OLEUI
  23. #ifdef WIN32
  24. /*
  25.  * Comment the next line and remove the comment from the
  26.  * line after it to compile for Windows NT 3.5.
  27.  */
  28. #include <oledlg.h>
  29. //#include <ole2ui.h>
  30. #else
  31. #include <ole2ui.h>
  32. #endif
  33. #endif
  34.  
  35. #include <bookguid.h>
  36.  
  37. #ifdef INC_CONTROLS
  38. #define INC_AUTOMATION
  39. #endif
  40.  
  41. #ifdef INC_AUTOMATION
  42. #ifndef WIN32
  43. #include <dispatch.h>
  44. #include <olenls.h>
  45. #else
  46. #include <oleauto.h>
  47. #endif
  48. #endif
  49.  
  50. #ifdef INC_CONTROLS
  51. #include <olectl.h>
  52. #ifndef INITGUIDS
  53. #include <olectlid.h>
  54. #endif
  55. #endif
  56.  
  57. #ifdef WIN32
  58. #include <tchar.h>
  59. #ifdef UNICODE
  60. #include <wchar.h>
  61. #endif
  62. #endif
  63.  
  64. #ifndef WIN32
  65. #include <shellapi.h>
  66. #include <malloc.h>
  67. #endif
  68.  
  69. #include <book1632.h>
  70. #include <dbgout.h>
  71.  
  72. #ifdef INC_CLASSLIB
  73. extern "C"
  74.     {
  75.     #include <commdlg.h>
  76.    #ifndef WIN32
  77.     #include <print.h>
  78.     #include <dlgs.h>
  79.    #endif
  80.     }
  81.  
  82. #include <classlib.h>
  83. #endif
  84.  
  85.  
  86. //Types that OLE2.H et. al. leave out
  87.  
  88. #ifndef PPVOID
  89. typedef LPVOID * PPVOID;
  90. #endif  //PPVOID
  91.  
  92.  
  93. #ifdef _OLE2_H_   //May not include ole2.h at all times.
  94.  
  95. #ifndef PPOINTL
  96. typedef POINTL * PPOINTL;
  97. #endif  //PPOINTL
  98.  
  99.  
  100. #ifndef _WIN32
  101. #ifndef OLECHAR
  102. typedef char OLECHAR;
  103. typedef OLECHAR FAR* LPOLESTR;
  104. typedef const OLECHAR FAR* LPCOLESTR;
  105. #endif //OLECHAR
  106. #endif //_WIN32
  107.  
  108.  
  109. //Useful macros.
  110. #define SETFormatEtc(fe, cf, asp, td, med, li)   \
  111.     {\
  112.     (fe).cfFormat=cf;\
  113.     (fe).dwAspect=asp;\
  114.     (fe).ptd=td;\
  115.     (fe).tymed=med;\
  116.     (fe).lindex=li;\
  117.     }
  118.  
  119. #define SETDefFormatEtc(fe, cf, med)   \
  120.     {\
  121.     (fe).cfFormat=cf;\
  122.     (fe).dwAspect=DVASPECT_CONTENT;\
  123.     (fe).ptd=NULL;\
  124.     (fe).tymed=med;\
  125.     (fe).lindex=-1;\
  126.     }
  127.  
  128.  
  129. #define SETRECTL(rcl, l, t, r, b) \
  130.     {\
  131.     (rcl).left=l;\
  132.     (rcl).top=t;\
  133.     (rcl).right=r;\
  134.     (rcl).bottom=b;\
  135.     }
  136.  
  137. #define SETSIZEL(szl, h, v) \
  138.     {\
  139.     (szl).cx=h;\
  140.     (szl).cy=v;\
  141.     }
  142.  
  143.  
  144. #define RECTLFROMRECT(rcl, rc)\
  145.     {\
  146.     (rcl).left=(long)(rc).left;\
  147.     (rcl).top=(long)(rc).top;\
  148.     (rcl).right=(long)(rc).right;\
  149.     (rcl).bottom=(long)(rc).bottom;\
  150.     }
  151.  
  152.  
  153. #define RECTFROMRECTL(rc, rcl)\
  154.     {\
  155.     (rc).left=(int)(rcl).left;\
  156.     (rc).top=(int)(rcl).top;\
  157.     (rc).right=(int)(rcl).right;\
  158.     (rc).bottom=(int)(rcl).bottom;\
  159.     }
  160.  
  161.  
  162. #define POINTLFROMPOINT(ptl, pt) \
  163.     { \
  164.     (ptl).x=(long)(pt).x; \
  165.     (ptl).y=(long)(pt).y; \
  166.     }
  167.  
  168.  
  169. #define POINTFROMPOINTL(pt, ptl) \
  170.     { \
  171.     (pt).x=(int)(ptl).x; \
  172.     (pt).y=(int)(ptl).y; \
  173.     }
  174.  
  175. //Here's one that should be in windows.h
  176. #define SETPOINT(pt, h, v) \
  177.     {\
  178.     (pt).x=h;\
  179.     (pt).y=v;\
  180.     }
  181.  
  182. #define SETPOINTL(ptl, h, v) \
  183.     {\
  184.     (ptl).x=h;\
  185.     (ptl).y=v;\
  186.     }
  187.  
  188. #endif  //_OLE2_H_
  189.  
  190. #ifdef INC_AUTOMATION
  191.  
  192. //Macros for setting DISPPARAMS structures
  193. #define SETDISPPARAMS(dp, numArgs, pvArgs, numNamed, pNamed) \
  194.     {\
  195.     (dp).cArgs=numArgs;\
  196.     (dp).rgvarg=pvArgs;\
  197.     (dp).cNamedArgs=numNamed;\
  198.     (dp).rgdispidNamedArgs=pNamed;\
  199.     }
  200.  
  201. #define SETNOPARAMS(dp) SETDISPPARAMS(dp, 0, NULL, 0, NULL)
  202.  
  203. //Macros for setting EXCEPINFO structures
  204. #define SETEXCEPINFO(ei, excode, src, desc, file, ctx, func, scd) \
  205.     {\
  206.     (ei).wCode=excode;\
  207.     (ei).wReserved=0;\
  208.     (ei).bstrSource=src;\
  209.     (ei).bstrDescription=desc;\
  210.     (ei).bstrHelpFile=file;\
  211.     (ei).dwHelpContext=ctx;\
  212.     (ei).pvReserved=NULL;\
  213.     (ei).pfnDeferredFillIn=func;\
  214.     (ei).scode=scd;\
  215.     }
  216.  
  217.  
  218. #define INITEXCEPINFO(ei) \
  219.         SETEXCEPINFO(ei,0,NULL,NULL,NULL,0L,NULL,S_OK)
  220.  
  221. #endif
  222.  
  223.  
  224. /*
  225.  * State flags for IPersistStorage implementations.  These
  226.  * are kept here to avoid repeating the code in all samples.
  227.  */
  228.  
  229. typedef enum
  230.     {
  231.     PSSTATE_UNINIT,     //Uninitialized
  232.     PSSTATE_SCRIBBLE,   //Scribble
  233.     PSSTATE_ZOMBIE,     //No scribble
  234.     PSSTATE_HANDSOFF    //Hand-off
  235.     } PSSTATE;
  236.  
  237.  
  238. /*
  239.  * Identifers to describe which persistence model an object
  240.  * is using, along with a union type that holds on the the
  241.  * appropriate pointers that a client may need.
  242.  */
  243. typedef enum
  244.     {
  245.     PERSIST_UNKNOWN=0,
  246.     PERSIST_STORAGE,
  247.     PERSIST_STREAM,
  248.     PERSIST_STREAMINIT,
  249.     PERSIST_FILE
  250.     } PERSIST_MODEL;
  251.  
  252. typedef struct
  253.     {
  254.     PERSIST_MODEL   psModel;
  255.     union
  256.         {
  257.         IPersistStorage    *pIPersistStorage;
  258.         IPersistStream     *pIPersistStream;
  259.        #ifdef INC_CONTROLS
  260.         IPersistStreamInit *pIPersistStreamInit;
  261.        #endif
  262.         IPersistFile       *pIPersistFile;
  263.         } pIP;
  264.  
  265.     } PERSISTPOINTER, *PPERSISTPOINTER;
  266.  
  267.  
  268. //To identify a storage in which to save, load, or create.
  269. typedef struct
  270.     {
  271.     PERSIST_MODEL   psModel;
  272.     union
  273.         {
  274.         IStorage    *pIStorage;
  275.         IStream     *pIStream;
  276.         } pIS;
  277.  
  278.     } STGPOINTER, *PSTGPOINTER;
  279.  
  280.  
  281.  
  282. //Type for an object-destroyed callback
  283. typedef void (*PFNDESTROYED)(void);
  284.  
  285.  
  286. //DeleteInterfaceImp calls 'delete' and NULLs the pointer
  287. #define DeleteInterfaceImp(p)\
  288.             {\
  289.             if (NULL!=p)\
  290.                 {\
  291.                 delete p;\
  292.                 p=NULL;\
  293.                 }\
  294.             }
  295.  
  296.  
  297. //ReleaseInterface calls 'Release' and NULLs the pointer
  298. #define ReleaseInterface(p)\
  299.             {\
  300.             IUnknown *pt=(IUnknown *)p;\
  301.             p=NULL;\
  302.             if (NULL!=pt)\
  303.                 pt->Release();\
  304.             }
  305.  
  306.  
  307. //OLE Documents Clipboard Formats
  308.  
  309. #define CFSTR_EMBEDSOURCE       TEXT("Embed Source")
  310. #define CFSTR_EMBEDDEDOBJECT    TEXT("Embedded Object")
  311. #define CFSTR_LINKSOURCE        TEXT("Link Source")
  312. #define CFSTR_CUSTOMLINKSOURCE  TEXT("Custom Link Source")
  313. #define CFSTR_OBJECTDESCRIPTOR  TEXT("Object Descriptor")
  314. #define CFSTR_LINKSRCDESCRIPTOR TEXT("Link Source Descriptor")
  315.  
  316.  
  317.  
  318. //Functions in the helper DLL, INOLE.DLL
  319.  
  320. //UI Effects
  321. STDAPI_(void) UIDrawHandles(LPRECT, HDC, DWORD, UINT, BOOL);
  322. STDAPI_(void) UIDrawShading(LPRECT, HDC, DWORD, UINT);
  323. STDAPI_(void) UIShowObject(LPCRECT, HDC, BOOL);
  324.  
  325. //For UIDrawHandles
  326. #define UI_HANDLES_USEINVERSE    0x00000001L
  327. #define UI_HANDLES_NOBORDER      0x00000002L
  328. #define UI_HANDLES_INSIDE        0x00000004L
  329. #define UI_HANDLES_OUTSIDE       0x00000008L
  330.  
  331. //For UIDrawShading
  332. #define UI_SHADE_FULLRECT        1
  333. #define UI_SHADE_BORDERIN        2
  334. #define UI_SHADE_BORDEROUT       3
  335.  
  336. //Coordinate Munging
  337. STDAPI_(int)  XformWidthInHimetricToPixels(HDC,  int);
  338. STDAPI_(int)  XformWidthInPixelsToHimetric(HDC,  int);
  339. STDAPI_(int)  XformHeightInHimetricToPixels(HDC, int);
  340. STDAPI_(int)  XformHeightInPixelsToHimetric(HDC, int);
  341.  
  342. STDAPI_(void) XformRectInPixelsToHimetric(HDC, LPRECT,  LPRECT);
  343. STDAPI_(void) XformRectInHimetricToPixels(HDC, LPRECT,  LPRECT);
  344. STDAPI_(void) XformSizeInPixelsToHimetric(HDC, LPSIZEL, LPSIZEL);
  345. STDAPI_(void) XformSizeInHimetricToPixels(HDC, LPSIZEL, LPSIZEL);
  346.  
  347.  
  348. //Helpers
  349. STDAPI_(void)     INOLE_MetafilePictIconFree(HGLOBAL);
  350. STDAPI            INOLE_SwitchDisplayAspect(IUnknown *, LPDWORD, DWORD
  351.                       , HGLOBAL, BOOL, BOOL, IAdviseSink *, BOOL *);
  352. STDAPI            INOLE_SetIconInCache(IUnknown *, HGLOBAL);
  353. STDAPI_(UINT)     INOLE_GetUserTypeOfClass(REFCLSID, UINT, LPTSTR
  354.                       , UINT);
  355. STDAPI            INOLE_DoConvert(IStorage *, REFCLSID);
  356. STDAPI_(LPTSTR)   INOLE_CopyString(LPTSTR);
  357. STDAPI_(HGLOBAL)  INOLE_ObjectDescriptorFromOleObject(IOleObject *
  358.                       , DWORD, POINTL, LPSIZEL);
  359. STDAPI_(HGLOBAL)  INOLE_AllocObjectDescriptor(CLSID, DWORD
  360.                       , SIZEL, POINTL, DWORD, LPTSTR, LPTSTR);
  361. STDAPI_(IStorage *) INOLE_CreateStorageOnHGlobal(DWORD);
  362. STDAPI            INOLE_GetLinkSourceData(IMoniker *, LPCLSID
  363.                       , LPFORMATETC, LPSTGMEDIUM);
  364. STDAPI_(void)     INOLE_RegisterAsRunning(IUnknown *, IMoniker *
  365.                       , DWORD, LPDWORD);
  366. STDAPI_(void)     INOLE_RevokeAsRunning(LPDWORD);
  367. STDAPI_(void)     INOLE_NoteChangeTime(DWORD, FILETIME *, LPTSTR);
  368.  
  369.  
  370.  
  371. /*
  372.  * These are for ANSI compilations on Win32.  Source code assumes
  373.  * a Win32 Unicode environment (or Win16 Ansi).  These macros
  374.  * route Win32 ANSI compiled functions to wrappers which do the
  375.  * proper Unicode conversion.
  376.  */
  377.  
  378.  
  379. #ifdef WIN32ANSI
  380. STDAPI INOLE_ConvertStringToANSI(LPCWSTR, LPSTR *);
  381. STDAPI INOLE_StringFromCLSID(REFCLSID, LPSTR *);
  382. STDAPI INOLE_StringFromGUID2(REFGUID, LPSTR, int);
  383. STDAPI INOLE_ProgIDFromCLSID(REFCLSID, LPSTR *);
  384.  
  385. STDAPI INOLE_ReadFmtUserTypeStg(IStorage *, CLIPFORMAT *, LPSTR *);
  386. STDAPI INOLE_WriteFmtUserTypeStg(IStorage *, CLIPFORMAT, LPSTR);
  387.  
  388. STDAPI INOLE_StgIsStorageFile(LPCSTR);
  389. STDAPI INOLE_StgCreateDocfile(LPCSTR, DWORD, DWORD, IStorage **);
  390. STDAPI INOLE_StgOpenStorage(LPCSTR, IStorage *, DWORD, SNB
  391.            , DWORD, IStorage **);
  392.  
  393.  
  394. STDAPI INOLE_CreateFileMoniker(LPCSTR, LPMONIKER *);
  395. STDAPI INOLE_CreateItemMoniker(LPCSTR, LPCSTR, LPMONIKER *);
  396. STDAPI INOLE_MkParseDisplayName(LPBC, LPCSTR, ULONG *, LPMONIKER *);
  397.  
  398. STDAPI INOLE_OleCreateLinkToFile(LPCSTR, REFIID, DWORD, LPFORMATETC
  399.            , LPOLECLIENTSITE, LPSTORAGE, LPVOID *);
  400. STDAPI INOLE_OleCreateFromFile(REFCLSID, LPCSTR, REFIID
  401.            , DWORD, LPFORMATETC, LPOLECLIENTSITE, LPSTORAGE, LPVOID *);
  402.  
  403.  
  404. #ifndef NOMACROREDIRECT
  405. #undef StringFromCLSID
  406. #define StringFromCLSID(c, pp) INOLE_StringFromCLSID(c, pp)
  407.  
  408. #undef StringFromGUID2
  409. #define StringFromGUID2(r, p, i) INOLE_StringFromGUID2(r, p, i)
  410.  
  411. #undef ProgIDFromCLSID
  412. #define ProgIDFromCLSID(c, pp) INOLE_ProgIDFromCLSID(c, pp)
  413.  
  414. #undef ReadFmtUserTypeStg
  415. #define ReadFmtUserTypeStg(p, c, s) INOLE_ReadFmtUserTypeStg(p, c, s)
  416.  
  417. #undef WriteFmtUserTypeStg
  418. #define WriteFmtUserTypeStg(p, c, s) INOLE_WriteFmtUserTypeStg(p, c, s)
  419.  
  420. #undef StgIsStorageFile
  421. #define StgIsStorageFile(s) INOLE_StgIsStorageFile(s)
  422.  
  423. #undef StgCreateDocfile
  424. #define StgCreateDocfile(a, b, c, d) INOLE_StgCreateDocfile(a, b, c, d)
  425.  
  426. #undef StgOpenStorage
  427. #define StgOpenStorage(a,b,c,d,e,f) INOLE_StgOpenStorage(a,b,c,d,e,f)
  428.  
  429. #undef CreateFileMoniker
  430. #define CreateFileMoniker(p, i) INOLE_CreateFileMoniker(p, i)
  431.  
  432. #undef CreateItemMoniker
  433. #define CreateItemMoniker(p1, p2, i) INOLE_CreateItemMoniker(p1, p2, i)
  434.  
  435. #undef MkParseDisplayName
  436. #define MkParseDisplayName(b, p, u, i) INOLE_MkParseDisplayName(b, p, u, i)
  437.  
  438. #undef OleCreateLinkToFile
  439. #define OleCreateLinkToFile(s, i, d, fe, cs, st, pv) INOLE_OleCreateLinkToFile(s, i, d, fe, cs, st, pv)
  440.  
  441. #undef OleCreateFromFile
  442. #define OleCreateFromFile(c, s, i, d, fe, cs, st, pv) INOLE_OleCreateFromFile(c, s, i, d, fe, cs, st, pv)
  443.  
  444.  
  445. #endif
  446.  
  447. #endif
  448.  
  449.  
  450.  
  451. #endif //_INOLE_H_
  452.