home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WOLEAUTO.HPP < prev    next >
C/C++ Source or Header  |  1996-10-18  |  18KB  |  496 lines

  1. /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2.    %     Copyright (C) 1994, by WATCOM International Inc.  All rights    %
  3.    %     reserved.  No part of this software may be reproduced or        %
  4.    %     used in any form or by any means - graphic, electronic or       %
  5.    %     mechanical, including photocopying, recording, taping or        %
  6.    %     information storage and retrieval systems - except with the     %
  7.    %     written permission of WATCOM International Inc.                 %
  8.    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. */
  10.  
  11. #ifndef _WOLEAUTO_HPP_INCLUDED
  12. #define _WOLEAUTO_HPP_INCLUDED
  13.  
  14. #ifndef _WNO_PRAGMA_PUSH
  15. #pragma pack(push,8);
  16. #pragma enum int;
  17. #endif
  18.  
  19. #include <stdarg.h>
  20. #ifndef _WOLETYPE_HPP_INCLUDED
  21. #   include "woletype.hpp"
  22. #endif
  23. #ifndef _WSTRING_HPP_INCLUDED
  24. #   include "wstring.hpp"
  25. #endif
  26. #ifndef _WOLEBSTR_HPP_INCLUDED
  27. #   include "wolebstr.hpp"
  28. #endif
  29. #ifndef _WBUFFER_HPP_INCLUDED
  30. #   include "wbuffer.hpp"
  31. #endif
  32. #ifndef _WARRAY_HPP_INCLUDED
  33. #  include "warray.hpp"
  34. #endif
  35.  
  36. enum WAmbientID {
  37.     WAmbient_BACKCOLOR         = (-701)
  38. ,   WAmbient_DISPLAYNAME       = (-702)
  39. ,   WAmbient_FONT              = (-703)
  40. ,   WAmbient_FORECOLOR         = (-704)
  41. ,   WAmbient_LOCALEID          = (-705)
  42. ,   WAmbient_MESSAGEREFLECT    = (-706)
  43. ,   WAmbient_SCALEUNITS        = (-707)
  44. ,   WAmbient_TEXTALIGN         = (-708)
  45. ,   WAmbient_USERMODE          = (-709)
  46. ,   WAmbient_UIDEAD            = (-710)
  47. ,   WAmbient_SHOWGRABHANDLES   = (-711)
  48. ,   WAmbient_SHOWHATCHING      = (-712)
  49. ,   WAmbient_DISPLAYASDEFAULT  = (-713)
  50. ,   WAmbient_SUPPORTSMNEMONICS = (-714)
  51. ,   WAmbient_AUTOCLIP          = (-715)
  52. };
  53.  
  54. enum WDispatchFlag {
  55.     WDispatchFlag_Method                = 0x1
  56. ,   WDispatchFlag_PropertyGet           = 0x2
  57. ,   WDispatchFlag_PropertyPut           = 0x4
  58. ,   WDispatchFlag_PropertyPutRef        = 0x8
  59. };
  60.  
  61. enum WInvokeError {
  62.     WInvokeError_None
  63. ,   WInvokeError_HelperNotInitialized
  64. ,   WInvokeError_NoErrorInfo
  65. ,   WInvokeError_CallNotMade
  66. ,   WInvokeError_OutOfMemory
  67. ,   WInvokeError_TooManyParams
  68. ,   WInvokeError_BadNamedParam
  69. ,   WInvokeError_BadParamCount
  70. ,   WInvokeError_BadParamArray
  71. ,   WInvokeError_BadVarType
  72. ,   WInvokeError_Exception
  73. ,   WInvokeError_MemberNotFound
  74. ,   WInvokeError_Overflow
  75. ,   WInvokeError_ParamNotFound
  76. ,   WInvokeError_TypeMismatch
  77. ,   WInvokeError_Error
  78. };
  79.  
  80. /*************************************************************************
  81.  *
  82.  * WExceptionInfo -- Exception Information
  83.  *
  84.  *
  85.  *   Events:
  86.  *
  87.  *
  88.  *************************************************************************/
  89.  
  90. class WCMCLASS WExceptionInfo {
  91.  
  92.     public:
  93.  
  94.     /**********************************************************
  95.      * Constructors and Destructors
  96.      *********************************************************/
  97.         WExceptionInfo();
  98.         WExceptionInfo( const WExceptionInfo & excep );
  99.         WExceptionInfo( WPIErrorInfo pErrorInfo );
  100.         ~WExceptionInfo();
  101.  
  102.     public:
  103.  
  104.     /**************************************************************
  105.      * Properties
  106.      **************************************************************/
  107.  
  108.         // WCode
  109.         WBool SetWCode( WUShort wcode );
  110.         WUShort GetWCode() const;
  111.  
  112.         // Scode
  113.         WBool SetSCode( WScode scode );
  114.         WScode GetSCode() const;
  115.  
  116.         // Description
  117.         WBool SetDescription( const WString & description );
  118.         WString GetDescription() const;
  119.  
  120.         // Help File
  121.         WBool SetHelpFile( const WString & helpFile );
  122.         WString GetHelpFile() const;
  123.  
  124.         // Source
  125.         WBool SetSource( const WString & source );
  126.         WString GetSource() const;
  127.  
  128.         // Help Context
  129.         WBool SetHelpContext( WULong helpContext );
  130.         WULong GetHelpContext() const;
  131.  
  132.         // GUID
  133.         WBool SetGUID( const WGUID & guid );
  134.         WGUID GetGUID() const;
  135.  
  136.         WBool SetExceptionInfo( void );
  137.         static WBool GetExceptionInfo( WPIDispatch wdisp, const WIID & wiid,
  138.                                        WExceptionInfo & excepInfo );
  139.  
  140.     /**************************************************************
  141.      * Methods
  142.      **************************************************************/
  143.  
  144.         void Display( void );
  145.  
  146.         static WBool ClearExceptionInfo( void );
  147.  
  148.     /**********************************************************
  149.      * Operators
  150.      *********************************************************/
  151.     
  152.         WExceptionInfo & operator=( const WExceptionInfo & excep );
  153.  
  154.     private:
  155.  
  156.     /**********************************************************
  157.      * Data Members
  158.      *********************************************************/
  159.     
  160.         WUShort         _wCode;
  161.         WScode          _scode;
  162.         WString         _source;
  163.         WString         _description;
  164.         WString         _helpFile;
  165.         WULong          _helpContext;
  166.         WGUID           _guid;
  167. };
  168.  
  169.  
  170. enum WVarEnum {
  171.     WVT_EMPTY           = 0,
  172.     WVT_NULL            = 1,
  173.     WVT_I2              = 2,
  174.     WVT_I4              = 3,
  175.     WVT_R4              = 4,
  176.     WVT_R8              = 5,
  177.     WVT_CY              = 6,
  178.     WVT_DATE            = 7,
  179.     WVT_BSTR            = 8,
  180.     WVT_DISPATCH        = 9,
  181.     WVT_ERROR           = 10,
  182.     WVT_BOOL            = 11,
  183.     WVT_VARIANT         = 12,
  184.     WVT_UNKNOWN         = 13,
  185.     WVT_I1              = 16,
  186.     WVT_UI1             = 17,
  187.     WVT_UI2             = 18,
  188.     WVT_UI4             = 19,
  189.     WVT_I8              = 20,
  190.     WVT_UI8             = 21,
  191.     WVT_INT             = 22,
  192.     WVT_UINT            = 23,
  193.     WVT_VOID            = 24,
  194.     WVT_HRESULT         = 25,
  195.     WVT_PTR             = 26,
  196.     WVT_SAFEARRAY       = 27,
  197.     WVT_CARRAY          = 28,
  198.     WVT_USERDEFINED     = 29,
  199.     WVT_LPSTR           = 30,
  200.     WVT_LPWSTR          = 31,
  201.     WVT_FILETIME        = 64,
  202.     WVT_BLOB            = 65,
  203.     WVT_STREAM          = 66,
  204.     WVT_STORAGE         = 67,
  205.     WVT_STREAMED_OBJECT = 68,
  206.     WVT_STORED_OBJECT   = 69,
  207.     WVT_BLOB_OBJECT     = 70,
  208.     WVT_CF              = 71,
  209.     WVT_CLSID           = 72,
  210.  
  211.     // extensions for ole controls
  212.     WVT_COLOR           = WVT_I4,
  213.     WVT_XPOS_PIXELS     = WVT_I4,
  214.     WVT_YPOS_PIXELS     = WVT_I4,
  215.     WVT_XSIZE_PIXELS    = WVT_I4,
  216.     WVT_YSIZE_PIXELS    = WVT_I4,
  217.     WVT_XPOS_HIMETRIC   = WVT_I4,
  218.     WVT_YPOS_HIMETRIC   = WVT_I4,
  219.     WVT_XSIZE_HIMETRIC  = WVT_I4,
  220.     WVT_YSIZE_HIMETRIC  = WVT_I4,
  221.     WVT_TRISTATE        = WVT_I2,
  222.     WVT_OPTEXCLUSIVE    = WVT_BOOL,
  223.     WVT_FONT            = WVT_DISPATCH,
  224.     WVT_PICTURE         = WVT_DISPATCH,
  225.  
  226.     // 4 BYTE windows handle
  227.     WVT_HANDLE          = WVT_I4
  228. };
  229.  
  230. #define WVT_VECTOR      (0x1000)
  231. #define WVT_ARRAY       (0x2000)
  232. #define WVT_BYREF       (0x4000)
  233. #define WVT_RESERVED    (0x8000)
  234.  
  235. #define WDISP_E_PARAMNOTFOUND   0x80020004L
  236. #define W_INV_ALL_PARAMS        0xffffffff
  237.  
  238. typedef unsigned short WVarType;
  239.  
  240. // forward type declaration
  241. struct _WVARIANT;
  242.  
  243. typedef struct _WVARIANT {
  244.  
  245.     /**********************************************************
  246.      * Data Members
  247.      *********************************************************/
  248.     
  249.     WVarType            vt;
  250.     unsigned short      wReserved1;
  251.     unsigned short      wReserved2;
  252.     unsigned short      wReserved3;
  253.     union
  254.     {
  255.         unsigned char   bVal;           /* WVT_UI1                      */
  256.         short           iVal;           /* WVT_I2                       */
  257.         long            lVal;           /* WVT_I4                       */
  258.         float           fltVal;         /* WVT_R4                       */
  259.         double          dblVal;         /* WVT_R8                       */
  260.         WVARIANT_BOOL   bool;           /* WVT_BOOL                     */
  261.         WScode          scode;          /* WVT_ERROR                    */
  262.         WCurrency       cyVal;          /* WVT_CY                       */
  263.         WDate           date;           /* WVT_DATE                     */
  264.         WBStr           bstrVal;        /* WVT_BSTR                     */
  265.         WPIUnknown      punkVal;        /* WVT_UNKNOWN                  */
  266.         WPIDispatch     pdispVal;       /* WVT_DISPATCH                 */
  267.         WSafeArray      *parray;        /* WVT_ARRAY|*                  */
  268.         unsigned char   *pbVal;         /* WVT_BYREF|WVT_UI1            */
  269.         short           *piVal;         /* WVT_BYREF|WVT_I2             */
  270.         long            *plVal;         /* WVT_BYREF|WVT_I4             */
  271.         float           *pfltVal;       /* WVT_BYREF|WVT_R4             */
  272.         double          *pdblVal;       /* WVT_BYREF|WVT_R8             */
  273.         WVARIANT_BOOL   *pbool;         /* WVT_BYREF|WVT_BOOL           */
  274.         WScode          *pscode;        /* WVT_BYREF|WVT_ERROR          */
  275.         WCurrency       *pcyVal;        /* WVT_BYREF|WVT_CY             */
  276.         WDate           *pdate;         /* WVT_BYREF|WVT_DATE           */
  277.         WBStr           *pbstrVal;      /* WVT_BYREF|WVT_BSTR           */
  278.         WPIUnknown      *ppunkVal;      /* WVT_BYREF|WVT_UNKNOWN        */
  279.         WPIDispatch     *ppdispVal;     /* WVT_BYREF|WVT_DISPATCH       */
  280.         WSafeArray      **pparray;      /* WVT_BYREF|WVT_ARRAY|*        */
  281.         _WVARIANT       *pvarVal;       /* WVT_BYREF|WVT_VARIANT        */
  282.         void            *byref;         /* Generic ByRef                */
  283.  
  284.         // WClass extras
  285.         unsigned short  uiVal;          /* WVT_UI2                      */
  286.         unsigned long   ulVal;          /* WVT_UI4                      */
  287.         char            cVal;           /* WVT_I1                       */
  288.         unsigned int    uintVal;        /* WVT_UINT                     */
  289.         int             intVal;         /* WVT_INT                      */
  290.         char            *pcVal;         /* WVT_BYREF|WVT_I1             */
  291.         unsigned short  *puiVal;        /* WVT_BYREF|WVT_UI2            */
  292.         unsigned long   *pulVal;        /* WVT_BYREF|WVT_UI4            */
  293.         unsigned int    *puintVal;      /* WVT_BYREF|WVT_UINT           */
  294.         int             *pintVal;       /* WVT_BYREF|WVT_INT            */
  295.         WBString        *pwbstringVal;
  296.     };
  297. } _WVARIANT;
  298.  
  299.  
  300. typedef _WVARIANT WVARIANT;
  301.  
  302. class WVariant;
  303.  
  304. extern template WArrayReference<WVariant>;
  305. extern template WArray<WVariant>;
  306.  
  307. typedef WArray<WVariant> WVariantArray;
  308.  
  309. /*************************************************************************
  310.  *
  311.  * WVariant
  312.  *
  313.  *
  314.  *   Events:
  315.  *
  316.  *
  317.  *************************************************************************/
  318.  
  319. // The contents of this class are not managed in any way.
  320. // This means that no attempt is made to call Release through
  321. // interface pointers, etc. The only exception to this rule are
  322. // strings.
  323. class WCMCLASS WVariant : public _WVARIANT {
  324.  
  325.     public:
  326.  
  327.         /**********************************************************
  328.          * Constructors and Destructors
  329.          *********************************************************/
  330.  
  331.         WVariant( void );
  332.         WVariant( unsigned char b );
  333.         WVariant( short s );
  334.         WVariant( long l );
  335.         WVariant( float flt );
  336.         WVariant( double dbl );
  337.         WVariant( WCurrency cy );
  338.         WVariant( WBStr bstr );
  339.         WVariant( WPIUnknown punk );
  340.         WVariant( WPIDispatch pdisp );
  341.         WVariant( WSafeArray *p );
  342.         WVariant( unsigned char *pb );
  343.         WVariant( short *pi );
  344.         WVariant( long *pl );
  345.         WVariant( float *pflt );
  346.         WVariant( double *pdbl );
  347.         WVariant( WCurrency *pcy );
  348.         WVariant( WBStr *pbstr );
  349.         WVariant( WPIUnknown *ppunk );
  350.         WVariant( WPIDispatch *ppdisp );
  351.         WVariant( WSafeArray **ppa );
  352.         WVariant( WVariant *pvar );
  353.         WVariant( unsigned short ui );
  354.         WVariant( unsigned long ul );
  355.         WVariant( char c );
  356.         WVariant( unsigned int ui );
  357.         WVariant( int i );
  358.         WVariant( unsigned short *pui );
  359.         WVariant( unsigned long *pul );
  360.         WVariant( unsigned int *puint );
  361.         WVariant( int *pint );
  362.  
  363.         // Ambiguous with short:
  364.         // WVariant( WVARIANT_BOOL b )  { vt = WVT_BOOL; bool = b; freeMember = isWBString = FALSE; SetReserved(); };
  365.         // Ambiguous with long:
  366.         // WVariant( WScode sc )        { vt = WVT_ERROR; scode = sc; freeMember = isWBString = FALSE; SetReserved(); };
  367.         // Ambiguous with double:
  368.         // WVariant( WDate dt )         { vt = WVT_DATE; date = dt; freeMember = isWBString = FALSE; SetReserved(); };
  369.         // Ambiguous with short *:
  370.         // WVariant( WVARIANT_BOOL *pb ){ vt = WVT_BYREF|WVT_BOOL; pbool = pb; freeMember = isWBString = FALSE; SetReserved(); };
  371.         // Ambiguous with long *:
  372.         // WVariant( WScode *psc )      { vt = WVT_BYREF|WVT_ERROR; pscode = psc; freeMember = isWBString = FALSE; SetReserved(); };
  373.         // Ambiguous with double *:
  374.         // WVariant( WDate *pdt )       { vt = WVT_BYREF|WVT_DATE; pdate = pdt; freeMember = isWBString = FALSE; SetReserved(); }
  375.  
  376.         // Amibiguous the the string constructors.
  377.         // WVariant( char *pc )         { vt = WVT_BYREF|WVT_I1; pcVal = pc; freeMember = isWBString = FALSE; SetReserved(); };
  378.  
  379.         WVariant( const WChar * const str );
  380.  
  381.         // The following constuctor sets freeMember to TRUE and
  382.         // cause BSTR's to be allocated NOT pointers to WStrings.
  383.         WVariant( const WString & str );
  384.         WVariant( const WBString & wbstr );
  385.  
  386.         // Copy constructor. This member will cause BSTR's or WString pointers
  387.         // to be allocated instead of copied if freeMember is TRUE
  388.         WVariant( const WVariant & var );
  389.  
  390.         WVariant( const _WVARIANT & var );
  391.  
  392.         // WBuffer constructor. This member will cause a BSTR to be allocated
  393.         WVariant( const WBuffer & buffer );
  394.  
  395.         // WVariantArray constructor. This member will cause a
  396.         // SAFEARRAY of VARIANTS to be allocated
  397.         WVariant( WVariantArray & variantArray );
  398.  
  399.         ~WVariant();
  400.  
  401.         /**************************************************************
  402.          * Methods
  403.          **************************************************************/
  404.  
  405.         void Init( void );
  406.         WBool Clear( void );
  407.         WBool ChangeType( const WVarType vtNew );
  408.         WBool ChangeType( WVariant & dest, const WVarType vtNew );
  409.     
  410.         // NOTE: If vt is WVT_BSTR then the argument is a WString *
  411.         WBool Assign( void * val, WVarType type );
  412.     
  413.         // NOTE: If vtSet is WVT_BSTR then the argument is expected to
  414.         // be a WChar *
  415.         WBool Set( const WVarType vtSet, va_list arg );
  416.     
  417.         WBool BStrToWBString( void );
  418.         WBool WBStringToBStr( void );
  419.         WBool IsWBString() { return( isWBString ); };
  420.  
  421.         /**************************************************************
  422.          * Internal Methods
  423.          **************************************************************/
  424.  
  425.         void SetReserved( void );
  426.  
  427.         /**************************************************************
  428.          * Operators
  429.          **************************************************************/
  430.  
  431.         WVariant & operator=( const WVariant & var );
  432.  
  433.         // cast operators
  434.  
  435.         operator unsigned char() const;
  436.         operator short() const;
  437.         operator long() const;
  438.         WCMRETURNSFLOAT operator float() const;
  439.         WCMRETURNSFLOAT operator double() const;
  440.         //operator WVARIANT_BOOL() const;
  441.         //operator WScode() const;
  442.         operator WCurrency() const;
  443.         //operator WDate() const;
  444.         operator WBStr();
  445.         operator WString();
  446.         operator WBString();
  447.         operator WBuffer();
  448.         operator WPIUnknown() const;
  449.         operator WPIDispatch() const;
  450.         operator WSafeArray *() const;
  451.  
  452.         operator unsigned char *() const;
  453.         operator short *() const;
  454.         operator long *() const;
  455.         operator float *() const;
  456.         operator double *() const;
  457.         //operator WVARIANT_BOOL *() const;
  458.         //operator WScode *() const;
  459.         operator WCurrency *() const;
  460.         //operator WDate *() const;
  461.         operator WBStr *() const;
  462.         operator WPIUnknown *() const;
  463.         operator WPIDispatch *() const;
  464.         operator WSafeArray **() const;
  465.         operator _WVARIANT *() const;
  466.         operator void *() const;
  467.  
  468.         operator unsigned short() const;
  469.         operator unsigned long() const;
  470.         operator char() const;
  471.         operator unsigned int() const;
  472.         operator int() const;
  473.         operator char *() const;
  474.         operator unsigned short *() const;
  475.         operator unsigned long *() const;
  476.         operator unsigned int *() const;
  477.         operator int *() const;
  478.         operator WBString *();
  479.  
  480.     /**********************************************************
  481.      * Data Members
  482.      *********************************************************/
  483.  
  484.     private:
  485.         WBool freeMember;
  486.         WBool isWBString;
  487.     
  488. };
  489.  
  490. #ifndef _WNO_PRAGMA_PUSH
  491. #pragma enum pop;
  492. #pragma pack(pop);
  493. #endif
  494.  
  495. #endif // _WOLEAUTO_HPP_INCLUDED
  496.