home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / basetyps.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  9KB  |  241 lines

  1. //+---------------------------------------------------------------------------
  2. //
  3. //  Microsoft Windows
  4. //  Copyright (C) Microsoft Corporation, 1992-1997.
  5. //
  6. //  File:       basetyps.h
  7. //
  8. //----------------------------------------------------------------------------
  9. #if !defined( _BASETYPS_H_ )
  10. #define _BASETYPS_H_
  11.  
  12. // Common macros gleamed from COMPOBJ.H
  13.  
  14. #ifdef __cplusplus
  15.     #define EXTERN_C    extern "C"
  16. #else
  17.     #define EXTERN_C    extern
  18. #endif
  19.  
  20. #ifdef _WIN32
  21.  
  22. // Win32 doesn't support __export
  23.  
  24. #define STDMETHODCALLTYPE       __stdcall
  25. #define STDMETHODVCALLTYPE      __cdecl
  26.  
  27. #define STDAPICALLTYPE          __stdcall
  28. #define STDAPIVCALLTYPE         __cdecl
  29.  
  30. #else
  31.  
  32. #define STDMETHODCALLTYPE       __export __stdcall
  33. #define STDMETHODVCALLTYPE      __export __cdecl
  34.  
  35. #define STDAPICALLTYPE          __export __stdcall
  36. #define STDAPIVCALLTYPE         __export __cdecl
  37.  
  38. #endif
  39.  
  40. #define STDAPI                  EXTERN_C HRESULT STDAPICALLTYPE
  41. #define STDAPI_(type)           EXTERN_C type STDAPICALLTYPE
  42.  
  43. #define STDMETHODIMP            HRESULT STDMETHODCALLTYPE
  44. #define STDMETHODIMP_(type)     type STDMETHODCALLTYPE
  45.  
  46. // The 'V' versions allow Variable Argument lists.
  47.  
  48. #define STDAPIV                 EXTERN_C HRESULT STDAPIVCALLTYPE
  49. #define STDAPIV_(type)          EXTERN_C type STDAPIVCALLTYPE
  50.  
  51. #define STDMETHODIMPV           HRESULT STDMETHODVCALLTYPE
  52. #define STDMETHODIMPV_(type)    type STDMETHODVCALLTYPE
  53.  
  54.  
  55.  
  56.  
  57. /****** Interface Declaration ***********************************************/
  58.  
  59. /*
  60.  *      These are macros for declaring interfaces.  They exist so that
  61.  *      a single definition of the interface is simulataneously a proper
  62.  *      declaration of the interface structures (C++ abstract classes)
  63.  *      for both C and C++.
  64.  *
  65.  *      DECLARE_INTERFACE(iface) is used to declare an interface that does
  66.  *      not derive from a base interface.
  67.  *      DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface
  68.  *      that does derive from a base interface.
  69.  *
  70.  *      By default if the source file has a .c extension the C version of
  71.  *      the interface declaratations will be expanded; if it has a .cpp
  72.  *      extension the C++ version will be expanded. if you want to force
  73.  *      the C version expansion even though the source file has a .cpp
  74.  *      extension, then define the macro "CINTERFACE".
  75.  *      eg.     cl -DCINTERFACE file.cpp
  76.  *
  77.  *      Example Interface declaration:
  78.  *
  79.  *          #undef  INTERFACE
  80.  *          #define INTERFACE   IClassFactory
  81.  *
  82.  *          DECLARE_INTERFACE_(IClassFactory, IUnknown)
  83.  *          {
  84.  *              // *** IUnknown methods ***
  85.  *              STDMETHOD(QueryInterface) (THIS_
  86.  *                                        REFIID riid,
  87.  *                                        LPVOID FAR* ppvObj) PURE;
  88.  *              STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  89.  *              STDMETHOD_(ULONG,Release) (THIS) PURE;
  90.  *
  91.  *              // *** IClassFactory methods ***
  92.  *              STDMETHOD(CreateInstance) (THIS_
  93.  *                                        LPUNKNOWN pUnkOuter,
  94.  *                                        REFIID riid,
  95.  *                                        LPVOID FAR* ppvObject) PURE;
  96.  *          };
  97.  *
  98.  *      Example C++ expansion:
  99.  *
  100.  *          struct FAR IClassFactory : public IUnknown
  101.  *          {
  102.  *              virtual HRESULT STDMETHODCALLTYPE QueryInterface(
  103.  *                                                  IID FAR& riid,
  104.  *                                                  LPVOID FAR* ppvObj) = 0;
  105.  *              virtual HRESULT STDMETHODCALLTYPE AddRef(void) = 0;
  106.  *              virtual HRESULT STDMETHODCALLTYPE Release(void) = 0;
  107.  *              virtual HRESULT STDMETHODCALLTYPE CreateInstance(
  108.  *                                              LPUNKNOWN pUnkOuter,
  109.  *                                              IID FAR& riid,
  110.  *                                              LPVOID FAR* ppvObject) = 0;
  111.  *          };
  112.  *
  113.  *          NOTE: Our documentation says '#define interface class' but we use
  114.  *          'struct' instead of 'class' to keep a lot of 'public:' lines
  115.  *          out of the interfaces.  The 'FAR' forces the 'this' pointers to
  116.  *          be far, which is what we need.
  117.  *
  118.  *      Example C expansion:
  119.  *
  120.  *          typedef struct IClassFactory
  121.  *          {
  122.  *              const struct IClassFactoryVtbl FAR* lpVtbl;
  123.  *          } IClassFactory;
  124.  *
  125.  *          typedef struct IClassFactoryVtbl IClassFactoryVtbl;
  126.  *
  127.  *          struct IClassFactoryVtbl
  128.  *          {
  129.  *              HRESULT (STDMETHODCALLTYPE * QueryInterface) (
  130.  *                                                  IClassFactory FAR* This,
  131.  *                                                  IID FAR* riid,
  132.  *                                                  LPVOID FAR* ppvObj) ;
  133.  *              HRESULT (STDMETHODCALLTYPE * AddRef) (IClassFactory FAR* This) ;
  134.  *              HRESULT (STDMETHODCALLTYPE * Release) (IClassFactory FAR* This) ;
  135.  *              HRESULT (STDMETHODCALLTYPE * CreateInstance) (
  136.  *                                                  IClassFactory FAR* This,
  137.  *                                                  LPUNKNOWN pUnkOuter,
  138.  *                                                  IID FAR* riid,
  139.  *                                                  LPVOID FAR* ppvObject);
  140.  *              HRESULT (STDMETHODCALLTYPE * LockServer) (
  141.  *                                                  IClassFactory FAR* This,
  142.  *                                                  BOOL fLock);
  143.  *          };
  144.  */
  145.  
  146.  
  147. #if defined(__cplusplus) && !defined(CINTERFACE)
  148. //#define interface               struct FAR
  149. #define interface struct
  150. #define STDMETHOD(method)       virtual HRESULT STDMETHODCALLTYPE method
  151. #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  152. #define PURE                    = 0
  153. #define THIS_
  154. #define THIS                    void
  155. #define DECLARE_INTERFACE(iface)    interface iface
  156. #define DECLARE_INTERFACE_(iface, baseiface)    interface iface : public baseiface
  157.  
  158.  
  159.  
  160. #else
  161.  
  162. #define interface               struct
  163.  
  164. #define STDMETHOD(method)       HRESULT (STDMETHODCALLTYPE * method)
  165. #define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
  166.  
  167.  
  168.  
  169.  
  170. #define PURE
  171. #define THIS_                   INTERFACE FAR* This,
  172. #define THIS                    INTERFACE FAR* This
  173. #ifdef CONST_VTABLE
  174. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  175.                                     const struct iface##Vtbl FAR* lpVtbl; \
  176.                                 } iface; \
  177.                                 typedef const struct iface##Vtbl iface##Vtbl; \
  178.                                 const struct iface##Vtbl
  179. #else
  180. #define DECLARE_INTERFACE(iface)    typedef interface iface { \
  181.                                     struct iface##Vtbl FAR* lpVtbl; \
  182.                                 } iface; \
  183.                                 typedef struct iface##Vtbl iface##Vtbl; \
  184.                                 struct iface##Vtbl
  185. #endif
  186. #define DECLARE_INTERFACE_(iface, baseiface)    DECLARE_INTERFACE(iface)
  187.  
  188. #endif
  189.  
  190. // macros to define byte pattern for a GUID.
  191. //      Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
  192. //
  193. // Each dll/exe must initialize the GUIDs once.  This is done in one of
  194. // two ways.  If you are not using precompiled headers for the file(s) which
  195. // initializes the GUIDs, define INITGUID before including compobj.h.  This
  196. // is how OLE builds the initialized versions of the GUIDs which are included
  197. // in ole2.lib.  The GUIDs in ole2.lib are all defined in the same text
  198. // segment GUID_TEXT.
  199. //
  200. // The alternative (which some versions of the compiler don't handle properly;
  201. // they wind up with the initialized GUIDs in a data, not a text segment),
  202. // is to use a precompiled version of compobj.h and then include initguid.h
  203. // after compobj.h followed by one or more of the guid defintion files.
  204.  
  205. #ifndef INITGUID
  206. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  207.     EXTERN_C const GUID FAR name
  208. #else
  209.  
  210. #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
  211.         EXTERN_C const GUID name \
  212.                 = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
  213. #endif // INITGUID
  214.  
  215. #define DEFINE_OLEGUID(name, l, w1, w2) \
  216.     DEFINE_GUID(name, l, w1, w2, 0xC0,0,0,0,0,0,0,0x46)
  217.  
  218. #ifndef _ERROR_STATUS_T_DEFINED
  219. typedef unsigned long error_status_t;
  220. #define _ERROR_STATUS_T_DEFINED
  221. #endif
  222.  
  223. #ifndef _WCHAR_T_DEFINED
  224. typedef unsigned short wchar_t;
  225. #define _WCHAR_T_DEFINED
  226. #endif
  227.  
  228. #ifndef GUID_DEFINED
  229. #define GUID_DEFINED
  230. typedef struct _GUID
  231. {
  232.     unsigned long Data1;
  233.     unsigned short Data2;
  234.     unsigned short Data3;
  235.     unsigned char Data4[8];
  236. } GUID;
  237. #endif /* GUID_DEFINED */
  238.  
  239. #endif
  240.  
  241.