home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / msinc.pak / COMPOBJ.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  35KB  |  1,051 lines

  1. /*****************************************************************************\
  2. *                                                                             *
  3. * compobj.h -   Component object model definitions                                                        *
  4. *                                                                             *
  5. *               OLE Version 2.0                                               *
  6. *                                                                             *
  7. \*****************************************************************************/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 6.5
  11.  *
  12.  *      Copyright (c) 1994 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17. #if !defined(__FLAT__)
  18. #if !defined( _COMPOBJ_H_ )
  19. #define _COMPOBJ_H_
  20. #define __COMPOBJ_H
  21.  
  22. /****** Linkage Definitions *************************************************/
  23.  
  24. /*
  25.  *      These are macros for declaring methods/functions.  They exist so that
  26.  *      control over the use of keywords (CDECL, PASCAL, __export,
  27.  *      extern "C") resides in one place, and because this is the least
  28.  *      intrusive way of writing function declarations that do not have
  29.  *      to be modified in order to port to the Mac.
  30.  *
  31.  *      The macros without the trailing underscore are for functions/methods
  32.  *      which a return value of type HRESULT; this is by far the most common
  33.  *      case in OLE. The macros with a trailing underscore take a return
  34.  *      type as a parameter.
  35.  *
  36.  * WARNING: STDAPI is hard coded into the LPFNGETCLASSOBJECT typedef below.
  37.  */
  38.  
  39. #ifdef __cplusplus
  40.     #define EXTERN_C    extern "C"
  41. #else
  42.     #define EXTERN_C    extern
  43. #endif
  44.  
  45. #ifdef _MAC
  46. #define STDMETHODCALLTYPE
  47. #define STDAPICALLTYPE          pascal
  48.  
  49. #define STDAPI                  EXTERN_C STDAPICALLTYPE HRESULT
  50. #define STDAPI_(type)           EXTERN_C STDAPICALLTYPE type
  51.  
  52. #else   //  !_MAC
  53.  
  54. #ifdef WIN32
  55. #define STDMETHODCALLTYPE       __export __cdecl
  56. #define STDAPICALLTYPE          __export __stdcall
  57.  
  58. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  59. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  60.  
  61. #else
  62. #define STDMETHODCALLTYPE       __export FAR CDECL
  63. #define STDAPICALLTYPE          __export FAR PASCAL
  64.  
  65. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  66. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  67.  
  68. #endif
  69.  
  70. #endif //!_MAC
  71.  
  72. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  73. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  74.  
  75.  
  76. /****** Interface Declaration ***********************************************/
  77.  
  78. /*
  79.  *      These are macros for declaring interfaces.  They exist so that
  80.  *      a single definition of the interface is simulataneously a proper
  81.  *      declaration of the interface structures (C++ abstract classes)
  82.  *      for both C and C++.
  83.  *
  84.  *      DECLARE_INTERFACE(iface) is used to declare an interface that does
  85.  *      not derive from a base interface.
  86.  *      DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface
  87.  *      that does derive from a base interface.
  88.  *
  89.  *      By default if the source file has a .c extension the C version of
  90.  *      the interface declaratations will be expanded; if it has a .cpp
  91.  *      extension the C++ version will be expanded. if you want to force
  92.  *      the C version expansion even though the source file has a .cpp
  93.  *      extension, then define the macro "CINTERFACE".
  94.  *      eg.     cl -DCINTERFACE file.cpp
  95.  *
  96.  *      Example Interface declaration:
  97.  *
  98.  *          #undef  INTERFACE
  99.  *          #define INTERFACE   IClassFactory
  100.  *
  101.  *          DECLARE_INTERFACE_(IClassFactory, IUnknown)
  102.  *          {
  103.  *              // *** IUnknown methods ***
  104.  *              STDMETHOD(QueryInterface) (THIS_
  105.  *                                        REFIID riid,
  106.  *                                        LPVOID FAR* ppvObj) PURE;
  107.  *              STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  108.  *              STDMETHOD_(ULONG,Release) (THIS) PURE;
  109.  *
  110.  *              // *** IClassFactory methods ***
  111.  *              STDMETHOD(CreateInstance) (THIS_
  112.  *                                        LPUNKNOWN pUnkOuter,
  113.  *                                        REFIID riid,
  114.  *                                        LPVOID FAR* ppvObject) PURE;
  115.  *          };
  116.  *
  117.  *      Example C++ expansion:
  118.  *
  119.  *          struct FAR IClassFactory : public IUnknown
  120.  *          {
  121.  *              virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  122.  *                                                  IID FAR& riid,
  123.  *                                                  LPVOID FAR* ppvObj) = 0;
  124.  *              virtual HRESULT STDMETHODCALLTYPE AddRef(void) = 0;
  125.  *              virtual HRESULT STDMETHODCALLTYPE Release(void) = 0;
  126.  *              virtual HRESULT STDMETHODCALLTYPE CreateInstance(
  127.  *                                              LPUNKNOWN pUnkOuter,
  128.  *                                              IID FAR& riid,
  129.  *                                              LPVOID FAR* ppvObject) = 0;
  130.  *          };
  131.  *
  132.  *          NOTE: Our documentation says '#define interface class' but we use
  133.  *          'struct' instead of 'class' to keep a lot of 'public:' lines
  134.  *          out of the interfaces.  The 'FAR' forces the 'this' pointers to
  135.  *          be far, which is what we need.
  136.  *
  137.  *      Example C expansion:
  138.  *
  139.  *          typedef struct IClassFactory
  140.  *          {
  141.  *              const struct IClassFactoryVtbl FAR* lpVtbl;
  142.  *          } IClassFactory;
  143.  *
  144.  *          typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  145.  *
  146.  *          struct IClassFactoryVtbl
  147.  *          {
  148.  *              HRESULT (STDMETHODCALLTYPE * QueryInterface) (
  149.  *                                                  IClassFactory FAR* This,
  150.  *                                                  IID FAR* riid,
  151.  *                                                  LPVOID FAR* ppvObj) ;
  152.  *              HRESULT (STDMETHODCALLTYPE * AddRef) (IClassFactory FAR* This) ;
  153.  *              HRESULT (STDMETHODCALLTYPE * Release) (IClassFactory FAR* This) ;
  154.  *              HRESULT (STDMETHODCALLTYPE * CreateInstance) (
  155.  *                                                  IClassFactory FAR* This,
  156.  *                                                  LPUNKNOWN pUnkOuter,
  157.  *                                                  IID FAR* riid,
  158.  *                                                  LPVOID FAR* ppvObject);
  159.  *              HRESULT (STDMETHODCALLTYPE * LockServer) (
  160.  *                                                  IClassFactory FAR* This,
  161.  *                                                  BOOL fLock);
  162.  *          };
  163.  */
  164.  
  165.  
  166. #if defined(__cplusplus) && !defined(CINTERFACE)
  167. #ifdef __TURBOC__
  168. #define interface               struct huge
  169. #else
  170. #define interface               struct FAR
  171. #endif
  172. #define STDMETHOD(method)       virtual HRESULT STDMETHODCALLTYPE method
  173. #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  174. #define PURE                    = 0
  175. #define THIS_
  176. #define THIS                    void
  177. #define DECLARE_INTERFACE(iface)    interface iface
  178. #define DECLARE_INTERFACE_(iface, baseiface)    interface iface : public baseiface
  179.  
  180. #else
  181. #define interface               struct
  182.  
  183. #ifdef _MAC
  184.  
  185. #define STDMETHOD(method)       long    method##pad;\
  186.                 HRESULT (STDMETHODCALLTYPE * method)
  187. #define STDMETHOD_(type,method) long    method##pad;\
  188.                 type (STDMETHODCALLTYPE * method)
  189.  
  190. #else // _MAC
  191.  
  192. #define STDMETHOD(method)       HRESULT (STDMETHODCALLTYPE * method)
  193. #define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
  194.  
  195. #endif // !_MAC
  196.  
  197. #define PURE
  198. #define THIS_                   INTERFACE FAR* This,
  199. #define THIS                    INTERFACE FAR* This
  200. #ifdef CONST_VTABLE
  201. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  202.                     const struct iface##Vtbl FAR* lpVtbl; \
  203.                 } iface; \
  204.                 typedef const struct iface##Vtbl iface##Vtbl; \
  205.                 const struct iface##Vtbl
  206. #else
  207. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  208.                     struct iface##Vtbl FAR* lpVtbl; \
  209.                 } iface; \
  210.                 typedef struct iface##Vtbl iface##Vtbl; \
  211.                 struct iface##Vtbl
  212. #endif
  213. #define DECLARE_INTERFACE_(iface, baseiface)    DECLARE_INTERFACE(iface)
  214.  
  215. #endif
  216.  
  217.  
  218. /****** Additional basic types **********************************************/
  219.  
  220.  
  221. #ifndef FARSTRUCT
  222. #ifdef __cplusplus
  223. #define FARSTRUCT   FAR
  224. #else
  225. #define FARSTRUCT
  226. #endif  // __cplusplus
  227. #endif  // FARSTRUCT
  228.  
  229.  
  230. #ifndef WINAPI          /* If not included with 3.1 headers... */
  231.  
  232. #ifdef WIN32
  233. #define FAR
  234. #define PASCAL          __stdcall
  235. #define CDECL
  236. #else
  237. #define FAR             _far
  238. #define PASCAL          _pascal
  239. #define CDECL           _cdecl
  240. #endif
  241.  
  242. #define VOID            void
  243. #define WINAPI      FAR PASCAL
  244. #define CALLBACK    FAR PASCAL
  245.  
  246. #ifndef FALSE
  247. #define FALSE 0
  248. #define TRUE 1
  249. #endif
  250.  
  251. typedef int BOOL;
  252. typedef unsigned char BYTE;
  253. typedef unsigned short WORD;
  254. typedef unsigned int UINT;
  255.  
  256. typedef long LONG;
  257. typedef unsigned long DWORD;
  258.  
  259.  
  260. typedef UINT WPARAM;
  261. typedef LONG LPARAM;
  262. typedef LONG LRESULT;
  263.  
  264. typedef unsigned int HANDLE;
  265. #define DECLARE_HANDLE(name)    typedef UINT name
  266.  
  267. DECLARE_HANDLE(HMODULE);
  268. DECLARE_HANDLE(HINSTANCE);
  269. DECLARE_HANDLE(HLOCAL);
  270. DECLARE_HANDLE(HGLOBAL);
  271. DECLARE_HANDLE(HDC);
  272. DECLARE_HANDLE(HRGN);
  273. DECLARE_HANDLE(HWND);
  274. DECLARE_HANDLE(HMENU);
  275. DECLARE_HANDLE(HACCEL);
  276. DECLARE_HANDLE(HTASK);
  277.  
  278. #if !defined(NULL)
  279. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  280. #  define NULL    0
  281. #else
  282. #  define NULL    0L
  283. #endif
  284. #endif
  285.  
  286.  
  287. typedef void FAR *      LPVOID;
  288. typedef WORD FAR *      LPWORD;
  289. typedef DWORD FAR *     LPDWORD;
  290. typedef char FAR*       LPSTR;
  291. typedef const char FAR* LPCSTR;
  292. typedef void FAR*       LPLOGPALETTE;
  293. typedef void FAR*       LPMSG;
  294. //typedef struct tagMSG FAR *LPMSG;
  295.  
  296. typedef HANDLE FAR *LPHANDLE;
  297. typedef struct tagRECT FAR *LPRECT;
  298.  
  299. typedef struct FARSTRUCT tagSIZE
  300. {
  301.     int cx;
  302.     int cy;
  303. } SIZE;
  304. typedef SIZE*       PSIZE;
  305.  
  306.  
  307. #endif  /* WINAPI */
  308.  
  309.  
  310. typedef short SHORT;
  311. typedef unsigned short USHORT;
  312. typedef DWORD ULONG;
  313.  
  314.  
  315. #ifndef HUGEP
  316. #ifdef WIN32
  317. #define HUGEP
  318. #else
  319. #define HUGEP __huge
  320. #endif // WIN32
  321. #endif // HUGEP
  322.  
  323. typedef WORD WCHAR;
  324.  
  325. #ifndef WIN32
  326. typedef struct FARSTRUCT _LARGE_INTEGER {
  327.     DWORD LowPart;
  328.     LONG  HighPart;
  329. } LARGE_INTEGER, *PLARGE_INTEGER;
  330. #endif
  331. #define LISet32(li, v) ((li).HighPart = ((LONG)(v)) < 0 ? -1 : 0, (li).LowPart = (v))
  332.  
  333. #ifndef WIN32
  334. typedef struct FARSTRUCT _ULARGE_INTEGER {
  335.     DWORD LowPart;
  336.     DWORD HighPart;
  337. } ULARGE_INTEGER, *PULARGE_INTEGER;
  338. #endif
  339. #define ULISet32(li, v) ((li).HighPart = 0, (li).LowPart = (v))
  340.  
  341. #ifndef _WINDOWS_
  342. #ifndef _FILETIME_
  343. #define _FILETIME_
  344. typedef struct FARSTRUCT tagFILETIME
  345. {
  346.     DWORD dwLowDateTime;
  347.     DWORD dwHighDateTime;
  348. } FILETIME;
  349. #endif
  350. #endif
  351.  
  352. #ifdef WIN32
  353. #define HTASK DWORD
  354. #endif
  355.  
  356. #include "scode.h"
  357.  
  358.  
  359.  
  360. // *********************** Compobj errors **********************************
  361.  
  362. #define CO_E_NOTINITIALIZED         (CO_E_FIRST + 0x0)
  363. // CoInitialize has not been called and must be
  364.  
  365. #define CO_E_ALREADYINITIALIZED     (CO_E_FIRST + 0x1)
  366. // CoInitialize has already been called and cannot be called again (temporary)
  367.  
  368. #define CO_E_CANTDETERMINECLASS     (CO_E_FIRST + 0x2)
  369. // can't determine clsid (e.g., extension not in reg.dat)
  370.  
  371. #define CO_E_CLASSSTRING            (CO_E_FIRST + 0x3)
  372. // the string form of the clsid is invalid (including ole1 classes)
  373.  
  374. #define CO_E_IIDSTRING              (CO_E_FIRST + 0x4)
  375. // the string form of the iid is invalid
  376.  
  377. #define CO_E_APPNOTFOUND            (CO_E_FIRST + 0x5)
  378. // application not found
  379.  
  380. #define CO_E_APPSINGLEUSE           (CO_E_FIRST + 0x6)
  381. // application cannot be run more than once
  382.  
  383. #define CO_E_ERRORINAPP             (CO_E_FIRST + 0x7)
  384. // some error in the app program file
  385.  
  386. #define CO_E_DLLNOTFOUND            (CO_E_FIRST + 0x8)
  387. // dll not found
  388.  
  389. #define CO_E_ERRORINDLL             (CO_E_FIRST + 0x9)
  390. // some error in the dll file
  391.  
  392. #define CO_E_WRONGOSFORAPP          (CO_E_FIRST + 0xa)
  393. // app written for other version of OS or other OS altogether
  394.  
  395. #define CO_E_OBJNOTREG              (CO_E_FIRST + 0xb)
  396. // object is not registered
  397.  
  398. #define CO_E_OBJISREG               (CO_E_FIRST + 0xc)
  399. // object is already registered
  400.  
  401. #define CO_E_OBJNOTCONNECTED        (CO_E_FIRST + 0xd)
  402. // handler is not connected to server
  403.  
  404. #define CO_E_APPDIDNTREG            (CO_E_FIRST + 0xe)
  405. // app was launched, but didn't registered a class factory
  406.  
  407.  
  408. // ********************* ClassObject errors ********************************
  409.  
  410. #define CLASS_E_NOAGGREGATION       (CLASSFACTORY_E_FIRST + 0x0)
  411. // class does not support aggregation (or class object is remote)
  412.  
  413. #define CLASS_E_CLASSNOTAVAILABLE   (CLASSFACTORY_E_FIRST + 0x1)
  414. // dll doesn't support that class (returned from DllGetClassObject)
  415.  
  416.  
  417. // *********************** Reg.dat errors **********************************
  418.  
  419. #define REGDB_E_READREGDB           (REGDB_E_FIRST + 0x0)
  420. // some error reading the registration database
  421.  
  422. #define REGDB_E_WRITEREGDB          (REGDB_E_FIRST + 0x1)
  423. // some error reading the registration database
  424.  
  425. #define REGDB_E_KEYMISSING          (REGDB_E_FIRST + 0x2)
  426. // some error reading the registration database
  427.  
  428. #define REGDB_E_INVALIDVALUE        (REGDB_E_FIRST + 0x3)
  429. // some error reading the registration database
  430.  
  431. #define REGDB_E_CLASSNOTREG         (REGDB_E_FIRST + 0x4)
  432. // some error reading the registration database
  433.  
  434. #define REGDB_E_IIDNOTREG           (REGDB_E_FIRST + 0x5)
  435. // some error reading the registration database
  436.  
  437.  
  438. // *************************** RPC errors **********************************
  439.  
  440. #define RPC_E_FIRST    MAKE_SCODE(SEVERITY_ERROR, FACILITY_RPC,  0x000)
  441.  
  442. // call was rejected by callee, either by MF::HandleIncomingCall or
  443. #define RPC_E_CALL_REJECTED             (RPC_E_FIRST + 0x1)
  444.  
  445. // call was canceld by call - returned by MessagePending
  446. // this code only occurs if MessagePending return cancel
  447. #define RPC_E_CALL_CANCELED             (RPC_E_FIRST + 0x2)
  448.  
  449. // the caller is dispatching an intertask SendMessage call and
  450. // can NOT call out via PostMessage
  451. #define RPC_E_CANTPOST_INSENDCALL       (RPC_E_FIRST + 0x3)
  452.  
  453. // the caller is dispatching an asynchronus call can NOT
  454. // make an outgoing call on behalf of this call
  455. #define RPC_E_CANTCALLOUT_INASYNCCALL   (RPC_E_FIRST + 0x4)
  456.  
  457. // the caller is not in a state where an outgoing call can be made
  458. // this is the case if the caller has an outstandig call and
  459. // another incoming call was excepted by HIC; now the caller is
  460. // not allowed to call out again
  461. #define RPC_E_CANTCALLOUT_INEXTERNALCALL (RPC_E_FIRST + 0x5)
  462.  
  463. // the connection terminated or is in a bogus state
  464. // and can not be used any more. Other connections
  465. // are still valid.
  466. #define RPC_E_CONNECTION_TERMINATED     (RPC_E_FIRST + 0x6)
  467.  
  468. // the callee (server [not server application]) is not available
  469. // and disappeared; all connections are invalid
  470. #define RPC_E_SERVER_DIED               (RPC_E_FIRST + 0x7)
  471.  
  472. // the caller (client ) disappeared while the callee (server) was
  473. // processing a call
  474. #define RPC_E_CLIENT_DIED               (RPC_E_FIRST + 0x8)
  475.  
  476. // the date paket with the marshalled parameter data is
  477. // incorrect
  478. #define RPC_E_INVALID_DATAPACKET        (RPC_E_FIRST + 0x9)
  479.  
  480. // the call was not transmitted properly; the message queue
  481. // was full and was not emptied after yielding
  482. #define RPC_E_CANTTRANSMIT_CALL         (RPC_E_FIRST + 0xa)
  483.  
  484. // the client (caller) can not marshall the parameter data
  485. // or unmarshall the return data - low memory etc.
  486. #define RPC_E_CLIENT_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xb)
  487. #define RPC_E_CLIENT_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xc)
  488.  
  489. // the server (caller) can not unmarshall the parameter data
  490. // or marshall the return data - low memory
  491. #define RPC_E_SERVER_CANTMARSHAL_DATA   (RPC_E_FIRST + 0xd)
  492. #define RPC_E_SERVER_CANTUNMARSHAL_DATA (RPC_E_FIRST + 0xe)
  493.  
  494. // received data are invalid; can be server or
  495. // client data
  496. #define RPC_E_INVALID_DATA              (RPC_E_FIRST + 0xf)
  497.  
  498. // a particular parameter is invalid and can not be un/marshalled
  499. #define RPC_E_INVALID_PARAMETER         (RPC_E_FIRST + 0x10)
  500.  
  501. // DDE conversation - no second outgoing call on same channel
  502. #define RPC_E_CANTCALLOUT_AGAIN                 (RPC_E_FIRST + 0x11)
  503.  
  504. // a internal error occured
  505. #define RPC_E_UNEXPECTED                (RPC_E_FIRST + 0xFFFF)
  506.  
  507.  
  508. /****** Globally Unique Ids *************************************************/
  509.  
  510. #ifdef __cplusplus
  511.  
  512. struct FAR GUID
  513. {
  514.     DWORD Data1;
  515.     WORD  Data2;
  516.     WORD  Data3;
  517.     BYTE  Data4[8];
  518.  
  519.     BOOL operator==(const GUID& iidOther) const
  520.  
  521. #ifdef WIN32
  522.     { return !memcmp(&Data1,&iidOther.Data1,sizeof(GUID)); }
  523. #else
  524.     { return !_fmemcmp(&Data1,&iidOther.Data1,sizeof(GUID)); }
  525. #endif
  526.     BOOL operator!=(const GUID& iidOther) const
  527.     { return !((*this) == iidOther); }
  528. };
  529.  
  530. #else
  531. typedef struct GUID
  532. {
  533.     DWORD Data1;
  534.     WORD  Data2;
  535.     WORD  Data3;
  536.     BYTE  Data4[8];
  537. } GUID;
  538. #endif
  539.  
  540. typedef                GUID FAR* LPGUID;
  541.  
  542.  
  543. // macros to define byte pattern for a GUID.
  544. //      Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
  545. //
  546. // Each dll/exe must initialize the GUIDs once.  This is done in one of
  547. // two ways.  If you are not using precompiled headers for the file(s) which
  548. // initializes the GUIDs, define INITGUID before including compobj.h.  This
  549. // is how OLE builds the initialized versions of the GUIDs which are included
  550. // in compobj.dll.
  551. //
  552. // The alternative (which some versions of the compiler don't handle properly;
  553. // they wind up with the initialized GUIDs in a data, not a text segment),
  554. // is to use a precompiled version of compobj.h and then include initguid.h
  555. // after compobj.h followed by one or more of the guid defintion files.
  556.  
  557.  
  558. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  559.     EXTERN_C const GUID CDECL FAR name
  560.  
  561. #ifdef INITGUID
  562. #include "initguid.h"
  563. #endif
  564.  
  565. #define DEFINE_OLEGUID(name, l, w1, w2) \
  566.     DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  567.  
  568.  
  569. // Interface ID are just a kind of GUID
  570. typedef GUID IID;
  571. typedef                IID FAR* LPIID;
  572. #define IID_NULL            GUID_NULL
  573. #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
  574.  
  575.  
  576. // Class ID are just a kind of GUID
  577. typedef GUID CLSID;
  578. typedef              CLSID FAR* LPCLSID;
  579. #define CLSID_NULL          GUID_NULL
  580. #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
  581.  
  582.  
  583. #if defined(__cplusplus)
  584. #define REFGUID             const GUID FAR&
  585. #define REFIID              const IID FAR&
  586. #define REFCLSID            const CLSID FAR&
  587. #else
  588. #define REFGUID             const GUID FAR* const
  589. #define REFIID              const IID FAR* const
  590. #define REFCLSID            const CLSID FAR* const
  591. #endif
  592.  
  593.  
  594. #ifndef INITGUID
  595. #include "coguid.h"
  596. #endif
  597.  
  598. /****** Other value types ***************************************************/
  599.  
  600. // memory context values; passed to CoGetMalloc
  601. typedef enum tagMEMCTX
  602. {
  603.     MEMCTX_TASK = 1,            // task (private) memory
  604.     MEMCTX_SHARED = 2,          // shared memory (between processes)
  605. #ifdef _MAC
  606.     MEMCTX_MACSYSTEM = 3,       // on the mac, the system heap
  607. #endif
  608.  
  609.     // these are mostly for internal use...
  610.     MEMCTX_UNKNOWN = -1,        // unknown context (when asked about it)
  611.     MEMCTX_SAME = -2,           // same context (as some other pointer)
  612. } MEMCTX;
  613.  
  614.  
  615.  
  616. // class context: used to determine what scope and kind of class object to use
  617. // NOTE: this is a bitwise enum
  618. typedef enum tagCLSCTX
  619. {
  620.     CLSCTX_INPROC_SERVER = 1,   // server dll (runs in same process as caller)
  621.     CLSCTX_INPROC_HANDLER = 2,  // handler dll (runs in same process as caller)
  622.     CLSCTX_LOCAL_SERVER = 4     // server exe (runs on same machine; diff proc)
  623. } CLSCTX;
  624.  
  625. #define CLSCTX_ALL              (CLSCTX_INPROC_SERVER| \
  626.                  CLSCTX_INPROC_HANDLER| \
  627.                  CLSCTX_LOCAL_SERVER)
  628.  
  629. #define CLSCTX_INPROC           (CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER)
  630.  
  631. #define CLSCTX_SERVER           (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER)
  632.  
  633.  
  634. // class registration flags; passed to CoRegisterClassObject
  635. typedef enum tagREGCLS
  636. {
  637.     REGCLS_SINGLEUSE = 0,       // class object only generates one instance
  638.     REGCLS_MULTIPLEUSE = 1,     // same class object genereates multiple inst.
  639.                                 // and local automatically goes into inproc tbl.
  640.     REGCLS_MULTI_SEPARATE = 2,  // multiple use, but separate control over each
  641.                                 // context.
  642.  
  643.     // NOTE: CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE is the same as
  644.     // (CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER), REGCLS_MULTI_SEPARATE, but
  645.     // not the same as CLSCTX_LOCAL_SERVER, REGCLS_MULTI_SEPARATE.
  646. } REGCLS;
  647.  
  648.  
  649. // interface marshaling definitions
  650. #define MARSHALINTERFACE_MIN 40 // minimum number of bytes for interface marshl
  651.  
  652. // marshaling flags; passed to CoMarshalInterface
  653. typedef enum tagMSHLFLAGS
  654. {
  655.     MSHLFLAGS_NORMAL = 0,       // normal marshaling via proxy/stub
  656.     MSHLFLAGS_TABLESTRONG = 1,  // keep object alive; must explicitly release
  657.     MSHLFLAGS_TABLEWEAK = 2     // doesn't hold object alive; still must release
  658. } MSHLFLAGS;
  659.  
  660. // marshal context: determines the destination context of the marshal operation
  661. typedef enum tagMSHCTX
  662. {
  663.     MSHCTX_LOCAL = 0,           // unmarshal context is local (eg.shared memory)
  664.     MSHCTX_NOSHAREDMEM = 1,     // unmarshal context has no shared memory access
  665. } MSHCTX;
  666.  
  667.  
  668. // call type used by IMessageFilter::HandleIncommingMessage
  669. typedef enum tagCALLTYPE
  670. {
  671.     CALLTYPE_TOPLEVEL = 1,      // toplevel call - no outgoing call
  672.     CALLTYPE_NESTED   = 2,      // callback on behalf of previous outgoing call - should always handle
  673.     CALLTYPE_ASYNC    = 3,      // aysnchronous call - can NOT be rejected
  674.     CALLTYPE_TOPLEVEL_CALLPENDING = 4,  // new toplevel call with new LID
  675.     CALLTYPE_ASYNC_CALLPENDING    = 5   // async call - can NOT be rejected
  676. } CALLTYPE;
  677.  
  678. typedef struct tagINTERFACEINFO
  679. {
  680.     interface IUnknown FAR *pUnk;       // the pointer to the object
  681.     IID                         iid;            // interface id
  682.     WORD                        wMethod;        // interface methode
  683. } INTERFACEINFO, FAR * LPINTERFACEINFO;
  684.  
  685. // status of server call - returned by IMessageFilter::HandleIncommingCall
  686. // and passed to  IMessageFilter::RetryRejectedCall
  687. typedef enum tagSERVERCALL
  688. {
  689.     SERVERCALL_ISHANDLED    = 0,
  690.     SERVERCALL_REJECTED     = 1,
  691.     SERVERCALL_RETRYLATER   = 2
  692. } SERVERCALL;
  693.  
  694.  
  695. // Pending type indicates the level of nesting
  696. typedef enum tagPENDINGTYPE
  697. {
  698.     PENDINGTYPE_TOPLEVEL = 1,       // toplevel call
  699.     PENDINGTYPE_NESTED   = 2,       // nested call
  700. } PENDINGTYPE;
  701.  
  702. // return values of MessagePending
  703. typedef enum tagPENDINGMSG
  704. {
  705.     PENDINGMSG_CANCELCALL  = 0, // cancel the outgoing call
  706.     PENDINGMSG_WAITNOPROCESS  = 1, // wait for the return and don't dispatch the message
  707.     PENDINGMSG_WAITDEFPROCESS = 2  // wait and dispatch the message
  708.  
  709. } PENDINGMSG;
  710.  
  711.  
  712. // bit flags for IExternalConnection
  713. typedef enum tagEXTCONN
  714. {
  715.     EXTCONN_STRONG          = 0x0001        // strong connection
  716. } EXTCONN;
  717.  
  718.  
  719. /****** IUnknown Interface **************************************************/
  720.  
  721.  
  722. #undef  INTERFACE
  723. #define INTERFACE   IUnknown
  724.  
  725. DECLARE_INTERFACE(IUnknown)
  726. {
  727.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  728.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  729.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  730. };
  731.  
  732. typedef        IUnknown FAR* LPUNKNOWN;
  733.  
  734.  
  735. /****** Class Factory Interface *******************************************/
  736.  
  737.  
  738. #undef  INTERFACE
  739. #define INTERFACE   IClassFactory
  740.  
  741. DECLARE_INTERFACE_(IClassFactory, IUnknown)
  742. {
  743.     // *** IUnknown methods ***
  744.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  745.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  746.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  747.  
  748.     // *** IClassFactory methods ***
  749.     STDMETHOD(CreateInstance) (THIS_ LPUNKNOWN pUnkOuter,
  750.                   REFIID riid,
  751.                   LPVOID FAR* ppvObject) PURE;
  752.     STDMETHOD(LockServer) (THIS_ BOOL fLock) PURE;
  753.  
  754. };
  755. typedef       IClassFactory FAR* LPCLASSFACTORY;
  756.  
  757.  
  758. /****** Memory Allocation Interface ***************************************/
  759.  
  760.  
  761. #undef  INTERFACE
  762. #define INTERFACE   IMalloc
  763.  
  764. DECLARE_INTERFACE_(IMalloc, IUnknown)
  765. {
  766.     // *** IUnknown methods ***
  767.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  768.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  769.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  770.  
  771.     // *** IMalloc methods ***
  772.     STDMETHOD_(void FAR*, Alloc) (THIS_ ULONG cb) PURE;
  773.     STDMETHOD_(void FAR*, Realloc) (THIS_ void FAR* pv, ULONG cb) PURE;
  774.     STDMETHOD_(void, Free) (THIS_ void FAR* pv) PURE;
  775.     STDMETHOD_(ULONG, GetSize) (THIS_ void FAR* pv) PURE;
  776.     STDMETHOD_(int, DidAlloc) (THIS_ void FAR* pv) PURE;
  777.     STDMETHOD_(void, HeapMinimize) (THIS) PURE;
  778. };
  779. typedef       IMalloc FAR* LPMALLOC;
  780.  
  781.  
  782. /****** IMarshal Interface ************************************************/
  783.  
  784. // forward declaration for IStream; must include storage.h later to use
  785. #ifdef __cplusplus
  786. interface IStream;
  787. #else
  788. typedef interface IStream IStream;
  789. #endif
  790. typedef         IStream FAR* LPSTREAM;
  791.  
  792.  
  793. #undef  INTERFACE
  794. #define INTERFACE   IMarshal
  795.  
  796. DECLARE_INTERFACE_(IMarshal, IUnknown)
  797. {
  798.     // *** IUnknown methods ***
  799.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  800.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  801.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  802.  
  803.     // *** IMarshal methods ***
  804.     STDMETHOD(GetUnmarshalClass)(THIS_ REFIID riid, LPVOID pv,
  805.             DWORD dwDestContext, LPVOID pvDestContext,
  806.             DWORD mshlflags, LPCLSID pCid) PURE;
  807.     STDMETHOD(GetMarshalSizeMax)(THIS_ REFIID riid, LPVOID pv,
  808.             DWORD dwDestContext, LPVOID pvDestContext,
  809.             DWORD mshlflags, LPDWORD pSize) PURE;
  810.     STDMETHOD(MarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  811.             LPVOID pv, DWORD dwDestContext, LPVOID pvDestContext,
  812.             DWORD mshlflags) PURE;
  813.     STDMETHOD(UnmarshalInterface)(THIS_ LPSTREAM pStm, REFIID riid,
  814.             LPVOID FAR* ppv) PURE;
  815.     STDMETHOD(ReleaseMarshalData)(THIS_ LPSTREAM pStm) PURE;
  816.     STDMETHOD(DisconnectObject)(THIS_ DWORD dwReserved) PURE;
  817. };
  818. typedef         IMarshal FAR* LPMARSHAL;
  819.  
  820.  
  821. #undef  INTERFACE
  822. #define INTERFACE   IStdMarshalInfo
  823.  
  824. DECLARE_INTERFACE_(IStdMarshalInfo, IUnknown)
  825. {
  826.     // *** IUnknown methods ***
  827.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  828.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  829.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  830.  
  831.     // *** IStdMarshalInfo methods ***
  832.     STDMETHOD(GetClassForHandler)(THIS_ DWORD dwDestContext,
  833.             LPVOID pvDestContext, LPCLSID pClsid) PURE;
  834. };
  835. typedef         IStdMarshalInfo FAR* LPSTDMARSHALINFO;
  836.  
  837.  
  838. /****** Message Filter Interface *******************************************/
  839.  
  840.  
  841. #undef  INTERFACE
  842. #define INTERFACE   IMessageFilter
  843.  
  844. DECLARE_INTERFACE_(IMessageFilter, IUnknown)
  845. {
  846.     // *** IUnknown methods ***
  847.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  848.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  849.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  850.  
  851.     // *** IMessageFilter methods ***
  852.     STDMETHOD_(DWORD, HandleInComingCall) (THIS_ DWORD dwCallType,
  853.                 HTASK htaskCaller, DWORD dwTickCount,
  854.                 DWORD dwReserved ) PURE;
  855.     STDMETHOD_(DWORD, RetryRejectedCall) (THIS_
  856.                 HTASK htaskCallee, DWORD dwTickCount,
  857.                 DWORD dwRejectType ) PURE;
  858.     STDMETHOD_(DWORD, MessagePending) (THIS_
  859.                 HTASK htaskCallee, DWORD dwTickCount,
  860.                 DWORD dwPendingType  ) PURE;
  861. };
  862. typedef       IMessageFilter FAR* LPMESSAGEFILTER;
  863.  
  864.  
  865. /****** External Connection Information ***********************************/
  866.  
  867. #undef  INTERFACE
  868. #define INTERFACE   IExternalConnection
  869.  
  870. DECLARE_INTERFACE_(IExternalConnection, IUnknown)
  871. {
  872.     // *** IUnknown methods ***
  873.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  874.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  875.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  876.  
  877.     // *** IExternalConnection methods ***
  878.     STDMETHOD_(DWORD, AddConnection) (THIS_ DWORD extconn, DWORD reserved) PURE;
  879.     STDMETHOD_(DWORD, ReleaseConnection) (THIS_ DWORD extconn, DWORD reserved, BOOL fLastReleaseCloses) PURE;
  880. };
  881. typedef       IExternalConnection FAR* LPEXTERNALCONNECTION;
  882.  
  883.  
  884. /****** Enumerator Interfaces *********************************************/
  885.  
  886. /*
  887.  *  Since we don't use parametrized types, we put in explicit declarations
  888.  *  of the enumerators we need.
  889.  */
  890.  
  891.  
  892. #undef  INTERFACE
  893. #define INTERFACE   IEnumString
  894.  
  895. DECLARE_INTERFACE_(IEnumString, IUnknown)
  896. {
  897.     // *** IUnknown methods ***
  898.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  899.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  900.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  901.  
  902.     // *** IEnumString methods ***
  903.     STDMETHOD(Next) (THIS_ ULONG celt,
  904.                LPSTR FAR* rgelt,
  905.                ULONG FAR* pceltFetched) PURE;
  906.     STDMETHOD(Skip) (THIS_ ULONG celt) PURE;
  907.     STDMETHOD(Reset) (THIS) PURE;
  908.     STDMETHOD(Clone) (THIS_ IEnumString FAR* FAR* ppenm) PURE;
  909. };
  910. typedef      IEnumString FAR* LPENUMSTRING;
  911.  
  912.  
  913. #undef  INTERFACE
  914. #define INTERFACE   IEnumUnknown
  915.  
  916. DECLARE_INTERFACE_(IEnumUnknown, IUnknown)
  917. {
  918.     // *** IUnknown methods ***
  919.     STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR* ppvObj) PURE;
  920.     STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
  921.     STDMETHOD_(ULONG,Release) (THIS) PURE;
  922.  
  923.     // *** IEnumUnknown methods ***
  924.     STDMETHOD(Next) (THIS_ ULONG celt, LPUNKNOWN FAR* rgelt, ULONG FAR* pceltFetched) PURE;
  925.     STDMETHOD(Skip) (THIS_ ULONG celt) PURE;
  926.     STDMETHOD(Reset) (THIS) PURE;
  927.     STDMETHOD(Clone) (THIS_ IEnumUnknown FAR* FAR* ppenm) PURE;
  928. };
  929. typedef         IEnumUnknown FAR* LPENUMUNKNOWN;
  930.  
  931.  
  932. /****** STD Object API Prototypes *****************************************/
  933.  
  934. STDAPI_(DWORD) CoBuildVersion( VOID );
  935.  
  936. /* init/uninit */
  937.  
  938. STDAPI  CoInitialize(LPMALLOC pMalloc);
  939. STDAPI_(void)  CoUninitialize(void);
  940. STDAPI  CoGetMalloc(DWORD dwMemContext, LPMALLOC FAR* ppMalloc);
  941. STDAPI_(DWORD) CoGetCurrentProcess(void);
  942. STDAPI  CoCreateStandardMalloc(DWORD memctx, IMalloc FAR* FAR* ppMalloc);
  943.  
  944.  
  945. /* register/revoke/get class objects */
  946.  
  947. STDAPI  CoGetClassObject(REFCLSID rclsid, DWORD dwClsContext, LPVOID pvReserved,
  948.             REFIID riid, LPVOID FAR* ppv);
  949. STDAPI  CoRegisterClassObject(REFCLSID rclsid, LPUNKNOWN pUnk,
  950.             DWORD dwClsContext, DWORD flags, LPDWORD lpdwRegister);
  951. STDAPI  CoRevokeClassObject(DWORD dwRegister);
  952.  
  953.  
  954. /* marshaling interface pointers */
  955.  
  956. STDAPI CoMarshalInterface(LPSTREAM pStm, REFIID riid, LPUNKNOWN pUnk,
  957.             DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags);
  958. STDAPI CoUnmarshalInterface(LPSTREAM pStm, REFIID riid, LPVOID FAR* ppv);
  959. STDAPI CoMarshalHresult(LPSTREAM pstm, HRESULT hresult);
  960. STDAPI CoUnmarshalHresult(LPSTREAM pstm, HRESULT FAR * phresult);
  961. STDAPI CoReleaseMarshalData(LPSTREAM pStm);
  962. STDAPI CoDisconnectObject(LPUNKNOWN pUnk, DWORD dwReserved);
  963. STDAPI CoLockObjectExternal(LPUNKNOWN pUnk, BOOL fLock, BOOL fLastUnlockReleases);
  964. STDAPI CoGetStandardMarshal(REFIID riid, LPUNKNOWN pUnk,
  965.             DWORD dwDestContext, LPVOID pvDestContext, DWORD mshlflags,
  966.             LPMARSHAL FAR* ppMarshal);
  967.  
  968. STDAPI_(BOOL) CoIsHandlerConnected(LPUNKNOWN pUnk);
  969.  
  970. /* dll loading helpers; keeps track of ref counts and unloads all on exit */
  971.  
  972. STDAPI_(HINSTANCE) CoLoadLibrary(LPSTR lpszLibName, BOOL bAutoFree);
  973. STDAPI_(void) CoFreeLibrary(HINSTANCE hInst);
  974. STDAPI_(void) CoFreeAllLibraries(void);
  975. STDAPI_(void) CoFreeUnusedLibraries(void);
  976.  
  977.  
  978. /* helper for creating instances */
  979.  
  980. STDAPI CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter,
  981.             DWORD dwClsContext, REFIID riid, LPVOID FAR* ppv);
  982.  
  983.  
  984. /* other helpers */
  985. STDAPI_(BOOL) IsEqualGUID(REFGUID rguid1, REFGUID rguid2);
  986. STDAPI StringFromCLSID(REFCLSID rclsid, LPSTR FAR* lplpsz);
  987. STDAPI CLSIDFromString(LPSTR lpsz, LPCLSID pclsid);
  988. STDAPI StringFromIID(REFIID rclsid, LPSTR FAR* lplpsz);
  989. STDAPI IIDFromString(LPSTR lpsz, LPIID lpiid);
  990. STDAPI_(BOOL) CoIsOle1Class(REFCLSID rclsid);
  991. STDAPI ProgIDFromCLSID (REFCLSID clsid, LPSTR FAR* lplpszProgID);
  992. STDAPI CLSIDFromProgID (LPCSTR lpszProgID, LPCLSID lpclsid);
  993. STDAPI_(int) StringFromGUID2(REFGUID rguid, LPSTR lpsz, int cbMax);
  994.  
  995. STDAPI CoCreateGuid(GUID FAR *pguid);
  996.  
  997. STDAPI_(BOOL) CoFileTimeToDosDateTime(
  998.          FILETIME FAR* lpFileTime, LPWORD lpDosDate, LPWORD lpDosTime);
  999. STDAPI_(BOOL) CoDosDateTimeToFileTime(
  1000.                WORD nDosDate, WORD nDosTime, FILETIME FAR* lpFileTime);
  1001. STDAPI  CoFileTimeNow( FILETIME FAR* lpFileTime );
  1002.  
  1003.  
  1004. STDAPI CoRegisterMessageFilter( LPMESSAGEFILTER lpMessageFilter,
  1005.                 LPMESSAGEFILTER FAR* lplpMessageFilter );
  1006.  
  1007.  
  1008. /* TreatAs APIS */
  1009.  
  1010. STDAPI CoGetTreatAsClass(REFCLSID clsidOld, LPCLSID pClsidNew);
  1011. STDAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew);
  1012.  
  1013.  
  1014. /* the server dlls must define their DllGetClassObject and DllCanUnloadNow
  1015.  * to match these; the typedefs are located here to ensure all are changed at
  1016.  * the same time.
  1017.  */
  1018.  
  1019. STDAPI  DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID FAR* ppv);
  1020. #ifdef _MAC
  1021. typedef STDAPICALLTYPE HRESULT (FAR* LPFNGETCLASSOBJECT) (REFCLSID, REFIID, LPVOID FAR*);
  1022. #else
  1023. typedef HRESULT (STDAPICALLTYPE FAR* LPFNGETCLASSOBJECT) (REFCLSID, REFIID, LPVOID FAR*);
  1024. #endif
  1025.  
  1026.  
  1027. STDAPI  DllCanUnloadNow(void);
  1028. #ifdef _MAC
  1029. typedef STDAPICALLTYPE HRESULT (FAR* LPFNCANUNLOADNOW)(void);
  1030. #else
  1031. typedef HRESULT (STDAPICALLTYPE FAR* LPFNCANUNLOADNOW)(void);
  1032. #endif
  1033.  
  1034.  
  1035. /****** Debugging Helpers *************************************************/
  1036.  
  1037. #ifdef _DEBUG
  1038. // writes to the debug port and displays a message box
  1039. STDAPI FnAssert(LPSTR lpstrExpr, LPSTR lpstrMsg, LPSTR lpstrFileName, UINT iLine);
  1040. #endif  //  _DEBUG
  1041.  
  1042. #endif // _COMPOBJ_H_
  1043. #else  /* !__FLAT__ */
  1044. #ifndef RC_INVOKED
  1045. #pragma message("WARNING: your code should #include objbase.h instead of compobj.h")
  1046. #endif /* !RC_INVOKED */
  1047.  
  1048. #include <objbase.h>
  1049.  
  1050. #endif  /* __FLAT__ */
  1051.