home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 November / VPR9611B.ISO / vabasic / ntclnt.exe / DISK8 / data.8 / datab / INCLUDE / VVARIANT.H < prev    next >
C/C++ Source or Header  |  1996-07-29  |  15KB  |  453 lines

  1. /*------------------------------------------------------------------------
  2.  * $Source: /rcs/crcs/general/vvariant.h,v $
  3.  * Checked in by: $Author: bing $
  4.  * $Date: 1996/04/10 00:41:40 $              $Revision: 1.16 $
  5.  *
  6.  * Copyright 1987, Techtrol Ltd.
  7.  * Copyright 1990, Visual Edge Software Ltd.
  8.  * -----------------------------------------
  9.  * ALL RIGHTS RESERVED.     This notice is intended as a precaution against
  10.  * inadvertent publication, and shall not be deemed to constitute an
  11.  * acknowledgment that publication has    occurred nor to imply any waiver
  12.  * of confidentiality.    The year included in the notice is the year
  13.  * of the creation of the work.
  14.  *------------------------------------------------------------------------*/
  15. /*------------------------------------------------------------------------
  16.  *
  17.  *       Module Name: vvariant.h
  18.  *  Module Description: Cross platform APIs for OLE/COM data types
  19.  *
  20.  *          Date: May 1994
  21.  *
  22.  *------------------------------------------------------------------------*/
  23.  
  24. #ifndef VARIANT_H
  25. #define VARIANT_H
  26.  
  27. #include <vnls.h>
  28. #include <strutil.h>
  29. #include <vtoolkit.h>
  30.  
  31. #ifdef USE_OLE2
  32.  
  33. /*---------------------------------------------------------------------*/
  34. /*                  String API                   */
  35. /*---------------------------------------------------------------------*/
  36.  
  37. #    define VeSysAllocString        SysAllocString
  38. #    define VeSysReAllocString    SysReAllocString
  39. #    define VeSysAllocStringLen    SysAllocStringLen
  40. #    define VeSysReAllocStringLen    SysReAllocStringLen
  41. #    define VeSysFreeString        SysFreeString
  42. #    define VeSysStringLen        SysStringLen
  43.  
  44. /*---------------------------------------------------------------------*/
  45. /*                 SafeArray API                   */
  46. /*---------------------------------------------------------------------*/
  47.  
  48. #define VeSafeArrayAllocDescriptor    SafeArrayAllocDescriptor
  49. #define VeSafeArrayDestroyDescriptor    SafeArrayDestroyDescriptor
  50. #define VeSafeArrayCreate        SafeArrayCreate
  51. #define VeSafeArrayDestroy        SafeArrayDestroy
  52. #define VeSafeArrayGetDim        SafeArrayGetDim
  53. #define VeSafeArrayGetElemsize        SafeArrayGetElemsize
  54. #define VeSafeArrayGetUBound        SafeArrayGetUBound
  55. #define VeSafeArrayGetLBound        SafeArrayGetLBound
  56. #define VeSafeArrayAllocData        SafeArrayAllocData
  57. #define VeSafeArrayDestroyData        SafeArrayDestroyData
  58. #define VeSafeArrayLock            SafeArrayLock
  59. #define VeSafeArrayUnlock        SafeArrayUnlock
  60. #define VeSafeArrayAccessData        SafeArrayAccessData
  61. #define VeSafeArrayUnaccessData        SafeArrayUnaccessData
  62. #define VeSafeArrayGetElement        SafeArrayGetElement
  63. #define VeSafeArrayPutElement        SafeArrayPutElement
  64. #define VeSafeArrayCopy            SafeArrayCopy
  65. #define VeSafeArrayRedim        SafeArrayRedim
  66.  
  67. /*---------------------------------------------------------------------*/
  68. /*                  Variant API                   */
  69. /*---------------------------------------------------------------------*/
  70.  
  71. #define VeVariantInit            VariantInit
  72. #define VeVariantClear            VariantClear
  73. #define VeVariantCopy            VariantCopy
  74. #define VeVariantCopyInd        VariantCopyInd
  75.  
  76. /*---------------------------------------------------------------------*/
  77. /*                  New Variant type                   */
  78. /*---------------------------------------------------------------------*/
  79. #define VT_VEOBJ        15
  80. #define V_VEOBJ(X)     V_UNION(X, punkVal)
  81. #define V_VEOBJREF(X)     V_UNION(X, ppunkVal)
  82.  
  83. #else
  84.  
  85. #include <visedge.h>
  86.  
  87. #    ifndef FAR
  88. #        define FAR
  89. #    endif
  90.  
  91. #    ifndef PASCAL
  92. #        define PASCAL VPASCAL
  93. #    endif
  94.  
  95. #    ifndef HUGEP
  96. #        define HUGEP
  97. #    endif
  98.  
  99. #    ifndef UINT
  100. #        define UINT unsigned int
  101. #    endif
  102.  
  103. #    ifndef WORD
  104. #        define WORD unsigned short
  105. #    endif
  106.  
  107. #    ifndef DWORD
  108. #        define DWORD unsigned long
  109. #    endif
  110.  
  111. #    ifndef ULONG
  112. #        define ULONG unsigned long
  113. #    endif
  114.  
  115. #    ifndef LONG
  116. #        define LONG long
  117. #    endif
  118.  
  119. #    ifndef USHORT
  120. #        define USHORT unsigned short
  121. #    endif
  122.  
  123. #    ifndef TRUE
  124. #        define TRUE 1
  125. #    endif
  126.  
  127. #    ifndef FALSE
  128. #        define FALSE 0
  129. #    endif
  130.  
  131. #ifdef __cplusplus
  132. #    define EXTERN_C extern "C"
  133. #else
  134. #    define EXTERN_C extern
  135. #endif
  136.  
  137. #define STDAPICALLTYPE    FAR
  138.  
  139. #define STDAPI_H(type) EXTERN_C VFUNCDECL(type) STDAPICALLTYPE
  140. #define STDAPI_C(type) EXTERN_C VFUNCDEF(type) STDAPICALLTYPE
  141. #define STDAPI_DECL    STDAPI_H(HRESULT)
  142. #define STDAPI_DEF     STDAPI_C(HRESULT)
  143.  
  144. #include <vscode.h>  /* Use our version of scode.h, not the OLE2 one.*/
  145.  
  146. typedef VTOleChar *    BSTR;
  147. typedef double        DATE;
  148. typedef unsigned short    VARTYPE;
  149.  
  150. typedef struct { int dummy; } IDispatch;
  151.  
  152. #ifndef BIXLIB_HACK
  153. /*
  154.  * Don't define IUnknown if BIXLIB_HACK is defined otherwise
  155.  * we get redefinition errors.    This should be resolved in bixlib.cc.
  156.  */
  157. typedef struct { int dummy; } IUnknown;
  158. #endif
  159.  
  160. /* 0 == FALSE, -1 == TRUE */
  161. typedef short  VARIANT_BOOL;
  162.  
  163. /* This is a helper struct for use in handling currency. */
  164. typedef struct tagCY
  165. {
  166.     unsigned long Lo; 
  167.     long          Hi; 
  168. } CY;
  169.  
  170. /*
  171.  * VARENUM usage key,
  172.  *
  173.  *   [V] - may appear in a VARIANT
  174.  *   [T] - may appear in a TYPEDESC
  175.  *   [P] - may appear in an OLE property set
  176.  */
  177. enum VARENUM
  178. {
  179.     VT_EMPTY           = 0,   /* [V]   [P]  nothing            */
  180.     VT_NULL           = 1,   /* [V]        SQL style Null        */
  181.     VT_I2           = 2,   /* [V][T][P]  2 byte signed int        */
  182.     VT_I4           = 3,   /* [V][T][P]  4 byte signed int        */
  183.     VT_R4           = 4,   /* [V][T][P]  4 byte real            */
  184.     VT_R8           = 5,   /* [V][T][P]  8 byte real            */
  185.     VT_CY           = 6,   /* [V][T][P]  currency            */
  186.     VT_DATE           = 7,   /* [V][T][P]  date            */
  187.     VT_BSTR           = 8,   /* [V][T][P]  binary string        */
  188.     VT_DISPATCH           = 9,   /* [V][T]        IDispatch *            */
  189.     VT_ERROR           = 10,  /* [V][T]        SCODE            */
  190.     VT_BOOL           = 11,  /* [V][T][P]  True=-1, False=0        */
  191.     VT_VARIANT           = 12,  /* [V][T][P]  VARIANT *            */
  192.     VT_UNKNOWN           = 13,  /* [V][T]        IUnknown *            */
  193.     VT_WBSTR           = 14,  /* [V][T]        wide binary string        */
  194.     VT_VEOBJ           = 15,  /* [V][T]        VE Object            */
  195.  
  196.     /*
  197.      * - The following a currently not supported but mentioned in OLE 2.0
  198.      *   header file 'variant.h'.
  199.      */
  200.     VT_I1           = 16,  /*    [T]        signed char            */
  201.     VT_UI1           = 17,  /* [V][T]        unsigned char        */
  202.     VT_UI2           = 18,  /*    [T]        unsigned short        */
  203.     VT_UI4           = 19,  /*    [T]        unsigned short        */
  204.     VT_I8           = 20,  /*    [T][P]  signed 64-bit int        */
  205.     VT_UI8           = 21,  /*    [T]        unsigned 64-bit int        */
  206.     VT_INT           = 22,  /*    [T]        signed machine int        */
  207.     VT_UINT           = 23,  /*    [T]        unsigned machine int    */
  208.     VT_VOID           = 24,  /*    [T]        C style void        */
  209.     VT_HRESULT           = 25,  /*    [T]                    */
  210.     VT_PTR           = 26,  /*    [T]        pointer type        */
  211.     VT_SAFEARRAY       = 27,  /*    [T]        (use VT_ARRAY in VARIANT)    */
  212.     VT_CARRAY           = 28,  /*    [T]        C style array        */
  213.     VT_USERDEFINED     = 29,  /*    [T]        user defined type        */
  214.     VT_LPSTR           = 30,  /*    [T][P]  null terminated string    */
  215.     VT_LPWSTR           = 31,  /*    [T][P]  wide null terminated string */
  216.  
  217.     VT_FILETIME           = 64,  /*       [P]  FILETIME            */
  218.     VT_BLOB           = 65,  /*       [P]  Length prefixed bytes    */
  219.     VT_STREAM           = 66,  /*       [P]  Name of the stream follows    */
  220.     VT_STORAGE           = 67,  /*       [P]  Name of the storage follows */
  221.     VT_STREAMED_OBJECT = 68,  /*       [P]  Stream contains an object    */
  222.     VT_STORED_OBJECT   = 69,  /*       [P]  Storage contains an object    */
  223.     VT_BLOB_OBJECT     = 70,  /*       [P]  Blob contains an object    */
  224.     VT_CF           = 71,  /*       [P]  Clipboard format        */
  225.     VT_CLSID           = 72   /*       [P]  A Class ID            */
  226. };
  227.  
  228. #define VT_VECTOR      0x1000 /*       [P]  simple counted array    */
  229. #define VT_ARRAY       0x2000 /* [V]        SAFEARRAY*            */
  230. #define VT_BYREF       0x4000 /* [V]                    */
  231. #define VT_RESERVED    0x8000
  232.  
  233. typedef struct
  234. {
  235.     unsigned long cElements;
  236.     long  lLbound;
  237. } SAFEARRAYBOUND;
  238.  
  239. typedef struct tagSAFEARRAY *LPSAFEARRAY;
  240.  
  241. typedef struct tagSAFEARRAY
  242. {
  243. #ifdef VE_INTERNAL
  244.     void*           pValidate;      /* Pointer to itself for validation */
  245. #endif
  246.     unsigned short cDims;           /* Number of dimensions.        */
  247.     unsigned short fFeatures;      /* SafeArray Flags.        */
  248.     unsigned short cbElements;     /* Size of one element.        */
  249.     unsigned short cLocks;           /* Number of locks on array. */
  250.     unsigned long  handle;           /* Handle on array.        */
  251.     void*           pvData;           /* Pointer to data.        */
  252.     SAFEARRAYBOUND rgsabound[1];   /* Array of dimensions.        */
  253. } SAFEARRAY;
  254.  
  255. #define FADF_AUTO    0x0001     /* array is allocated on the stack        */
  256. #define FADF_STATIC    0x0002     /* array is staticly allocated            */
  257. #define FADF_EMBEDDED    0x0004     /* array is embedded in a structure        */
  258. #define FADF_FIXEDSIZE    0x0010     /* array may not be resized or reallocated */
  259. #define FADF_BSTR    0x0100     /* an array of BSTRs                */
  260. #define FADF_UNKNOWN    0x0200     /* an array of IUnknown*            */
  261. #define FADF_DISPATCH    0x0400     /* an array of IDispatch*            */
  262. #define FADF_VARIANT    0x0800     /* an array of VARIANTs            */
  263. #define FADF_RESERVED    0xF0E8     /* bits reserved for future use        */
  264.  
  265. typedef struct tagVARIANT *LPVARIANT;
  266. typedef struct tagVARIANT VARIANTARG;
  267. typedef struct tagVARIANT *LPVARIANTARG;
  268.  
  269. typedef struct tagVARIANT
  270. {
  271.     VARTYPE vt;
  272.     WORD      wReserved1;
  273.     WORD      wReserved2;
  274.     WORD      wReserved3;
  275.     union {
  276.         unsigned char         bVal;      /* VT_UI1           */
  277.         short            iVal;      /* VT_I2               */
  278.         long            lVal;      /* VT_I4               */
  279.         struct { float    f;} fltVal;    /* VT_R4               */
  280.         struct { double    d;} dblVal;    /* VT_R8               */
  281.         VARIANT_BOOL        MS_bool;   /* VT_BOOL           */
  282.         SCODE            scode;     /* VT_ERROR           */
  283.         CY            cyVal;     /* VT_CY               */
  284.         struct { DATE    d;} date;      /* VT_DATE           */
  285.         BSTR            bstrVal;   /* VT_BSTR           */
  286.         IUnknown        *punkVal;  /* VT_UNKNOWN           */
  287.         IDispatch        *pdispVal; /* VT_DISPATCH           */
  288.         LPSAFEARRAY        parray;    /* VT_ARRAY|*           */
  289.  
  290.         unsigned char        *pbVal;    /* VT_BYREF|VT_UI1      */
  291.         short            *piVal;    /* VT_BYREF|VT_I2       */
  292.         long            *plVal;    /* VT_BYREF|VT_I4       */
  293.         float            *pfltVal;  /* VT_BYREF|VT_R4       */
  294.         double            *pdblVal;  /* VT_BYREF|VT_R8       */
  295.         VARIANT_BOOL        *pbool;    /* VT_BYREF|VT_BOOL     */
  296.         SCODE            *pscode;   /* VT_BYREF|VT_ERROR    */
  297.         CY            *pcyVal;   /* VT_BYREF|VT_CY       */
  298.         DATE            *pdate;    /* VT_BYREF|VT_DATE     */
  299.         BSTR            *pbstrVal; /* VT_BYREF|VT_BSTR     */
  300.         IUnknown        **ppunkVal;/* VT_BYREF|VT_UNKNOWN  */
  301.         IDispatch         **ppdispVal;/* VT_BYREF|VT_DISPATCH*/
  302.         LPSAFEARRAY        *pparray;  /* VT_BYREF|VT_ARRAY|*  */
  303.         LPVARIANT        pvarVal;   /* VT_BYREF|VT_VARIANT  */
  304.  
  305.         void            *byref;    /* Generic ByRef           */
  306.     } u;
  307. } VARIANT;
  308.  
  309. #define V_UNION(X, Y) ((X)->u.Y)
  310.  
  311. /* Variant access macros */
  312. #define V_VT(X)         ((X)->vt)
  313. #define V_ISBYREF(X)     (V_VT(X)&VT_BYREF)
  314. #define V_ISARRAY(X)     (V_VT(X)&VT_ARRAY)
  315. #define V_ISVECTOR(X)     (V_VT(X)&VT_VECTOR)
  316.  
  317. #define V_NONE(X)     V_I2(X)
  318. #define V_UI1(X)     V_UNION(X, bVal)
  319. #define V_UI1REF(X)     V_UNION(X, pbVal)
  320. #define V_I2(X)         V_UNION(X, iVal)
  321. #define V_I2REF(X)     V_UNION(X, piVal)
  322. #define V_I4(X)         V_UNION(X, lVal)
  323. #define V_I4REF(X)     V_UNION(X, plVal)
  324. #define V_R4(X)         V_UNION(X, fltVal.f)
  325. #define V_R4REF(X)     V_UNION(X, pfltVal)
  326. #define V_R8(X)         V_UNION(X, dblVal.d)
  327. #define V_R8REF(X)     V_UNION(X, pdblVal)
  328. #define V_BOOL(X)     V_UNION(X, MS_bool)
  329. #define V_BOOLREF(X)     V_UNION(X, pbool)
  330. #define V_ERROR(X)     V_UNION(X, scode)
  331. #define V_ERRORREF(X)     V_UNION(X, pscode)
  332. #define V_CY(X)         V_UNION(X, cyVal)
  333. #define V_CYREF(X)     V_UNION(X, pcyVal)
  334. #define V_DATE(X)     V_UNION(X, date.d)
  335. #define V_DATEREF(X)     V_UNION(X, pdate)
  336. #define V_BSTR(X)     V_UNION(X, bstrVal)
  337. #define V_BSTRREF(X)     V_UNION(X, pbstrVal)
  338. #define V_UNKNOWN(X)     V_UNION(X, punkVal)
  339. #define V_UNKNOWNREF(X)     V_UNION(X, ppunkVal)
  340. #define V_DISPATCH(X)     V_UNION(X, pdispVal)
  341. #define V_DISPATCHREF(X) V_UNION(X, ppdispVal)
  342. #define V_VEOBJ(X)     V_UNION(X, punkVal)
  343. #define V_VEOBJREF(X)     V_UNION(X, ppunkVal)
  344. #define V_VARIANTREF(X)     V_UNION(X, pvarVal)
  345. #define V_ARRAY(X)     V_UNION(X, parray)
  346. #define V_ARRAYREF(X)     V_UNION(X, pparray)
  347. #define V_BYREF(X)     V_UNION(X, byref)
  348.  
  349. #ifdef __cplusplus
  350. extern "C"
  351. {
  352. #endif
  353.  
  354. /*---------------------------------------------------------------------*/
  355. /*                  String API                   */
  356. /*---------------------------------------------------------------------*/
  357.  
  358. VFUNCDECL(BSTR)     VeSysAllocString    (VTOleChar *);
  359. VFUNCDECL(bool_t)VeSysReAllocString    (BSTR *, VTOleChar *);
  360. VFUNCDECL(BSTR)     VeSysAllocStringLen    (VTOleChar *, UINT);
  361. VFUNCDECL(bool_t)VeSysReAllocStringLen    (BSTR *, VTOleChar *, UINT);
  362. VFUNCDECL(void)     VeSysFreeString    (BSTR);
  363. VFUNCDECL(UINT)     VeSysStringLen        (BSTR);
  364.  
  365. /*---------------------------------------------------------------------*/
  366. /*                 SafeArray API                   */
  367. /*---------------------------------------------------------------------*/
  368.  
  369. VFUNCDECL(HRESULT)    VeSafeArrayAllocDescriptor(
  370.                 UINT        cDims,
  371.                 LPSAFEARRAY    *rtrn);
  372.  
  373. VFUNCDECL(HRESULT)    VeSafeArrayDestroyDescriptor(LPSAFEARRAY psa);
  374.  
  375. VFUNCDECL(HRESULT)    VeSafeArrayDestroy(LPSAFEARRAY psa);
  376.  
  377. VFUNCDECL(LPSAFEARRAY)    VeSafeArrayCreate(
  378.                 VARTYPE        vt,
  379.                 UINT        cDims,
  380.                 SAFEARRAYBOUND    *rgsabound);
  381.  
  382. VFUNCDECL(HRESULT)    VeSafeArrayDestroy(LPSAFEARRAY psa);
  383.  
  384. VFUNCDECL(UINT)        VeSafeArrayGetDim(LPSAFEARRAY psa);
  385.  
  386. VFUNCDECL(UINT)        VeSafeArrayGetElemsize(LPSAFEARRAY psa);
  387.  
  388. VFUNCDECL(HRESULT)    VeSafeArrayGetUBound(
  389.                 LPSAFEARRAY    psa,
  390.                 UINT        nDim,
  391.                 LONG        *plUbound);
  392.  
  393. VFUNCDECL(HRESULT)    VeSafeArrayGetLBound(
  394.                 LPSAFEARRAY    psa,
  395.                 UINT        nDim,
  396.                 LONG        *plLbound);
  397.  
  398. VFUNCDECL(HRESULT)    VeSafeArrayAllocData(SAFEARRAY *pSafeArray);
  399.  
  400. VFUNCDECL(HRESULT)    VeSafeArrayDestroyData(SAFEARRAY *psa);
  401.  
  402. VFUNCDECL(HRESULT)    VeSafeArrayLock(LPSAFEARRAY psa);
  403.  
  404. VFUNCDECL(HRESULT)    VeSafeArrayUnlock(LPSAFEARRAY psa);
  405.  
  406. VFUNCDECL(HRESULT)    VeSafeArrayAccessData(
  407.                 LPSAFEARRAY    psa,
  408.                 void        * HUGEP*ppvData);
  409.  
  410. VFUNCDECL(HRESULT)    VeSafeArrayUnaccessData(LPSAFEARRAY psa);
  411.  
  412. VFUNCDECL(HRESULT)    VeSafeArrayGetElement(
  413.                 LPSAFEARRAY    psa,
  414.                 LONG        *rgIndices,
  415.                 void        *pv);
  416.  
  417. VFUNCDECL(HRESULT)    VeSafeArrayPutElement(
  418.                 LPSAFEARRAY    psa,
  419.                 LONG        *rgIndices,
  420.                 void        *pv);
  421.  
  422. VFUNCDECL(HRESULT)    VeSafeArrayCopy(
  423.                 LPSAFEARRAY    psa,
  424.                 LPSAFEARRAY    *ppsaOut);
  425.  
  426. VFUNCDECL(HRESULT)    VeSafeArrayRedim(
  427.                 SAFEARRAY    *pSafeArray,
  428.                 SAFEARRAYBOUND    *psaboundNew);
  429.  
  430. /*---------------------------------------------------------------------*/
  431. /*                  Variant API                   */
  432. /*---------------------------------------------------------------------*/
  433.  
  434. VFUNCDECL(void)        VeVariantInit(LPVARIANTARG pvarg);
  435.  
  436. VFUNCDECL(HRESULT)    VeVariantClear(LPVARIANTARG pvarg);
  437.  
  438. VFUNCDECL(HRESULT)    VeVariantCopy(
  439.                 LPVARIANTARG    pvargDest,
  440.                 LPVARIANTARG    pvargSrc);
  441.  
  442. VFUNCDECL(HRESULT)    VeVariantCopyInd(
  443.                 LPVARIANTARG    pvarDest,
  444.                 LPVARIANTARG    pvargSrc);
  445.  
  446. #ifdef __cplusplus
  447. } /* extern "C" */
  448. #endif
  449.  
  450. #endif /* USE_OLE2 */
  451.  
  452. #endif /* VARIANT_H */
  453.