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