afxdisp.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #ifndef __AFXDISP_H__
  11. #define __AFXDISP_H__
  12. #ifdef _AFX_NO_OLE_SUPPORT
  13. #error OLE classes not supported in this library variant.
  14. #endif
  15. #ifndef __AFXWIN_H__
  16. #include <afxwin.h>
  17. #endif
  18. // include necessary OLE headers
  19. #ifndef _OBJBASE_H_
  20. #include <objbase.h>
  21. #endif
  22. #ifndef _OLEAUTO_H_
  23. #include <oleauto.h>
  24. #endif
  25. #ifndef _OLECTL_H_
  26. #include <olectl.h>
  27. #endif
  28. #ifndef __ocidl_h__
  29. #include <ocidl.h>
  30. #endif
  31. // Shell interface support
  32. #ifndef _SHLOBJ_H_
  33. #include <shlobj.h>
  34. #endif
  35. #ifdef _AFX_MINREBUILD
  36. #pragma component(minrebuild, off)
  37. #endif
  38. #ifndef _AFX_FULLTYPEINFO
  39. #pragma component(mintypeinfo, on)
  40. #endif
  41. #ifndef _AFX_NOFORCE_LIBS
  42. /////////////////////////////////////////////////////////////////////////////
  43. // Win32 libraries
  44. #ifdef _AFXDLL
  45. #if defined(_DEBUG) && !defined(_AFX_MONOLITHIC)
  46. #ifndef _UNICODE
  47. #pragma comment(lib, "mfco42d.lib")
  48. #else
  49. #pragma comment(lib, "mfco42ud.lib")
  50. #endif
  51. #endif
  52. #endif
  53. #pragma comment(lib, "oledlg.lib")
  54. #pragma comment(lib, "ole32.lib")
  55. #pragma comment(lib, "olepro32.lib")
  56. #pragma comment(lib, "oleaut32.lib")
  57. #pragma comment(lib, "uuid.lib")
  58. #pragma comment(lib, "urlmon.lib")
  59. #endif //!_AFX_NOFORCE_LIBS
  60. /////////////////////////////////////////////////////////////////////////////
  61. #ifdef _AFX_PACKING
  62. #pragma pack(push, _AFX_PACKING)
  63. #endif
  64. /////////////////////////////////////////////////////////////////////////////
  65. // AFXDISP - MFC IDispatch & ClassFactory support
  66. // Classes declared in this file
  67. //CException
  68. class COleException; // caught by client or server
  69. class COleDispatchException; // special exception for IDispatch calls
  70. //CCmdTarget
  71. class COleObjectFactory; // glue for IClassFactory -> runtime class
  72. class COleTemplateServer; // server documents using CDocTemplate
  73. class COleDispatchDriver; // helper class to call IDispatch
  74. class COleVariant; // OLE VARIANT wrapper
  75. class COleCurrency; // Based on OLE CY
  76. class COleDateTime; // Based on OLE DATE
  77. class COleDateTimeSpan; // Based on a double
  78. class COleSafeArray; // Based on OLE VARIANT
  79. /////////////////////////////////////////////////////////////////////////////
  80. // AFXDLL support
  81. #undef AFX_DATA
  82. #define AFX_DATA AFX_OLE_DATA
  83. /////////////////////////////////////////////////////////////////////////////
  84. // OLE COM (Component Object Model) implementation infrastructure
  85. // - data driven QueryInterface
  86. // - standard implementation of aggregate AddRef and Release
  87. // (see CCmdTarget in AFXWIN.H for more information)
  88. #define METHOD_PROLOGUE(theClass, localClass) \
  89. theClass* pThis = \
  90. ((theClass*)((BYTE*)this - offsetof(theClass, m_x##localClass))); \
  91. AFX_MANAGE_STATE(pThis->m_pModuleState) \
  92. pThis; // avoid warning from compiler \
  93. #define METHOD_PROLOGUE_(theClass, localClass) \
  94. theClass* pThis = \
  95. ((theClass*)((BYTE*)this - offsetof(theClass, m_x##localClass))); \
  96. pThis; // avoid warning from compiler \
  97. #ifndef _AFX_NO_NESTED_DERIVATION
  98. #define METHOD_PROLOGUE_EX(theClass, localClass) \
  99. theClass* pThis = ((theClass*)((BYTE*)this - m_nOffset)); \
  100. AFX_MANAGE_STATE(pThis->m_pModuleState) \
  101. pThis; // avoid warning from compiler \
  102. #define METHOD_PROLOGUE_EX_(theClass, localClass) \
  103. theClass* pThis = ((theClass*)((BYTE*)this - m_nOffset)); \
  104. pThis; // avoid warning from compiler \
  105. #else
  106. #define METHOD_PROLOGUE_EX(theClass, localClass) \
  107. METHOD_PROLOGUE(theClass, localClass) \
  108. #define METHOD_PROLOGUE_EX_(theClass, localClass) \
  109. METHOD_PROLOGUE_(theClass, localClass) \
  110. #endif
  111. // Provided only for compatibility with CDK 1.x
  112. #define METHOD_MANAGE_STATE(theClass, localClass) \
  113. METHOD_PROLOGUE_EX(theClass, localClass) \
  114. #define BEGIN_INTERFACE_PART(localClass, baseClass) \
  115. class X##localClass : public baseClass \
  116. { \
  117. public: \
  118. STDMETHOD_(ULONG, AddRef)(); \
  119. STDMETHOD_(ULONG, Release)(); \
  120. STDMETHOD(QueryInterface)(REFIID iid, LPVOID* ppvObj); \
  121. #ifndef _AFX_NO_NESTED_DERIVATION
  122. #define BEGIN_INTERFACE_PART_DERIVE(localClass, baseClass) \
  123. class X##localClass : public baseClass \
  124. { \
  125. public: \
  126. #else
  127. #define BEGIN_INTERFACE_PART_DERIVE(localClass, baseClass) \
  128. BEGIN_INTERFACE_PART(localClass, baseClass) \
  129. #endif
  130. #ifndef _AFX_NO_NESTED_DERIVATION
  131. #define INIT_INTERFACE_PART(theClass, localClass) \
  132. size_t m_nOffset; \
  133. INIT_INTERFACE_PART_DERIVE(theClass, localClass) \
  134. #define INIT_INTERFACE_PART_DERIVE(theClass, localClass) \
  135. X##localClass() \
  136. { m_nOffset = offsetof(theClass, m_x##localClass); } \
  137. #else
  138. #define INIT_INTERFACE_PART(theClass, localClass)
  139. #define INIT_INTERFACE_PART_DERIVE(theClass, localClass)
  140. #endif
  141. // Note: Inserts the rest of OLE functionality between these two macros,
  142. // depending upon the interface that is being implemented. It is not
  143. // necessary to include AddRef, Release, and QueryInterface since those
  144. // member functions are declared by the macro.
  145. #define END_INTERFACE_PART(localClass) \
  146. } m_x##localClass; \
  147. friend class X##localClass; \
  148. struct CInterfacePlaceHolder
  149. {
  150. DWORD m_vtbl; // filled in with USE_INTERFACE_PART
  151. CInterfacePlaceHolder() { m_vtbl = 0; }
  152. };
  153. #define END_INTERFACE_PART_OPTIONAL(localClass) \
  154. }; \
  155. CInterfacePlaceHolder m_x##localClass; \
  156. friend class X##localClass; \
  157. #ifdef _AFXDLL
  158. #define END_INTERFACE_PART_STATIC END_INTERFACE_PART
  159. #else
  160. #define END_INTERFACE_PART_STATIC END_INTERFACE_PART
  161. #endif
  162. #define USE_INTERFACE_PART(localClass) \
  163. m_x##localClass.m_vtbl = *(DWORD*)&X##localClass(); \
  164. #ifdef _AFXDLL
  165. #define BEGIN_INTERFACE_MAP(theClass, theBase) \
  166. const AFX_INTERFACEMAP* PASCAL theClass::_GetBaseInterfaceMap() \
  167. { return &theBase::interfaceMap; } \
  168. const AFX_INTERFACEMAP* theClass::GetInterfaceMap() const \
  169. { return &theClass::interfaceMap; } \
  170. AFX_COMDAT const AFX_DATADEF AFX_INTERFACEMAP theClass::interfaceMap = \
  171. { &theClass::_GetBaseInterfaceMap, &theClass::_interfaceEntries[0], }; \
  172. AFX_COMDAT const AFX_DATADEF AFX_INTERFACEMAP_ENTRY theClass::_interfaceEntries[] = \
  173. { \
  174. #else
  175. #define BEGIN_INTERFACE_MAP(theClass, theBase) \
  176. const AFX_INTERFACEMAP* theClass::GetInterfaceMap() const \
  177. { return &theClass::interfaceMap; } \
  178. AFX_COMDAT const AFX_DATADEF AFX_INTERFACEMAP theClass::interfaceMap = \
  179. { &theBase::interfaceMap, &theClass::_interfaceEntries[0], }; \
  180. AFX_COMDAT const AFX_DATADEF AFX_INTERFACEMAP_ENTRY theClass::_interfaceEntries[] = \
  181. { \
  182. #endif
  183. #define INTERFACE_PART(theClass, iid, localClass) \
  184. { &iid, offsetof(theClass, m_x##localClass) }, \
  185. #define INTERFACE_AGGREGATE(theClass, theAggr) \
  186. { NULL, offsetof(theClass, theAggr) }, \
  187. #define END_INTERFACE_MAP() \
  188. { NULL, (size_t)-1 } \
  189. }; \
  190. /////////////////////////////////////////////////////////////////////////////
  191. // COleException - unexpected or rare OLE error returned
  192. class COleException : public CException
  193. {
  194. DECLARE_DYNAMIC(COleException)
  195. public:
  196. SCODE m_sc;
  197. static SCODE PASCAL Process(const CException* pAnyException);
  198. // Implementation (use AfxThrowOleException to create)
  199. public:
  200. COleException();
  201. virtual ~COleException();
  202. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  203. PUINT pnHelpContext = NULL);
  204. };
  205. void AFXAPI AfxThrowOleException(SCODE sc);
  206. void AFXAPI AfxCheckError(SCODE sc);
  207. /////////////////////////////////////////////////////////////////////////////
  208. // IDispatch specific exception
  209. class COleDispatchException : public CException
  210. {
  211. DECLARE_DYNAMIC(COleDispatchException)
  212. public:
  213. // Attributes
  214. WORD m_wCode; // error code (specific to IDispatch implementation)
  215. CString m_strDescription; // human readable description of the error
  216. DWORD m_dwHelpContext; // help context for error
  217. // usually empty in application which creates it (eg. servers)
  218. CString m_strHelpFile; // help file to use with m_dwHelpContext
  219. CString m_strSource; // source of the error (name of server)
  220. // Implementation
  221. public:
  222. COleDispatchException(LPCTSTR lpszDescription, UINT nHelpID, WORD wCode);
  223. virtual ~COleDispatchException();
  224. static void PASCAL Process(
  225. EXCEPINFO* pInfo, const CException* pAnyException);
  226. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  227. PUINT pnHelpContext = NULL);
  228. SCODE m_scError; // SCODE describing the error
  229. };
  230. void AFXAPI AfxThrowOleDispatchException(WORD wCode, LPCTSTR lpszDescription,
  231. UINT nHelpID = 0);
  232. void AFXAPI AfxThrowOleDispatchException(WORD wCode, UINT nDescriptionID,
  233. UINT nHelpID = (UINT)-1);
  234. /////////////////////////////////////////////////////////////////////////////
  235. // Macros for CCmdTarget IDispatchable classes
  236. #ifdef _AFXDLL
  237. #define BEGIN_DISPATCH_MAP(theClass, baseClass) \
  238. const AFX_DISPMAP* PASCAL theClass::_GetBaseDispatchMap() \
  239. { return &baseClass::dispatchMap; } \
  240. const AFX_DISPMAP* theClass::GetDispatchMap() const \
  241. { return &theClass::dispatchMap; } \
  242. AFX_COMDAT const AFX_DISPMAP theClass::dispatchMap = \
  243. { &theClass::_GetBaseDispatchMap, &theClass::_dispatchEntries[0], \
  244. &theClass::_dispatchEntryCount, &theClass::_dwStockPropMask }; \
  245. AFX_COMDAT UINT theClass::_dispatchEntryCount = (UINT)-1; \
  246. AFX_COMDAT DWORD theClass::_dwStockPropMask = (DWORD)-1; \
  247. AFX_COMDAT const AFX_DISPMAP_ENTRY theClass::_dispatchEntries[] = \
  248. { \
  249. #else
  250. #define BEGIN_DISPATCH_MAP(theClass, baseClass) \
  251. const AFX_DISPMAP* theClass::GetDispatchMap() const \
  252. { return &theClass::dispatchMap; } \
  253. AFX_COMDAT const AFX_DISPMAP theClass::dispatchMap = \
  254. { &baseClass::dispatchMap, &theClass::_dispatchEntries[0], \
  255. &theClass::_dispatchEntryCount, &theClass::_dwStockPropMask }; \
  256. AFX_COMDAT UINT theClass::_dispatchEntryCount = (UINT)-1; \
  257. AFX_COMDAT DWORD theClass::_dwStockPropMask = (DWORD)-1; \
  258. AFX_COMDAT const AFX_DISPMAP_ENTRY theClass::_dispatchEntries[] = \
  259. { \
  260. #endif
  261. #define END_DISPATCH_MAP() \
  262. { VTS_NONE, DISPID_UNKNOWN, VTS_NONE, VT_VOID, \
  263. (AFX_PMSG)NULL, (AFX_PMSG)NULL, (size_t)-1, afxDispCustom } }; \
  264. // parameter types: by value VTs
  265. #define VTS_I2 "\x02" // a 'short'
  266. #define VTS_I4 "\x03" // a 'long'
  267. #define VTS_R4 "\x04" // a 'float'
  268. #define VTS_R8 "\x05" // a 'double'
  269. #define VTS_CY "\x06" // a 'CY' or 'CY*'
  270. #define VTS_DATE "\x07" // a 'DATE'
  271. #define VTS_WBSTR "\x08" // an 'LPCOLESTR'
  272. #define VTS_DISPATCH "\x09" // an 'IDispatch*'
  273. #define VTS_SCODE "\x0A" // an 'SCODE'
  274. #define VTS_BOOL "\x0B" // a 'BOOL'
  275. #define VTS_VARIANT "\x0C" // a 'const VARIANT&' or 'VARIANT*'
  276. #define VTS_UNKNOWN "\x0D" // an 'IUnknown*'
  277. #if defined(_UNICODE) || defined(OLE2ANSI)
  278. #define VTS_BSTR VTS_WBSTR// an 'LPCOLESTR'
  279. #define VT_BSTRT VT_BSTR
  280. #else
  281. #define VTS_BSTR "\x0E" // an 'LPCSTR'
  282. #define VT_BSTRA 14
  283. #define VT_BSTRT VT_BSTRA
  284. #endif
  285. #define VTS_UI1 "\x0F" // a 'BYTE'
  286. // parameter types: by reference VTs
  287. #define VTS_PI2 "\x42" // a 'short*'
  288. #define VTS_PI4 "\x43" // a 'long*'
  289. #define VTS_PR4 "\x44" // a 'float*'
  290. #define VTS_PR8 "\x45" // a 'double*'
  291. #define VTS_PCY "\x46" // a 'CY*'
  292. #define VTS_PDATE "\x47" // a 'DATE*'
  293. #define VTS_PBSTR "\x48" // a 'BSTR*'
  294. #define VTS_PDISPATCH "\x49" // an 'IDispatch**'
  295. #define VTS_PSCODE "\x4A" // an 'SCODE*'
  296. #define VTS_PBOOL "\x4B" // a 'VARIANT_BOOL*'
  297. #define VTS_PVARIANT "\x4C" // a 'VARIANT*'
  298. #define VTS_PUNKNOWN "\x4D" // an 'IUnknown**'
  299. #define VTS_PUI1 "\x4F" // a 'BYTE*'
  300. // special VT_ and VTS_ values
  301. #define VTS_NONE NULL // used for members with 0 params
  302. #define VT_MFCVALUE 0xFFF // special value for DISPID_VALUE
  303. #define VT_MFCBYREF 0x40 // indicates VT_BYREF type
  304. #define VT_MFCMARKER 0xFF // delimits named parameters (INTERNAL USE)
  305. // variant handling (use V_BSTRT when you have ANSI BSTRs, as in DAO)
  306. #ifndef _UNICODE
  307. #define V_BSTRT(b) (LPSTR)V_BSTR(b)
  308. #else
  309. #define V_BSTRT(b) V_BSTR(b)
  310. #endif
  311. /////////////////////////////////////////////////////////////////////////////
  312. // OLE control parameter types
  313. #define VTS_COLOR VTS_I4 // OLE_COLOR
  314. #define VTS_XPOS_PIXELS VTS_I4 // OLE_XPOS_PIXELS
  315. #define VTS_YPOS_PIXELS VTS_I4 // OLE_YPOS_PIXELS
  316. #define VTS_XSIZE_PIXELS VTS_I4 // OLE_XSIZE_PIXELS
  317. #define VTS_YSIZE_PIXELS VTS_I4 // OLE_YSIZE_PIXELS
  318. #define VTS_XPOS_HIMETRIC VTS_I4 // OLE_XPOS_HIMETRIC
  319. #define VTS_YPOS_HIMETRIC VTS_I4 // OLE_YPOS_HIMETRIC
  320. #define VTS_XSIZE_HIMETRIC VTS_I4 // OLE_XSIZE_HIMETRIC
  321. #define VTS_YSIZE_HIMETRIC VTS_I4 // OLE_YSIZE_HIMETRIC
  322. #define VTS_TRISTATE VTS_I2 // OLE_TRISTATE
  323. #define VTS_OPTEXCLUSIVE VTS_BOOL // OLE_OPTEXCLUSIVE
  324. #define VTS_PCOLOR VTS_PI4 // OLE_COLOR*
  325. #define VTS_PXPOS_PIXELS VTS_PI4 // OLE_XPOS_PIXELS*
  326. #define VTS_PYPOS_PIXELS VTS_PI4 // OLE_YPOS_PIXELS*
  327. #define VTS_PXSIZE_PIXELS VTS_PI4 // OLE_XSIZE_PIXELS*
  328. #define VTS_PYSIZE_PIXELS VTS_PI4 // OLE_YSIZE_PIXELS*
  329. #define VTS_PXPOS_HIMETRIC VTS_PI4 // OLE_XPOS_HIMETRIC*
  330. #define VTS_PYPOS_HIMETRIC VTS_PI4 // OLE_YPOS_HIMETRIC*
  331. #define VTS_PXSIZE_HIMETRIC VTS_PI4 // OLE_XSIZE_HIMETRIC*
  332. #define VTS_PYSIZE_HIMETRIC VTS_PI4 // OLE_YSIZE_HIMETRIC*
  333. #define VTS_PTRISTATE VTS_PI2 // OLE_TRISTATE*
  334. #define VTS_POPTEXCLUSIVE VTS_PBOOL // OLE_OPTEXCLUSIVE*
  335. #define VTS_FONT VTS_DISPATCH // IFontDispatch*
  336. #define VTS_PICTURE VTS_DISPATCH // IPictureDispatch*
  337. #define VTS_HANDLE VTS_I4 // OLE_HANDLE
  338. #define VTS_PHANDLE VTS_PI4 // OLE_HANDLE*
  339. // these DISP_ macros cause the framework to generate the DISPID
  340. #define DISP_FUNCTION(theClass, szExternalName, pfnMember, vtRetVal, vtsParams) \
  341. { _T(szExternalName), DISPID_UNKNOWN, vtsParams, vtRetVal, \
  342. (AFX_PMSG)(void (theClass::*)(void))&pfnMember, (AFX_PMSG)0, 0, \
  343. afxDispCustom }, \
  344. #define DISP_PROPERTY(theClass, szExternalName, memberName, vtPropType) \
  345. { _T(szExternalName), DISPID_UNKNOWN, NULL, vtPropType, (AFX_PMSG)0, (AFX_PMSG)0, \
  346. offsetof(theClass, memberName), afxDispCustom }, \
  347. #define DISP_PROPERTY_NOTIFY(theClass, szExternalName, memberName, pfnAfterSet, vtPropType) \
  348. { _T(szExternalName), DISPID_UNKNOWN, NULL, vtPropType, (AFX_PMSG)0, \
  349. (AFX_PMSG)(void (theClass::*)(void))&pfnAfterSet, \
  350. offsetof(theClass, memberName), afxDispCustom }, \
  351. #define DISP_PROPERTY_EX(theClass, szExternalName, pfnGet, pfnSet, vtPropType) \
  352. { _T(szExternalName), DISPID_UNKNOWN, NULL, vtPropType, \
  353. (AFX_PMSG)(void (theClass::*)(void))&pfnGet, \
  354. (AFX_PMSG)(void (theClass::*)(void))&pfnSet, 0, afxDispCustom }, \
  355. #define DISP_PROPERTY_PARAM(theClass, szExternalName, pfnGet, pfnSet, vtPropType, vtsParams) \
  356. { _T(szExternalName), DISPID_UNKNOWN, vtsParams, vtPropType, \
  357. (AFX_PMSG)(void (theClass::*)(void))&pfnGet, \
  358. (AFX_PMSG)(void (theClass::*)(void))&pfnSet, 0, afxDispCustom }, \
  359. // these DISP_ macros allow the app to determine the DISPID
  360. #define DISP_FUNCTION_ID(theClass, szExternalName, dispid, pfnMember, vtRetVal, vtsParams) \
  361. { _T(szExternalName), dispid, vtsParams, vtRetVal, \
  362. (AFX_PMSG)(void (theClass::*)(void))&pfnMember, (AFX_PMSG)0, 0, \
  363. afxDispCustom }, \
  364. #define DISP_PROPERTY_ID(theClass, szExternalName, dispid, memberName, vtPropType) \
  365. { _T(szExternalName), dispid, NULL, vtPropType, (AFX_PMSG)0, (AFX_PMSG)0, \
  366. offsetof(theClass, memberName), afxDispCustom }, \
  367. #define DISP_PROPERTY_NOTIFY_ID(theClass, szExternalName, dispid, memberName, pfnAfterSet, vtPropType) \
  368. { _T(szExternalName), dispid, NULL, vtPropType, (AFX_PMSG)0, \
  369. (AFX_PMSG)(void (theClass::*)(void))&pfnAfterSet, \
  370. offsetof(theClass, memberName), afxDispCustom }, \
  371. #define DISP_PROPERTY_EX_ID(theClass, szExternalName, dispid, pfnGet, pfnSet, vtPropType) \
  372. { _T(szExternalName), dispid, NULL, vtPropType, \
  373. (AFX_PMSG)(void (theClass::*)(void))&pfnGet, \
  374. (AFX_PMSG)(void (theClass::*)(void))&pfnSet, 0, afxDispCustom }, \
  375. #define DISP_PROPERTY_PARAM_ID(theClass, szExternalName, dispid, pfnGet, pfnSet, vtPropType, vtsParams) \
  376. { _T(szExternalName), dispid, vtsParams, vtPropType, \
  377. (AFX_PMSG)(void (theClass::*)(void))&pfnGet, \
  378. (AFX_PMSG)(void (theClass::*)(void))&pfnSet, 0, afxDispCustom }, \
  379. // the DISP_DEFVALUE is a special case macro that creates an alias for DISPID_VALUE
  380. #define DISP_DEFVALUE(theClass, szExternalName) \
  381. { _T(szExternalName), DISPID_UNKNOWN, NULL, VT_MFCVALUE, \
  382. (AFX_PMSG)0, (AFX_PMSG)0, 0, afxDispCustom }, \
  383. #define DISP_DEFVALUE_ID(theClass, dispid) \
  384. { NULL, dispid, NULL, VT_MFCVALUE, (AFX_PMSG)0, (AFX_PMSG)0, 0, \
  385. afxDispCustom }, \
  386. /////////////////////////////////////////////////////////////////////////////
  387. // Macros for creating "creatable" automation classes.
  388. #define DECLARE_OLECREATE(class_name) \
  389. public: \
  390. static AFX_DATA COleObjectFactory factory; \
  391. static AFX_DATA const GUID guid; \
  392. #define IMPLEMENT_OLECREATE(class_name, external_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  393. AFX_DATADEF COleObjectFactory class_name::factory(class_name::guid, \
  394. RUNTIME_CLASS(class_name), FALSE, _T(external_name)); \
  395. AFX_COMDAT const AFX_DATADEF GUID class_name::guid = \
  396. { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \
  397. /////////////////////////////////////////////////////////////////////////////
  398. // Helper class for driving IDispatch
  399. class COleDispatchDriver
  400. {
  401. // Constructors
  402. public:
  403. COleDispatchDriver();
  404. COleDispatchDriver(LPDISPATCH lpDispatch, BOOL bAutoRelease = TRUE);
  405. COleDispatchDriver(const COleDispatchDriver& dispatchSrc);
  406. // Attributes
  407. LPDISPATCH m_lpDispatch;
  408. BOOL m_bAutoRelease;
  409. // Operations
  410. BOOL CreateDispatch(REFCLSID clsid, COleException* pError = NULL);
  411. BOOL CreateDispatch(LPCTSTR lpszProgID, COleException* pError = NULL);
  412. void AttachDispatch(LPDISPATCH lpDispatch, BOOL bAutoRelease = TRUE);
  413. LPDISPATCH DetachDispatch();
  414. // detach and get ownership of m_lpDispatch
  415. void ReleaseDispatch();
  416. // helpers for IDispatch::Invoke
  417. void AFX_CDECL InvokeHelper(DISPID dwDispID, WORD wFlags,
  418. VARTYPE vtRet, void* pvRet, const BYTE* pbParamInfo, ...);
  419. void AFX_CDECL SetProperty(DISPID dwDispID, VARTYPE vtProp, ...);
  420. void GetProperty(DISPID dwDispID, VARTYPE vtProp, void* pvProp) const;
  421. // special operators
  422. operator LPDISPATCH();
  423. const COleDispatchDriver& operator=(const COleDispatchDriver& dispatchSrc);
  424. // Implementation
  425. public:
  426. ~COleDispatchDriver();
  427. void InvokeHelperV(DISPID dwDispID, WORD wFlags, VARTYPE vtRet,
  428. void* pvRet, const BYTE* pbParamInfo, va_list argList);
  429. };
  430. /////////////////////////////////////////////////////////////////////////////
  431. // Class Factory implementation (binds OLE class factory -> runtime class)
  432. // (all specific class factories derive from this class factory)
  433. class COleObjectFactory : public CCmdTarget
  434. {
  435. DECLARE_DYNAMIC(COleObjectFactory)
  436. // Construction
  437. public:
  438. COleObjectFactory(REFCLSID clsid, CRuntimeClass* pRuntimeClass,
  439. BOOL bMultiInstance, LPCTSTR lpszProgID);
  440. // Attributes
  441. virtual BOOL IsRegistered() const;
  442. REFCLSID GetClassID() const;
  443. // Operations
  444. virtual BOOL Register();
  445. BOOL Unregister();
  446. void Revoke();
  447. void UpdateRegistry(LPCTSTR lpszProgID = NULL);
  448. // default uses m_lpszProgID if not NULL
  449. BOOL IsLicenseValid();
  450. static BOOL PASCAL UnregisterAll();
  451. static BOOL PASCAL RegisterAll();
  452. static void PASCAL RevokeAll();
  453. static BOOL PASCAL UpdateRegistryAll(BOOL bRegister = TRUE);
  454. // Overridables
  455. protected:
  456. virtual CCmdTarget* OnCreateObject();
  457. virtual BOOL UpdateRegistry(BOOL bRegister);
  458. virtual BOOL VerifyUserLicense();
  459. virtual BOOL GetLicenseKey(DWORD dwReserved, BSTR* pbstrKey);
  460. virtual BOOL VerifyLicenseKey(BSTR bstrKey);
  461. // Implementation
  462. public:
  463. virtual ~COleObjectFactory();
  464. #ifdef _DEBUG
  465. void AssertValid() const;
  466. void Dump(CDumpContext& dc) const;
  467. #endif
  468. public:
  469. COleObjectFactory* m_pNextFactory; // list of factories maintained
  470. protected:
  471. DWORD m_dwRegister; // registry identifier
  472. CLSID m_clsid; // registered class ID
  473. CRuntimeClass* m_pRuntimeClass; // runtime class of CCmdTarget derivative
  474. BOOL m_bMultiInstance; // multiple instance?
  475. LPCTSTR m_lpszProgID; // human readable class ID
  476. BYTE m_bLicenseChecked;
  477. BYTE m_bLicenseValid;
  478. BYTE m_bRegistered; // is currently registered w/ system
  479. BYTE m_bOAT; // used by COleTemplateServer to
  480. // remember application type for unregistry
  481. // Interface Maps
  482. public:
  483. BEGIN_INTERFACE_PART(ClassFactory, IClassFactory2)
  484. INIT_INTERFACE_PART(COleObjectFactory, ClassFactory)
  485. STDMETHOD(CreateInstance)(LPUNKNOWN, REFIID, LPVOID*);
  486. STDMETHOD(LockServer)(BOOL);
  487. STDMETHOD(GetLicInfo)(LPLICINFO);
  488. STDMETHOD(RequestLicKey)(DWORD, BSTR*);
  489. STDMETHOD(CreateInstanceLic)(LPUNKNOWN, LPUNKNOWN, REFIID, BSTR,
  490. LPVOID*);
  491. END_INTERFACE_PART(ClassFactory)
  492. DECLARE_INTERFACE_MAP()
  493. friend SCODE AFXAPI AfxDllGetClassObject(REFCLSID, REFIID, LPVOID*);
  494. friend SCODE STDAPICALLTYPE DllGetClassObject(REFCLSID, REFIID, LPVOID*);
  495. };
  496. // Define COleObjectFactoryEx for compatibility with old CDK
  497. #define COleObjectFactoryEx COleObjectFactory
  498. //////////////////////////////////////////////////////////////////////////////
  499. // COleTemplateServer - COleObjectFactory using CDocTemplates
  500. // This enumeration is used in AfxOleRegisterServerClass to pick the
  501. // correct registration entries given the application type.
  502. enum OLE_APPTYPE
  503. {
  504. OAT_UNKNOWN = -1, // no type decided yet
  505. OAT_INPLACE_SERVER = 0, // server has full server user-interface
  506. OAT_SERVER = 1, // server supports only embedding
  507. OAT_CONTAINER = 2, // container supports links to embeddings
  508. OAT_DISPATCH_OBJECT = 3, // IDispatch capable object
  509. OAT_DOC_OBJECT_SERVER = 4, // sever supports DocObject embedding
  510. OAT_DOC_OBJECT_CONTAINER =5,// container supports DocObject clients
  511. };
  512. class COleTemplateServer : public COleObjectFactory
  513. {
  514. // Constructors
  515. public:
  516. COleTemplateServer();
  517. // Operations
  518. void ConnectTemplate(REFCLSID clsid, CDocTemplate* pDocTemplate,
  519. BOOL bMultiInstance);
  520. // set doc template after creating it in InitInstance
  521. void UpdateRegistry(OLE_APPTYPE nAppType = OAT_INPLACE_SERVER,
  522. LPCTSTR* rglpszRegister = NULL, LPCTSTR* rglpszOverwrite = NULL);
  523. // may want to UpdateRegistry if not run with /Embedded
  524. BOOL Register();
  525. BOOL Unregister();
  526. // Implementation
  527. protected:
  528. virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  529. AFX_CMDHANDLERINFO* pHandlerInfo);
  530. virtual CCmdTarget* OnCreateObject();
  531. CDocTemplate* m_pDocTemplate;
  532. private:
  533. void UpdateRegistry(LPCTSTR lpszProgID);
  534. // hide base class version of UpdateRegistry
  535. };
  536. /////////////////////////////////////////////////////////////////////////////
  537. // System registry helpers
  538. // Helper to register server in case of no .REG file loaded
  539. BOOL AFXAPI AfxOleRegisterServerClass(
  540. REFCLSID clsid, LPCTSTR lpszClassName,
  541. LPCTSTR lpszShortTypeName, LPCTSTR lpszLongTypeName,
  542. OLE_APPTYPE nAppType = OAT_SERVER,
  543. LPCTSTR* rglpszRegister = NULL, LPCTSTR* rglpszOverwrite = NULL,
  544. int nIconIndex = 0, LPCTSTR lpszLocalFilterName = NULL);
  545. BOOL AFXAPI AfxOleRegisterServerClass(
  546. REFCLSID clsid, LPCTSTR lpszClassName,
  547. LPCTSTR lpszShortTypeName, LPCTSTR lpszLongTypeName,
  548. OLE_APPTYPE nAppType,
  549. LPCTSTR* rglpszRegister, LPCTSTR* rglpszOverwrite,
  550. int nIconIndex, LPCTSTR lpszLocalFilterName, LPCTSTR lpszLocalFilterExt);
  551. BOOL AFXAPI AfxOleUnregisterServerClass(
  552. REFCLSID clsid, LPCTSTR lpszClassName, LPCTSTR lpszShortTypeName,
  553. LPCTSTR lpszLongTypeName, OLE_APPTYPE nAppType = OAT_SERVER,
  554. LPCTSTR* rglpszRegister = NULL, LPCTSTR* rglpszOverwrite = NULL);
  555. // AfxOleRegisterHelper is a worker function used by
  556. // AfxOleRegisterServerClass (available for advanced registry work)
  557. BOOL AFXAPI AfxOleRegisterHelper(LPCTSTR const* rglpszRegister,
  558. LPCTSTR const* rglpszSymbols, int nSymbols, BOOL bReplace,
  559. HKEY hKeyRoot = ((HKEY)0x80000000)); // HKEY_CLASSES_ROOT
  560. BOOL AFXAPI AfxOleUnregisterHelper(LPCTSTR const* rglpszRegister,
  561. LPCTSTR const* rglpszSymbols, int nSymbols,
  562. HKEY hKeyRoot = ((HKEY)0x80000000)); // HKEY_CLASSES_ROOT
  563. /////////////////////////////////////////////////////////////////////////////
  564. // Connection maps
  565. #define BEGIN_CONNECTION_PART(theClass, localClass) \
  566. class X##localClass : public CConnectionPoint \
  567. { \
  568. public: \
  569. X##localClass() \
  570. { m_nOffset = offsetof(theClass, m_x##localClass); }
  571. #define CONNECTION_IID(iid) \
  572. REFIID GetIID() { return iid; }
  573. #define END_CONNECTION_PART(localClass) \
  574. } m_x##localClass; \
  575. friend class X##localClass;
  576. #ifdef _AFXDLL
  577. #define BEGIN_CONNECTION_MAP(theClass, theBase) \
  578. const AFX_CONNECTIONMAP* PASCAL theClass::_GetBaseConnectionMap() \
  579. { return &theBase::connectionMap; } \
  580. const AFX_CONNECTIONMAP* theClass::GetConnectionMap() const \
  581. { return &theClass::connectionMap; } \
  582. AFX_COMDAT const AFX_DATADEF AFX_CONNECTIONMAP theClass::connectionMap = \
  583. { &theClass::_GetBaseConnectionMap, &theClass::_connectionEntries[0], }; \
  584. AFX_COMDAT const AFX_DATADEF AFX_CONNECTIONMAP_ENTRY theClass::_connectionEntries[] = \
  585. { \
  586. #else
  587. #define BEGIN_CONNECTION_MAP(theClass, theBase) \
  588. const AFX_CONNECTIONMAP* theClass::GetConnectionMap() const \
  589. { return &theClass::connectionMap; } \
  590. AFX_COMDAT const AFX_DATADEF AFX_CONNECTIONMAP theClass::connectionMap = \
  591. { &(theBase::connectionMap), &theClass::_connectionEntries[0], }; \
  592. AFX_COMDAT const AFX_DATADEF AFX_CONNECTIONMAP_ENTRY theClass::_connectionEntries[] = \
  593. { \
  594. #endif
  595. #define CONNECTION_PART(theClass, iid, localClass) \
  596. { &iid, offsetof(theClass, m_x##localClass) }, \
  597. #define END_CONNECTION_MAP() \
  598. { NULL, (size_t)-1 } \
  599. }; \
  600. /////////////////////////////////////////////////////////////////////////////
  601. // CConnectionPoint
  602. #ifdef _AFXDLL
  603. class CConnectionPoint : public CCmdTarget
  604. #else
  605. class AFX_NOVTABLE CConnectionPoint : public CCmdTarget
  606. #endif
  607. {
  608. // Constructors
  609. public:
  610. CConnectionPoint();
  611. // Operations
  612. POSITION GetStartPosition() const;
  613. LPUNKNOWN GetNextConnection(POSITION& pos) const;
  614. const CPtrArray* GetConnections(); // obsolete
  615. // Overridables
  616. virtual LPCONNECTIONPOINTCONTAINER GetContainer();
  617. virtual REFIID GetIID() = 0;
  618. virtual void OnAdvise(BOOL bAdvise);
  619. virtual int GetMaxConnections();
  620. virtual LPUNKNOWN QuerySinkInterface(LPUNKNOWN pUnkSink);
  621. // Implementation
  622. ~CConnectionPoint();
  623. void CreateConnectionArray();
  624. int GetConnectionCount();
  625. protected:
  626. size_t m_nOffset;
  627. LPUNKNOWN m_pUnkFirstConnection;
  628. CPtrArray* m_pConnections;
  629. // Interface Maps
  630. public:
  631. BEGIN_INTERFACE_PART(ConnPt, IConnectionPoint)
  632. INIT_INTERFACE_PART(CConnectionPoint, ConnPt)
  633. STDMETHOD(GetConnectionInterface)(IID* pIID);
  634. STDMETHOD(GetConnectionPointContainer)(
  635. IConnectionPointContainer** ppCPC);
  636. STDMETHOD(Advise)(LPUNKNOWN pUnkSink, DWORD* pdwCookie);
  637. STDMETHOD(Unadvise)(DWORD dwCookie);
  638. STDMETHOD(EnumConnections)(LPENUMCONNECTIONS* ppEnum);
  639. END_INTERFACE_PART(ConnPt)
  640. };
  641. /////////////////////////////////////////////////////////////////////////////
  642. // EventSink Maps
  643. #ifndef _AFX_NO_OCC_SUPPORT
  644. #ifdef _AFXDLL
  645. #define BEGIN_EVENTSINK_MAP(theClass, baseClass) \
  646. const AFX_EVENTSINKMAP* PASCAL theClass::_GetBaseEventSinkMap() \
  647. { return &baseClass::eventsinkMap; } \
  648. const AFX_EVENTSINKMAP* theClass::GetEventSinkMap() const \
  649. { return &theClass::eventsinkMap; } \
  650. const AFX_EVENTSINKMAP theClass::eventsinkMap = \
  651. { &theClass::_GetBaseEventSinkMap, &theClass::_eventsinkEntries[0], \
  652. &theClass::_eventsinkEntryCount }; \
  653. UINT theClass::_eventsinkEntryCount = (UINT)-1; \
  654. const AFX_EVENTSINKMAP_ENTRY theClass::_eventsinkEntries[] = \
  655. { \
  656. #else
  657. #define BEGIN_EVENTSINK_MAP(theClass, baseClass) \
  658. const AFX_EVENTSINKMAP* theClass::GetEventSinkMap() const \
  659. { return &theClass::eventsinkMap; } \
  660. const AFX_EVENTSINKMAP theClass::eventsinkMap = \
  661. { &baseClass::eventsinkMap, &theClass::_eventsinkEntries[0], \
  662. &theClass::_eventsinkEntryCount }; \
  663. UINT theClass::_eventsinkEntryCount = (UINT)-1; \
  664. const AFX_EVENTSINKMAP_ENTRY theClass::_eventsinkEntries[] = \
  665. { \
  666. #endif
  667. #define END_EVENTSINK_MAP() \
  668. { VTS_NONE, DISPID_UNKNOWN, VTS_NONE, VT_VOID, \
  669. (AFX_PMSG)NULL, (AFX_PMSG)NULL, (size_t)-1, afxDispCustom, \
  670. (UINT)-1, 0 } }; \
  671. #define ON_EVENT(theClass, id, dispid, pfnHandler, vtsParams) \
  672. { _T(""), dispid, vtsParams, VT_BOOL, \
  673. (AFX_PMSG)(void (theClass::*)(void))&pfnHandler, (AFX_PMSG)0, 0, \
  674. afxDispCustom, id, (UINT)-1 }, \
  675. #define ON_EVENT_RANGE(theClass, idFirst, idLast, dispid, pfnHandler, vtsParams) \
  676. { _T(""), dispid, vtsParams, VT_BOOL, \
  677. (AFX_PMSG)(void (theClass::*)(void))&pfnHandler, (AFX_PMSG)0, 0, \
  678. afxDispCustom, idFirst, idLast }, \
  679. #define ON_PROPNOTIFY(theClass, id, dispid, pfnRequest, pfnChanged) \
  680. { _T(""), dispid, VTS_NONE, VT_VOID, \
  681. (AFX_PMSG)(BOOL (CCmdTarget::*)(BOOL*))&pfnRequest, \
  682. (AFX_PMSG)(BOOL (CCmdTarget::*)(void))&pfnChanged, \
  683. 1, afxDispCustom, id, (UINT)-1 }, \
  684. #define ON_PROPNOTIFY_RANGE(theClass, idFirst, idLast, dispid, pfnRequest, pfnChanged) \
  685. { _T(""), dispid, VTS_NONE, VT_VOID, \
  686. (AFX_PMSG)(BOOL (CCmdTarget::*)(UINT, BOOL*))&pfnRequest, \
  687. (AFX_PMSG)(BOOL (CCmdTarget::*)(UINT))&pfnChanged, \
  688. 1, afxDispCustom, idFirst, idLast }, \
  689. #define ON_DSCNOTIFY(theClass, id, pfnNotify) \
  690. { _T(""), DISPID_UNKNOWN, VTS_NONE, VT_VOID, \
  691. (AFX_PMSG)(BOOL (CCmdTarget::*)(DSCSTATE, DSCREASON, BOOL*))&pfnNotify, (AFX_PMSG)0, \
  692. 1, afxDispCustom, id, (UINT)-1 }, \
  693. #define ON_DSCNOTIFY_RANGE(theClass, idFirst, idLast, pfnNotify) \
  694. { _T(""), DISPID_UNKNOWN, VTS_NONE, VT_VOID, \
  695. (AFX_PMSG)(BOOL (CCmdTarget::*)(UINT, DSCSTATE, DSCREASON, BOOL*))&pfnNotify, (AFX_PMSG)0, \
  696. 1, afxDispCustom, idFirst, idLast }, \
  697. #define ON_EVENT_REFLECT(theClass, dispid, pfnHandler, vtsParams) \
  698. { _T(""), dispid, vtsParams, VT_BOOL, \
  699. (AFX_PMSG)(void (theClass::*)(void))&pfnHandler, (AFX_PMSG)0, 0, \
  700. afxDispCustom, (UINT)-1, (UINT)-1 }, \
  701. #define ON_PROPNOTIFY_REFLECT(theClass, dispid, pfnRequest, pfnChanged) \
  702. { _T(""), dispid, VTS_NONE, VT_VOID, \
  703. (AFX_PMSG)(BOOL (CCmdTarget::*)(BOOL*))&pfnRequest, \
  704. (AFX_PMSG)(BOOL (CCmdTarget::*)(void))&pfnChanged, \
  705. 1, afxDispCustom, (UINT)-1, (UINT)-1 }, \
  706. #endif // !_AFX_NO_OCC_SUPPORT
  707. /////////////////////////////////////////////////////////////////////////////
  708. // Macros for type library information
  709. CTypeLibCache* AFXAPI AfxGetTypeLibCache(const GUID* pTypeLibID);
  710. #define DECLARE_OLETYPELIB(class_name) \
  711. protected: \
  712. virtual UINT GetTypeInfoCount(); \
  713. virtual HRESULT GetTypeLib(LCID, LPTYPELIB*); \
  714. virtual CTypeLibCache* GetTypeLibCache(); \
  715. #define IMPLEMENT_OLETYPELIB(class_name, tlid, wVerMajor, wVerMinor) \
  716. UINT class_name::GetTypeInfoCount() \
  717. { return 1; } \
  718. HRESULT class_name::GetTypeLib(LCID lcid, LPTYPELIB* ppTypeLib) \
  719. { return ::LoadRegTypeLib(tlid, wVerMajor, wVerMinor, lcid, ppTypeLib); } \
  720. CTypeLibCache* class_name::GetTypeLibCache() \
  721. { AFX_MANAGE_STATE(m_pModuleState); return AfxGetTypeLibCache(&tlid); } \
  722. /////////////////////////////////////////////////////////////////////////////
  723. // Init & Term helpers
  724. BOOL AFXAPI AfxOleInit();
  725. void AFXAPI AfxOleTerm(BOOL bJustRevoke = FALSE);
  726. void AFXAPI AfxOleTermOrFreeLib(BOOL bTerm = TRUE, BOOL bJustRevoke = FALSE);
  727. /////////////////////////////////////////////////////////////////////////////
  728. // Memory management helpers (for OLE task allocator memory)
  729. #define AfxAllocTaskMem(nSize) CoTaskMemAlloc(nSize)
  730. #define AfxFreeTaskMem(p) CoTaskMemFree(p)
  731. LPWSTR AFXAPI AfxAllocTaskWideString(LPCWSTR lpszString);
  732. LPWSTR AFXAPI AfxAllocTaskWideString(LPCSTR lpszString);
  733. LPSTR AFXAPI AfxAllocTaskAnsiString(LPCWSTR lpszString);
  734. LPSTR AFXAPI AfxAllocTaskAnsiString(LPCSTR lpszString);
  735. #ifdef _UNICODE
  736. #define AfxAllocTaskString(x) AfxAllocTaskWideString(x)
  737. #else
  738. #define AfxAllocTaskString(x) AfxAllocTaskAnsiString(x)
  739. #endif
  740. #ifdef OLE2ANSI
  741. #define AfxAllocTaskOleString(x) AfxAllocTaskAnsiString(x)
  742. #else
  743. #define AfxAllocTaskOleString(x) AfxAllocTaskWideString(x)
  744. #endif
  745. HRESULT AFXAPI AfxGetClassIDFromString(LPCTSTR lpsz, LPCLSID lpClsID);
  746. /////////////////////////////////////////////////////////////////////////////
  747. // Special in-proc server APIs
  748. SCODE AFXAPI AfxDllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv);
  749. SCODE AFXAPI AfxDllCanUnloadNow(void);
  750. /////////////////////////////////////////////////////////////////////////////
  751. // COleVariant class helpers
  752. #define AFX_OLE_TRUE (-1)
  753. #define AFX_OLE_FALSE 0
  754. class CLongBinary; // forward reference (see afxdb_.h)
  755. /////////////////////////////////////////////////////////////////////////////
  756. // COleVariant class - wraps VARIANT types
  757. typedef const VARIANT* LPCVARIANT;
  758. class COleVariant : public tagVARIANT
  759. {
  760. // Constructors
  761. public:
  762. COleVariant();
  763. COleVariant(const VARIANT& varSrc);
  764. COleVariant(LPCVARIANT pSrc);
  765. COleVariant(const COleVariant& varSrc);
  766. COleVariant(LPCTSTR lpszSrc);
  767. COleVariant(LPCTSTR lpszSrc, VARTYPE vtSrc); // used to set to ANSI string
  768. COleVariant(CString& strSrc);
  769. COleVariant(BYTE nSrc);
  770. COleVariant(short nSrc, VARTYPE vtSrc = VT_I2);
  771. COleVariant(long lSrc, VARTYPE vtSrc = VT_I4);
  772. COleVariant(const COleCurrency& curSrc);
  773. COleVariant(float fltSrc);
  774. COleVariant(double dblSrc);
  775. COleVariant(const COleDateTime& timeSrc);
  776. COleVariant(const CByteArray& arrSrc);
  777. COleVariant(const CLongBinary& lbSrc);
  778. COleVariant(LPCITEMIDLIST pidl);
  779. // Operations
  780. public:
  781. void Clear();
  782. void ChangeType(VARTYPE vartype, LPVARIANT pSrc = NULL);
  783. void Attach(VARIANT& varSrc);
  784. VARIANT Detach();
  785. BOOL operator==(const VARIANT& varSrc) const;
  786. BOOL operator==(LPCVARIANT pSrc) const;
  787. const COleVariant& operator=(const VARIANT& varSrc);
  788. const COleVariant& operator=(LPCVARIANT pSrc);
  789. const COleVariant& operator=(const COleVariant& varSrc);
  790. const COleVariant& operator=(const LPCTSTR lpszSrc);
  791. const COleVariant& operator=(const CString& strSrc);
  792. const COleVariant& operator=(BYTE nSrc);
  793. const COleVariant& operator=(short nSrc);
  794. const COleVariant& operator=(long lSrc);
  795. const COleVariant& operator=(const COleCurrency& curSrc);
  796. const COleVariant& operator=(float fltSrc);
  797. const COleVariant& operator=(double dblSrc);
  798. const COleVariant& operator=(const COleDateTime& dateSrc);
  799. const COleVariant& operator=(const CByteArray& arrSrc);
  800. const COleVariant& operator=(const CLongBinary& lbSrc);
  801. void SetString(LPCTSTR lpszSrc, VARTYPE vtSrc); // used to set ANSI string
  802. operator LPVARIANT();
  803. operator LPCVARIANT() const;
  804. // Implementation
  805. public:
  806. ~COleVariant();
  807. void _ClearCompat();
  808. };
  809. // COleVariant diagnostics and serialization
  810. #ifdef _DEBUG
  811. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleVariant varSrc);
  812. #endif
  813. CArchive& AFXAPI operator<<(CArchive& ar, COleVariant varSrc);
  814. CArchive& AFXAPI operator>>(CArchive& ar, COleVariant& varSrc);
  815. // Helper for initializing VARIANT structures
  816. void AFXAPI AfxVariantInit(LPVARIANT pVar);
  817. /////////////////////////////////////////////////////////////////////////////
  818. // COleCurrency class
  819. class COleCurrency
  820. {
  821. // Constructors
  822. public:
  823. COleCurrency();
  824. COleCurrency(CURRENCY cySrc);
  825. COleCurrency(const COleCurrency& curSrc);
  826. COleCurrency(const VARIANT& varSrc);
  827. COleCurrency(long nUnits, long nFractionalUnits);
  828. // Attributes
  829. public:
  830. enum CurrencyStatus
  831. {
  832. valid = 0,
  833. invalid = 1, // Invalid currency (overflow, div 0, etc.)
  834. null = 2, // Literally has no value
  835. };
  836. CURRENCY m_cur;
  837. CurrencyStatus m_status;
  838. void SetStatus(CurrencyStatus status);
  839. CurrencyStatus GetStatus() const;
  840. // Operations
  841. public:
  842. const COleCurrency& operator=(CURRENCY cySrc);
  843. const COleCurrency& operator=(const COleCurrency& curSrc);
  844. const COleCurrency& operator=(const VARIANT& varSrc);
  845. BOOL operator==(const COleCurrency& cur) const;
  846. BOOL operator!=(const COleCurrency& cur) const;
  847. BOOL operator<(const COleCurrency& cur) const;
  848. BOOL operator>(const COleCurrency& cur) const;
  849. BOOL operator<=(const COleCurrency& cur) const;
  850. BOOL operator>=(const COleCurrency& cur) const;
  851. // Currency math
  852. COleCurrency operator+(const COleCurrency& cur) const;
  853. COleCurrency operator-(const COleCurrency& cur) const;
  854. const COleCurrency& operator+=(const COleCurrency& cur);
  855. const COleCurrency& operator-=(const COleCurrency& cur);
  856. COleCurrency operator-() const;
  857. COleCurrency operator*(long nOperand) const;
  858. COleCurrency operator/(long nOperand) const;
  859. const COleCurrency& operator*=(long nOperand);
  860. const COleCurrency& operator/=(long nOperand);
  861. operator CURRENCY() const;
  862. // Currency definition
  863. void SetCurrency(long nUnits, long nFractionalUnits);
  864. BOOL ParseCurrency(LPCTSTR lpszCurrency, DWORD dwFlags = 0,
  865. LCID = LANG_USER_DEFAULT);
  866. // formatting
  867. CString Format(DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT) const;
  868. };
  869. // COleCurrency diagnostics and serialization
  870. #ifdef _DEBUG
  871. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleCurrency curSrc);
  872. #endif
  873. CArchive& AFXAPI operator<<(CArchive& ar, COleCurrency curSrc);
  874. CArchive& AFXAPI operator>>(CArchive& ar, COleCurrency& curSrc);
  875. /////////////////////////////////////////////////////////////////////////////
  876. // COleDateTime class helpers
  877. #define AFX_OLE_DATETIME_ERROR (-1)
  878. #define AFX_OLE_DATETIME_HALFSECOND (1.0 / (2.0 * (60.0 * 60.0 * 24.0)))
  879. /////////////////////////////////////////////////////////////////////////////
  880. // COleDateTime class
  881. class COleDateTime
  882. {
  883. // Constructors
  884. public:
  885. static COleDateTime PASCAL GetCurrentTime();
  886. COleDateTime();
  887. COleDateTime(const COleDateTime& dateSrc);
  888. COleDateTime(const VARIANT& varSrc);
  889. COleDateTime(DATE dtSrc);
  890. COleDateTime(time_t timeSrc);
  891. COleDateTime(const SYSTEMTIME& systimeSrc);
  892. COleDateTime(const FILETIME& filetimeSrc);
  893. COleDateTime(int nYear, int nMonth, int nDay,
  894. int nHour, int nMin, int nSec);
  895. COleDateTime(WORD wDosDate, WORD wDosTime);
  896. // Attributes
  897. public:
  898. enum DateTimeStatus
  899. {
  900. valid = 0,
  901. invalid = 1, // Invalid date (out of range, etc.)
  902. null = 2, // Literally has no value
  903. };
  904. DATE m_dt;
  905. DateTimeStatus m_status;
  906. void SetStatus(DateTimeStatus status);
  907. DateTimeStatus GetStatus() const;
  908. BOOL GetAsSystemTime(SYSTEMTIME& sysTime) const;
  909. int GetYear() const;
  910. int GetMonth() const; // month of year (1 = Jan)
  911. int GetDay() const; // day of month (0-31)
  912. int GetHour() const; // hour in day (0-23)
  913. int GetMinute() const; // minute in hour (0-59)
  914. int GetSecond() const; // second in minute (0-59)
  915. int GetDayOfWeek() const; // 1=Sun, 2=Mon, ..., 7=Sat
  916. int GetDayOfYear() const; // days since start of year, Jan 1 = 1
  917. // Operations
  918. public:
  919. const COleDateTime& operator=(const COleDateTime& dateSrc);
  920. const COleDateTime& operator=(const VARIANT& varSrc);
  921. const COleDateTime& operator=(DATE dtSrc);
  922. const COleDateTime& operator=(const time_t& timeSrc);
  923. const COleDateTime& operator=(const SYSTEMTIME& systimeSrc);
  924. const COleDateTime& operator=(const FILETIME& filetimeSrc);
  925. BOOL operator==(const COleDateTime& date) const;
  926. BOOL operator!=(const COleDateTime& date) const;
  927. BOOL operator<(const COleDateTime& date) const;
  928. BOOL operator>(const COleDateTime& date) const;
  929. BOOL operator<=(const COleDateTime& date) const;
  930. BOOL operator>=(const COleDateTime& date) const;
  931. // DateTime math
  932. COleDateTime operator+(const COleDateTimeSpan& dateSpan) const;
  933. COleDateTime operator-(const COleDateTimeSpan& dateSpan) const;
  934. const COleDateTime& operator+=(const COleDateTimeSpan dateSpan);
  935. const COleDateTime& operator-=(const COleDateTimeSpan dateSpan);
  936. // DateTimeSpan math
  937. COleDateTimeSpan operator-(const COleDateTime& date) const;
  938. operator DATE() const;
  939. int SetDateTime(int nYear, int nMonth, int nDay,
  940. int nHour, int nMin, int nSec);
  941. int SetDate(int nYear, int nMonth, int nDay);
  942. int SetTime(int nHour, int nMin, int nSec);
  943. BOOL ParseDateTime(LPCTSTR lpszDate, DWORD dwFlags = 0,
  944. LCID lcid = LANG_USER_DEFAULT);
  945. // formatting
  946. CString Format(DWORD dwFlags = 0, LCID lcid = LANG_USER_DEFAULT) const;
  947. CString Format(LPCTSTR lpszFormat) const;
  948. CString Format(UINT nFormatID) const;
  949. // Implementation
  950. protected:
  951. void CheckRange();
  952. friend COleDateTimeSpan;
  953. };
  954. // COleDateTime diagnostics and serialization
  955. #ifdef _DEBUG
  956. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleDateTime dateSrc);
  957. #endif
  958. CArchive& AFXAPI operator<<(CArchive& ar, COleDateTime dateSrc);
  959. CArchive& AFXAPI operator>>(CArchive& ar, COleDateTime& dateSrc);
  960. /////////////////////////////////////////////////////////////////////////////
  961. // COleDateTimeSpan class
  962. class COleDateTimeSpan
  963. {
  964. // Constructors
  965. public:
  966. COleDateTimeSpan();
  967. COleDateTimeSpan(double dblSpanSrc);
  968. COleDateTimeSpan(const COleDateTimeSpan& dateSpanSrc);
  969. COleDateTimeSpan(long lDays, int nHours, int nMins, int nSecs);
  970. // Attributes
  971. public:
  972. enum DateTimeSpanStatus
  973. {
  974. valid = 0,
  975. invalid = 1, // Invalid span (out of range, etc.)
  976. null = 2, // Literally has no value
  977. };
  978. double m_span;
  979. DateTimeSpanStatus m_status;
  980. void SetStatus(DateTimeSpanStatus status);
  981. DateTimeSpanStatus GetStatus() const;
  982. double GetTotalDays() const; // span in days (about -3.65e6 to 3.65e6)
  983. double GetTotalHours() const; // span in hours (about -8.77e7 to 8.77e6)
  984. double GetTotalMinutes() const; // span in minutes (about -5.26e9 to 5.26e9)
  985. double GetTotalSeconds() const; // span in seconds (about -3.16e11 to 3.16e11)
  986. long GetDays() const; // component days in span
  987. long GetHours() const; // component hours in span (-23 to 23)
  988. long GetMinutes() const; // component minutes in span (-59 to 59)
  989. long GetSeconds() const; // component seconds in span (-59 to 59)
  990. // Operations
  991. public:
  992. const COleDateTimeSpan& operator=(double dblSpanSrc);
  993. const COleDateTimeSpan& operator=(const COleDateTimeSpan& dateSpanSrc);
  994. BOOL operator==(const COleDateTimeSpan& dateSpan) const;
  995. BOOL operator!=(const COleDateTimeSpan& dateSpan) const;
  996. BOOL operator<(const COleDateTimeSpan& dateSpan) const;
  997. BOOL operator>(const COleDateTimeSpan& dateSpan) const;
  998. BOOL operator<=(const COleDateTimeSpan& dateSpan) const;
  999. BOOL operator>=(const COleDateTimeSpan& dateSpan) const;
  1000. // DateTimeSpan math
  1001. COleDateTimeSpan operator+(const COleDateTimeSpan& dateSpan) const;
  1002. COleDateTimeSpan operator-(const COleDateTimeSpan& dateSpan) const;
  1003. const COleDateTimeSpan& operator+=(const COleDateTimeSpan dateSpan);
  1004. const COleDateTimeSpan& operator-=(const COleDateTimeSpan dateSpan);
  1005. COleDateTimeSpan operator-() const;
  1006. operator double() const;
  1007. void SetDateTimeSpan(long lDays, int nHours, int nMins, int nSecs);
  1008. // formatting
  1009. CString Format(LPCTSTR pFormat) const;
  1010. CString Format(UINT nID) const;
  1011. // Implementation
  1012. public:
  1013. void CheckRange();
  1014. friend COleDateTime;
  1015. };
  1016. // COleDateTimeSpan diagnostics and serialization
  1017. #ifdef _DEBUG
  1018. CDumpContext& AFXAPI operator<<(CDumpContext& dc,COleDateTimeSpan dateSpanSrc);
  1019. #endif
  1020. CArchive& AFXAPI operator<<(CArchive& ar, COleDateTimeSpan dateSpanSrc);
  1021. CArchive& AFXAPI operator>>(CArchive& ar, COleDateTimeSpan& dateSpanSrc);
  1022. /////////////////////////////////////////////////////////////////////////////
  1023. // Helper for initializing COleSafeArray
  1024. void AFXAPI AfxSafeArrayInit(COleSafeArray* psa);
  1025. /////////////////////////////////////////////////////////////////////////////
  1026. // CSafeArray class
  1027. typedef const SAFEARRAY* LPCSAFEARRAY;
  1028. class COleSafeArray : public tagVARIANT
  1029. {
  1030. //Constructors
  1031. public:
  1032. COleSafeArray();
  1033. COleSafeArray(const SAFEARRAY& saSrc, VARTYPE vtSrc);
  1034. COleSafeArray(LPCSAFEARRAY pSrc, VARTYPE vtSrc);
  1035. COleSafeArray(const COleSafeArray& saSrc);
  1036. COleSafeArray(const VARIANT& varSrc);
  1037. COleSafeArray(LPCVARIANT pSrc);
  1038. COleSafeArray(const COleVariant& varSrc);
  1039. // Operations
  1040. public:
  1041. void Clear();
  1042. void Attach(VARIANT& varSrc);
  1043. VARIANT Detach();
  1044. COleSafeArray& operator=(const COleSafeArray& saSrc);
  1045. COleSafeArray& operator=(const VARIANT& varSrc);
  1046. COleSafeArray& operator=(LPCVARIANT pSrc);
  1047. COleSafeArray& operator=(const COleVariant& varSrc);
  1048. BOOL operator==(const SAFEARRAY& saSrc) const;
  1049. BOOL operator==(LPCSAFEARRAY pSrc) const;
  1050. BOOL operator==(const COleSafeArray& saSrc) const;
  1051. BOOL operator==(const VARIANT& varSrc) const;
  1052. BOOL operator==(LPCVARIANT pSrc) const;
  1053. BOOL operator==(const COleVariant& varSrc) const;
  1054. operator LPVARIANT();
  1055. operator LPCVARIANT() const;
  1056. // One dim array helpers
  1057. void CreateOneDim(VARTYPE vtSrc, DWORD dwElements,
  1058. const void* pvSrcData = NULL, long nLBound = 0);
  1059. DWORD GetOneDimSize();
  1060. void ResizeOneDim(DWORD dwElements);
  1061. // Multi dim array helpers
  1062. void Create(VARTYPE vtSrc, DWORD dwDims, DWORD* rgElements);
  1063. // SafeArray wrapper classes
  1064. void Create(VARTYPE vtSrc, DWORD dwDims, SAFEARRAYBOUND* rgsabounds);
  1065. void AccessData(void** ppvData);
  1066. void UnaccessData();
  1067. void AllocData();
  1068. void AllocDescriptor(DWORD dwDims);
  1069. void Copy(LPSAFEARRAY* ppsa);
  1070. void GetLBound(DWORD dwDim, long* pLBound);
  1071. void GetUBound(DWORD dwDim, long* pUBound);
  1072. void GetElement(long* rgIndices, void* pvData);
  1073. void PtrOfIndex(long* rgIndices, void** ppvData);
  1074. void PutElement(long* rgIndices, void* pvData);
  1075. void Redim(SAFEARRAYBOUND* psaboundNew);
  1076. void Lock();
  1077. void Unlock();
  1078. DWORD GetDim();
  1079. DWORD GetElemSize();
  1080. void Destroy();
  1081. void DestroyData();
  1082. void DestroyDescriptor();
  1083. //Implementation
  1084. public:
  1085. ~COleSafeArray();
  1086. // Cache info to make element access (operator []) faster
  1087. DWORD m_dwElementSize;
  1088. DWORD m_dwDims;
  1089. };
  1090. // COleSafeArray diagnostics and serialization
  1091. #ifdef _DEBUG
  1092. CDumpContext& AFXAPI operator<<(CDumpContext& dc, COleSafeArray& saSrc);
  1093. #endif
  1094. /////////////////////////////////////////////////////////////////////////////
  1095. // DDX_ functions for OLE controls on dialogs
  1096. #ifndef _AFX_NO_OCC_SUPPORT
  1097. void AFXAPI DDX_OCText(CDataExchange* pDX, int nIDC, DISPID dispid,
  1098. CString& value);
  1099. void AFXAPI DDX_OCTextRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1100. CString& value);
  1101. void AFXAPI DDX_OCBool(CDataExchange* pDX, int nIDC, DISPID dispid,
  1102. BOOL& value);
  1103. void AFXAPI DDX_OCBoolRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1104. BOOL& value);
  1105. void AFXAPI DDX_OCInt(CDataExchange* pDX, int nIDC, DISPID dispid,
  1106. int &value);
  1107. void AFXAPI DDX_OCIntRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1108. int &value);
  1109. void AFXAPI DDX_OCInt(CDataExchange* pDX, int nIDC, DISPID dispid,
  1110. long &value);
  1111. void AFXAPI DDX_OCIntRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1112. long &value);
  1113. void AFXAPI DDX_OCShort(CDataExchange* pDX, int nIDC, DISPID dispid,
  1114. short& value);
  1115. void AFXAPI DDX_OCShortRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1116. short& value);
  1117. void AFXAPI DDX_OCColor(CDataExchange* pDX, int nIDC, DISPID dispid,
  1118. OLE_COLOR& value);
  1119. void AFXAPI DDX_OCColorRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1120. OLE_COLOR& value);
  1121. void AFXAPI DDX_OCFloat(CDataExchange* pDX, int nIDC, DISPID dispid,
  1122. float& value);
  1123. void AFXAPI DDX_OCFloatRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1124. float& value);
  1125. void AFXAPI DDX_OCFloat(CDataExchange* pDX, int nIDC, DISPID dispid,
  1126. double& value);
  1127. void AFXAPI DDX_OCFloatRO(CDataExchange* pDX, int nIDC, DISPID dispid,
  1128. double& value);
  1129. #endif // !_AFX_NO_OCC_SUPPORT
  1130. /////////////////////////////////////////////////////////////////////////////
  1131. // Function to enable containment of OLE controls
  1132. #ifndef _AFX_NO_OCC_SUPPORT
  1133. void AFX_CDECL AfxEnableControlContainer(COccManager* pOccManager=NULL);
  1134. #else
  1135. #define AfxEnableControlContainer()
  1136. #endif
  1137. /////////////////////////////////////////////////////////////////////////////
  1138. // Inline function declarations
  1139. #ifdef _AFX_PACKING
  1140. #pragma pack(pop)
  1141. #endif
  1142. #ifdef _AFX_ENABLE_INLINES
  1143. #define _AFXDISP_INLINE AFX_INLINE
  1144. #include <afxole.inl>
  1145. #undef _AFXDISP_INLINE
  1146. #endif
  1147. #undef AFX_DATA
  1148. #define AFX_DATA
  1149. #ifdef _AFX_MINREBUILD
  1150. #pragma component(minrebuild, on)
  1151. #endif
  1152. #ifndef _AFX_FULLTYPEINFO
  1153. #pragma component(mintypeinfo, off)
  1154. #endif
  1155. #endif //__AFXDISP_H__
  1156. /////////////////////////////////////////////////////////////////////////////