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

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