home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / WOLESOBJ.HPP < prev    next >
C/C++ Source or Header  |  1996-12-05  |  8KB  |  232 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. /*************************************************************************
  12.  *
  13.  * WOleServerObject -- Ole Server Object class
  14.  *
  15.  *
  16.  *   Events:
  17.  *
  18.  *      QueryInterface          -- QueryInterface event
  19.  *
  20.  *************************************************************************/
  21.  
  22. #ifndef _WOLESOBJ_HPP_INCLUDED
  23. #define _WOLESOBJ_HPP_INCLUDED
  24.  
  25. #ifndef _WNO_PRAGMA_PUSH
  26. #pragma pack(push,8);
  27. #pragma enum int;
  28. #endif
  29.  
  30. #ifndef _WOLETYPE_HPP_INCLUDED
  31. #   include "woletype.hpp"
  32. #endif
  33. #ifndef _WSTRING_HPP_INCLUDED
  34. #   include "wstring.hpp"
  35. #endif
  36.  
  37. // forward class declarations
  38. class WCMCLASS WApplication;
  39. class WCMCLASS WOleClassManager;
  40. class WCMCLASS WOleServerObject;
  41. class WCMCLASS WOleServerObjectListEntry;
  42. class WCMCLASS WOleServerObjectRegistryData;
  43. class WCMCLASS WOleServerObject_IUnk;
  44. class WCMCLASS wllist_header;
  45. class WCMCLASS WOleInterfaceFamily;
  46.  
  47. typedef WOleServerObject * WCMDEF (*pfnOleSvrCreateInst)( WPIUnknown pUnkOuter );
  48. typedef WBool WCMDEF (*pfnOleSvrIsEqualClassID)( const WCLSID & clsid );
  49.  
  50. struct WOleServerObjectRegistryDataBlock {
  51.     WChar *_progID;
  52.     WChar *_viProgID;
  53.     WChar *_appFullName;
  54.     WChar *_appShortName;
  55.     WBool _insertable;
  56.     WBool _isOleControl;
  57.     WInt  _versionMajor;
  58.     WInt  _versionMinor;
  59. };
  60.  
  61. class WCMCLASS WOleServerObjectRegistryData {
  62.     public:
  63.         WOleServerObjectRegistryData( const WCLSID & clsid, WOleServerObjectRegistryDataBlock * );
  64.         ~WOleServerObjectRegistryData( void );
  65.  
  66.         // Self Registration
  67.         WBool Register( WApplication *application );
  68.         WBool Unregister( void );
  69.  
  70.         WCLSID                             _classID;
  71.         WOleServerObjectRegistryDataBlock *_registryDataBlock;
  72.  
  73.         WOleServerObjectRegistryData        *next;
  74.         static WOleServerObjectRegistryData *Head;
  75. };
  76.  
  77. // QueryInterface event data structure
  78. struct WQueryInterfaceEventData : public WEventData {
  79.     WCLSID      wclsid;
  80.     WPIUnknown  pIUnknown;
  81. };
  82.  
  83. // the following is definitions of WOleServerObject
  84.  
  85. class WCMCLASS WOleServerObject : public WEventGenerator {
  86.     WDeclareSubclass( WOleServerObject, WEventGenerator );
  87.  
  88.     friend class WOleServerObject_IUnk;
  89.  
  90.     public:
  91.  
  92.         /**********************************************************
  93.          * Constructors and Destructors
  94.          *********************************************************/
  95.  
  96.         WOleServerObject();
  97.         virtual ~WOleServerObject();
  98.  
  99.         WBool Create( WOleClassManager * );
  100.         WBool Destroy( void );
  101.  
  102.     public:
  103.  
  104.         /**************************************************************
  105.          * Properties
  106.          **************************************************************/
  107.  
  108.         // Prog ID
  109.         WString GetProgID( void ) const;
  110.  
  111.         // Version Independent Prog ID
  112.         WString GetVersionIndependentProgID( void ) const;
  113.  
  114.         // Version Major
  115.         WInt GetVersionMajor( void ) const;
  116.  
  117.         // Version Minor
  118.         WInt GetVersionMinor( void ) const;
  119.  
  120.         // Application Full Name
  121.         WString GetApplicationFullName( void ) const;
  122.  
  123.         // Application Short Name ( 15 chars max )
  124.         WString GetApplicationShortName( void ) const;
  125.  
  126.         // IsInsertable
  127.         WBool GetIsInsertable( void ) const;
  128.  
  129.         // IsOleControl
  130.         WBool GetIsOleControl( void ) const;
  131.  
  132.         // IUknown interface
  133.         WPIUnknown GetIUnknown( WBool addRef=TRUE ) const;
  134.  
  135.         /**************************************************************
  136.          * Static Methods
  137.          **************************************************************/
  138.  
  139.         // Self Registration
  140.         static WBool Register( WApplication *application );
  141.         static WBool Unregister( void );
  142.  
  143.         /**************************************************************
  144.          * Methods
  145.          **************************************************************/
  146.  
  147.         // Add an Interface Family
  148.         WBool AddInterfaceFamily( WOleInterfaceFamily *interfaceFamily );
  149.  
  150.         // Specify RegistryData
  151.         WBool SetRegistryData( WOleServerObjectRegistryData * );
  152.         WOleServerObjectRegistryData *GetRegistryData( void ) const;
  153.  
  154.         // Reference counting
  155.         WULong AddRef( void );
  156.         WULong Release( void );
  157.  
  158.         // Get the servers WCLSID
  159.         virtual WCLSID OleClassID( void );
  160.  
  161.         /**************************************************************
  162.          * Internal Methods
  163.          **************************************************************/
  164.  
  165.         WBool SetUnkOuter( WPIUnknown pUnkOuter );
  166.  
  167.     protected:
  168.  
  169.         WBool QueryInterfaceFamilies( const WCLSID & clsid, void **iface );
  170.  
  171.     /**********************************************************
  172.      * Data Members
  173.      *********************************************************/
  174.     
  175.     protected:
  176.         WULong                          _refCount;
  177.         WPIUnknown                      _pUnkOuter;
  178.         WOleServerObject_IUnk           *_iunknown;
  179.         wllist_header                   *_ifamilyList;
  180.         WOleClassManager                *_classManager;
  181.         WOleServerObjectRegistryData    *_registryData;
  182.  
  183. };
  184.  
  185. class WCMCLASS WOleServerObjectListEntry {
  186.     public:
  187.         WOleServerObjectListEntry( pfnOleSvrCreateInst pfn, const WCLSID & clsid );
  188.         ~WOleServerObjectListEntry( void );
  189.  
  190.         pfnOleSvrCreateInst             fnCreateInst;
  191.         WCLSID                          classID;
  192.         WOleServerObjectListEntry       *next;
  193.         static WOleServerObjectListEntry *Head;
  194. };
  195.  
  196. #define WOleDeclareServerObjectClassID()                                \
  197.     public:                                                             \
  198.         static WCLSID _oleClassID;                                      \
  199.         virtual WCLSID OleClassID( void ) { return( _oleClassID ); };
  200.  
  201. #define WOleDefineServerObjectClassID( c, c_id )                        \
  202.     WCLSID c::_oleClassID = c_id;
  203.  
  204. #define WOleDeclareServerObject( c, c_id )                              \
  205.     WOleDeclareServerObjectClassID();                                   \
  206.     protected:                                                          \
  207.         WOleServerObjectListEntry *_serverObjectListEntry;              \
  208.     public:                                                             \
  209.         static WOleServerObject *CreateInstance( WPIUnknown pUnkOuter );
  210.  
  211. #define WOleDefineServerObject( c, c_id, rdb )                          \
  212.     WOleDefineServerObjectClassID( c, c_id );                           \
  213.     static WOleServerObjectRegistryData _WOleSvrRegistryData( c_id, &rdb );\
  214.     static WOleServerObjectListEntry _WOleSvrListEntry( (pfnOleSvrCreateInst)c::CreateInstance, c_id );\
  215.     static WOleServerObject *                                           \
  216.     c::CreateInstance( WPIUnknown pUnkOuter ) {                         \
  217.         c *obj = new c();                                               \
  218.         if( obj ) {                                                     \
  219.             obj->SetUnkOuter( pUnkOuter );                              \
  220.             obj->SetRegistryData( &_WOleSvrRegistryData );              \
  221.         }                                                               \
  222.         return( obj );                                                  \
  223.     }
  224.  
  225. #ifndef _WNO_PRAGMA_PUSH
  226. #pragma enum pop;
  227. #pragma pack(pop);
  228. #endif
  229.  
  230. #endif // _WOLESOBJ_HPP_INCLUDED
  231.  
  232.