comLib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:10k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* comLib.h - VxWorks COM public API */
  2. /* Copyright (c) 1998 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02u,02jan02,nel  Fix alloca for diab build.
  7. 02t,10dec01,dbs  diab build
  8. 02s,08aug01,nel  Removed V_DECIMAL macros, not supported.
  9. 02r,16jul01,dbs  correct definition of comLibInit func
  10. 02q,13jul01,dbs  change vxcom back to vxidl
  11. 02p,28jun01,dbs  move VxMutex to private header
  12. 02o,27jun01,nel  Add extra SafeArray API.
  13. 02n,21jun01,dbs  move some definitions to comCoreLib
  14. 02m,20jun01,nel  Remove WindTypes and replace with vxcom.h.
  15. 02l,08feb01,nel  SPR#63885. SAFEARRAYs added. 
  16. 02k,30may00,nel  Add more variant support
  17. 02j,02feb00,dbs  add some Variant-related APIs
  18. 02i,22sep99,dbs  fix VARIANT type (moved to vxidl.idl)
  19. 02h,20sep99,dbs  move main typedefs into vxidl.idl/.h
  20. 02g,16sep99,dbs  add uchar typedef
  21. 02f,01sep99,dbs  add more IDL types
  22. 02e,18aug99,aim  fix GUID structure for SIMNT
  23. 02d,05aug99,dbs  add byte typedef
  24. 02c,30jul99,aim  changed mutex types to void*
  25. 02b,30jul99,dbs  fix build issues on SIMNT
  26. 02a,29jul99,dbs  add SIMNT support
  27. 01z,28jul99,drm  Changing g_defaultServerPriority to g_defaultServerPriority.
  28. 01y,27jul99,drm  Removing PS_CLNT_ASSIGNED enum entry.
  29. 01x,16jul99,dbs  reverse T2OLE expression, remove need for USES_CONVERSION
  30. 01w,10jun99,dbs  move vxdcom-private funcs out of here
  31. 01v,04jun99,dbs  remove public registry APIs
  32. 01u,03jun99,dbs  make mutex lock return void
  33. 01t,03jun99,dbs  fix long long type for W32
  34. 01s,02jun99,aim  #undef Free if it's defined
  35. 01r,02jun99,dbs  use new OS-specific macros
  36. 01q,20may99,dbs  add SysAllocStringByteLen() API
  37. 01p,07may99,dbs  add PROTSEQ typedef
  38. 01o,03may99,drm  adding priority scheme support
  39. 01n,28apr99,dbs  remove COM_NO_WINDOWS_H
  40. 01m,20apr99,dbs  add TLS defs for Win32, remove CoSetMalloc() API
  41. 01l,14apr99,dbs  fix alloca() definition for Win32
  42. 01k,14apr99,dbs  add definition for alloca() in gcc
  43. 01j,31mar99,dbs  added SysAllocStringLen API
  44. 01i,19mar99,drm  added CoCreateGuid() declaration
  45. 01h,01mar99,dbs  add GUID_NULL definition
  46. 01g,19feb99,dbs  add more wide-char support
  47. 01f,11feb99,dbs  add CoSetMalloc API
  48. 01e,04feb99,dbs  fix wide-char type for portability
  49. 01d,03feb99,dbs  use STDMETHOD macros
  50. 01c,20jan99,dbs  fix file names - vxcom becomes com
  51. 01b,08jan99,dbs  add TLS functions
  52. 01a,18dec98,dbs  created (from dcomLib.h)
  53. */
  54. /*
  55.  DESCRIPTION:
  56.  This file defines a working subset of the COM API (as defined by
  57.  Microsoft) for support of plain COM in VxWorks.
  58.  A slight difference from the MS implementation is that
  59.  CoCreateInstance() only works for CLSCTX_INPROC servers, and
  60.  CoCreateInstanceEx() must be used for CLSCTX_REMOTE servers.
  61.  Also, CoGetClassObject() is only available when DCOM is included, and
  62.  not under plain VXCOM.
  63.  
  64.  */
  65. #ifndef __INCcomLib_h
  66. #define __INCcomLib_h
  67. #include <string.h>
  68. #include "vxidl.h"
  69. #include "comCoreLib.h"
  70. #include "semLib.h"
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74.     
  75. extern int g_defaultServerPriority;
  76. /*
  77.  * The COM initialization type -- only COINIT_MULTITHREADED is
  78.  * accepted by VxCOM / VxDCOM, the others are provided for Win32
  79.  * compatibility.
  80. */
  81. typedef enum
  82.     {
  83.     COINIT_APARTMENTTHREADED = 0x2,  // apartment model - not supported
  84.     COINIT_MULTITHREADED     = 0x0,  // call objects on any thread.
  85.     COINIT_DISABLE_OLE1DDE   = 0x4,  // [don't use DDE for Ole1 support]
  86.     COINIT_SPEED_OVER_MEMORY = 0x8,  // [trade memory for speed?]
  87.     } COINIT;
  88. //////////////////////////////////////////////////////////////////////////
  89. //
  90. // Public API Functions - these mimic the Win32 CoXxxx API calls.
  91. //
  92. //////////////////////////////////////////////////////////////////////////
  93. STATUS comLibInit (void);
  94. HRESULT CoCreateInstance
  95.     (
  96.     REFCLSID rclsid, // CLSID of the object
  97.     IUnknown* pUnkOuter, // pointer to aggregating object
  98.     DWORD dwClsContext, // one of CLSCTX values
  99.     REFIID riid, // IID of desired interface
  100.     void** ppv // output interface ptr
  101.     );
  102. HRESULT CoInitialize (void*);
  103. HRESULT CoInitializeEx (void*, DWORD);
  104. void    CoUninitialize (void);
  105. DWORD CoGetCurrentProcess (void);
  106. void* CoTaskMemAlloc (ULONG cb); 
  107. void* CoTaskMemRealloc (LPVOID pv, ULONG cb); 
  108. void  CoTaskMemFree (LPVOID pv); 
  109. HRESULT CoGetMalloc 
  110.     (
  111.     DWORD               dwMemContext,   // private or shared
  112.     IMalloc**           ppMalloc        // output ptr
  113.     );
  114. HRESULT CoCreateGuid (GUID *pguid);
  115. BSTR SysAllocString (const OLECHAR*);
  116. BSTR SysAllocStringLen (const OLECHAR*, unsigned long);
  117. BSTR SysAllocStringByteLen (const char*, unsigned long);
  118. HRESULT SysFreeString (BSTR);
  119. DWORD SysStringLen (BSTR);
  120. DWORD SysStringByteLen (BSTR);
  121. int StringFromGUID2
  122.     (
  123.     REFGUID rguid, // IID to be converted
  124.     LPOLESTR lpsz, // resulting string
  125.     int cbMax // max size of returned string
  126.     );
  127. HRESULT StringFromCLSID
  128.     (
  129.     REFCLSID rclsid, // CLSID to be converted
  130.     LPOLESTR* ppsz // output var to receive string
  131.     );
  132. HRESULT StringFromIID
  133.     (
  134.     REFIID riid, // IID to be converted
  135.     LPOLESTR* ppsz // output var to receive string
  136.     );
  137. HRESULT CLSIDFromString
  138.     (
  139.     LPCOLESTR lpsz, // string representation of CLSID
  140.     LPCLSID pclsid // pointer to CLSID
  141.     );
  142. HRESULT IIDFromString
  143.     (
  144.     LPCOLESTR lpsz, // string representation of IID
  145.     LPIID piid // pointer to IID
  146.     );
  147. BOOL IsEqualGUID 
  148.     (
  149.     REFGUID             guid1,
  150.     REFGUID             guid2
  151.     );
  152. BOOL IsEqualCLSID 
  153.     (
  154.     REFCLSID            clsid1,
  155.     REFCLSID            clsid2
  156.     );
  157. BOOL IsEqualIID 
  158.     (
  159.     REFIID              iid1,
  160.     REFIID              iid2
  161.     );
  162. HRESULT WriteClassStm
  163.     (
  164.     IStream *           pStm,           // IStream to store in
  165.     REFCLSID            rclsid          // CLSID to be stored in stream
  166.     );
  167. HRESULT ReadClassStm
  168.     (
  169.     IStream *           pStm,           // stream holding the CLSID
  170.     CLSID *             pclsid          // output CLSID
  171.     );
  172. #ifndef V_VT
  173. /* Variant access macros */
  174. #define V_VT(X)         ((X)->vt)
  175. #define V_ISARRAY(X)    (V_VT(X)&VT_ARRAY)
  176. #define V_UI1(X)         ((X)->bVal)
  177. #define V_I2(X)          ((X)->iVal)
  178. #define V_I4(X)          ((X)->lVal)
  179. #define V_R4(X)          ((X)->fltVal)
  180. #define V_R8(X)          ((X)->dblVal)
  181. #define V_CY(X)          ((X)->cyVal)
  182. #define V_DATE(X)        ((X)->date)
  183. #define V_BSTR(X)        ((X)->bstrVal)
  184. #define V_ERROR(X)       ((X)->scode)
  185. #define V_BOOL(X)        ((X)->boolVal)
  186. #define V_UNKNOWN(X)     ((X)->punkVal)
  187. #define V_ARRAY(X)       ((X)->parray)
  188. #define V_VARIANT(X)  ((X)->pvarVal)
  189. #endif /* V_VT */
  190. void VariantInit (VARIANT* v);
  191. HRESULT VariantClear (VARIANT* v);
  192. HRESULT VariantCopy (VARIANT* d, VARIANT* s);
  193. HRESULT VariantChangeType (VARIANT * d, 
  194.                                       VARIANT * s, 
  195.                                       USHORT wFlags, 
  196.                                       VARTYPE vt);
  197. SAFEARRAY * SafeArrayCreate
  198.     ( 
  199.     VARTYPE             vt,
  200.     UINT                cDims,
  201.     SAFEARRAYBOUND *    rgsabound
  202.     );
  203. HRESULT SafeArrayDestroy
  204.     (
  205.     SAFEARRAY *         psa
  206.     );
  207. HRESULT SafeArrayLock (SAFEARRAY * psa);
  208. HRESULT SafeArrayUnlock (SAFEARRAY * psa);
  209. HRESULT SafeArrayPutElement
  210.     (
  211.     SAFEARRAY *     psa,
  212.     long *          rgIndicies,
  213.     void *          pv
  214.     );
  215. HRESULT SafeArrayGetElement
  216.     (
  217.     SAFEARRAY *     psa,
  218.     long *          rgIndicies,
  219.     void *          pv
  220.     );
  221. HRESULT SafeArrayAccessData
  222.     ( 
  223.     SAFEARRAY *  psa,       
  224.     void **  ppvData  
  225.     );
  226. HRESULT SafeArrayUnaccessData
  227.     ( 
  228.     SAFEARRAY *  psa  
  229.     );
  230. HRESULT SafeArrayCopy
  231.     (
  232.     SAFEARRAY * psa, 
  233.     SAFEARRAY ** ppsaOut 
  234.     );
  235. HRESULT SafeArrayGetLBound
  236.     (
  237.     SAFEARRAY * psa, 
  238.     unsigned int nDim, 
  239.     long * plLbound 
  240.     );
  241. HRESULT SafeArrayGetUBound
  242.     (
  243.     SAFEARRAY * psa, 
  244.     unsigned int nDim, 
  245.     long * plUbound
  246.     );
  247.   
  248. UINT SafeArrayGetDim
  249.     ( 
  250.     SAFEARRAY * psa
  251.     );
  252.   
  253. UINT SafeArrayGetElemsize
  254.     (
  255.     SAFEARRAY * psa
  256.     );
  257. HRESULT SafeArrayGetVartype
  258.     ( 
  259.     SAFEARRAY * psa, 
  260.     VARTYPE * pvt  
  261.     );
  262. const char* vxcomGUID2String (REFGUID guid);
  263. HRESULT comStreamCreate
  264.     (
  265.     const void* pMem, // raw memory block
  266.     unsigned long len, // length
  267.     IStream** ppStream // output stream-ptr
  268.     );
  269. int comWideToAscii
  270.     (
  271.     char* result, // resulting ascii string
  272.     const OLECHAR* wstr, // input wide-string
  273.     int maxLen // max length to convert
  274.     );
  275. int comAsciiToWide
  276.     (
  277.     OLECHAR* result, // resulting wide string
  278.     const char* str, // input string
  279.     int maxLen // max length to convert
  280.     );
  281. size_t comWideStrLen
  282.     (
  283.     const OLECHAR* wsz // wide string
  284.     );
  285. OLECHAR* comWideStrCopy
  286.     (
  287.     OLECHAR* wszDst, // destination
  288.     const OLECHAR* wszSrc // source
  289.     );
  290. HRESULT vxdcomClassRegister
  291.     (
  292.     REFCLSID         clsid, // key
  293.     PFN_GETCLASSOBJECT          pFnGCO,         // ptr to GetClassObject() fn
  294.     VXDCOMPRIORITYSCHEME        priorityScheme, // priority scheme 
  295.     int                         priority // priority assoc. with scheme
  296.     );
  297. //////////////////////////////////////////////////////////////////////////
  298. //
  299. // Inline ASCII/WIDE conversion macros a la ATL. Unlike ATL, a
  300. // function need not declare USES_CONVERSION at the top, but can
  301. // freely use the macros to do inline conversion of wide-to-ascii
  302. // (e.g. OLE2T(pwszSomeWideString)) or ascii-to-wide (e.g. T2OLE("some
  303. // ASCII text")) on any architecture. Currently, OLECHAR != wchar_t on
  304. // all VxWorks architectures, so use of Wide Literal Strings
  305. // (e.g. L"some wide text") is not recommended.
  306. //
  307. #ifdef __GNUC__
  308. # ifndef alloca
  309. #  define alloca __builtin_alloca
  310. # endif
  311. #elif defined(__DCC__)
  312. /* its a builtin for DCC */
  313. #else
  314. #include <malloc.h>
  315. #endif
  316. #ifndef USES_CONVERSION
  317. #define USES_CONVERSION
  318. #endif
  319. OLECHAR* comT2OLEHelper (void*,const char*);
  320. char*    comOLE2THelper (void*,const OLECHAR*);
  321. #define T2OLE(psz) 
  322.     ((psz) ? (comT2OLEHelper (alloca (sizeof (OLECHAR) * (strlen (psz) + 1)), 
  323.       psz)) : 0)
  324. #define OLE2T(pwsz) 
  325.     ((pwsz) ? (comOLE2THelper(alloca (comWideStrLen (pwsz) + 1), pwsz)) : 0)
  326. #ifdef __cplusplus
  327. }
  328. #endif
  329.     
  330. #endif