Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1456 lines
49 KiB

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