home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MFCINC.PAK / AFXDISP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  43.8 KB  |  1,304 lines

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