home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activexcontrol / basectl / include / autoobj.h next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  6.5 KB  |  153 lines

  1. //=--------------------------------------------------------------------------=
  2. // AutoObj.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1995-1997 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // all of our objects will inherit from this class to share as much of the same
  13. // code as possible.  this super-class contains the unknown and dispatch
  14. // implementations for them.
  15. //
  16. #ifndef _AUTOOBJ_H_
  17.  
  18. // all automation objects will use the Unknown object that supports aggegation.
  19. //
  20. #include "Unknown.H"
  21.  
  22. //=--------------------------------------------------------------------------=
  23. // the constants in this header file uniquely identify your automation objects.
  24. // make sure that for each object you have in the g_ObjectInfo table, you have
  25. // a constant in this header file.
  26. //
  27. #include "LocalSrv.H"
  28. #include "extobj.h"
  29.  
  30. //=--------------------------------------------------------------------------=
  31. // AUTOMATIONOBJECTINFO
  32. //=--------------------------------------------------------------------------=
  33. // for each automation object type you wish to expose to the programmer/user
  34. // that is not a control, you must fill out one of these structures.  if the
  35. // object isn't CoCreatable, then the first four fields should be empty.
  36. // otherwise, they should be filled in with the appropriate information.
  37. // use the macro DEFINE_AUTOMATIONOBJECT to both declare and define your object.
  38. // make sure you have an entry in the global table of objects, g_ObjectInfo
  39. // in the main .Cpp file for your InProc server.
  40. //
  41. typedef struct {
  42.  
  43.     UNKNOWNOBJECTINFO unknowninfo;               // fill in with 0's if we're not CoCreatable
  44.     long         lVersion;                       // Version number of Object.  ONLY USE IF YOU'RE CoCreatable!
  45.     const IID   *riid;                           // object's type
  46.     LPCSTR       pszHelpFile;                    // the helpfile for this automation object.
  47.     ITypeInfo   *pTypeInfo;                      // typeinfo for this object
  48.     UINT         cTypeInfo;                      // number of refs to the type info
  49.  
  50. } AUTOMATIONOBJECTINFO;
  51.  
  52. // macros to manipulate the AUTOMATIONOBJECTINFO in the global table table.
  53. //
  54. #define VERSIONOFOBJECT(index)         ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->lVersion
  55. #define INTERFACEOFOBJECT(index)       *(((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->riid)
  56. #define PPTYPEINFOOFOBJECT(index)      &((((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo))
  57. #define PTYPEINFOOFOBJECT(index)       ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo
  58. #define CTYPEINFOOFOBJECT(index)       ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->cTypeInfo
  59. #define HELPFILEOFOBJECT(index)        ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pszHelpFile
  60.  
  61.  
  62. #ifndef INITOBJECTS
  63.  
  64. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  65. extern AUTOMATIONOBJECTINFO name##Object \
  66.  
  67. #else
  68. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  69.     AUTOMATIONOBJECTINFO name##Object = { { clsid, objname, fn }, ver, riid, pszh, NULL, 0} \
  70.  
  71. #endif // INITOBJECTS
  72.  
  73. //=--------------------------------------------------------------------------=
  74. // Standard Dispatch and SupportErrorInfo
  75. //=--------------------------------------------------------------------------=
  76. // all objects should declare these in their class definitions so that they
  77. // get standard implementations of IDispatch and ISupportErrorInfo.
  78. //
  79. #define DECLARE_STANDARD_DISPATCH() \
  80.     STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { \
  81.         return CAutomationObject::GetTypeInfoCount(pctinfo); \
  82.     } \
  83.     STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **ppTypeInfoOut) { \
  84.         return CAutomationObject::GetTypeInfo(itinfo, lcid, ppTypeInfoOut); \
  85.     } \
  86.     STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR **rgszNames, UINT cnames, LCID lcid, DISPID *rgdispid) { \
  87.         return CAutomationObject::GetIDsOfNames(riid, rgszNames, cnames, lcid, rgdispid); \
  88.     } \
  89.     STDMETHOD(Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pVarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) { \
  90.         return CAutomationObject::Invoke(dispid, riid, lcid, wFlags, pdispparams, pVarResult, pexcepinfo, puArgErr); \
  91.     } \
  92.  
  93.  
  94. #define DECLARE_STANDARD_SUPPORTERRORINFO() \
  95.     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid) { \
  96.         return CAutomationObject::InterfaceSupportsErrorInfo(riid); \
  97.     } \
  98.  
  99. enum {EXPANDO_DISABLED=FALSE, EXPANDO_ENABLED=TRUE};
  100.  
  101. //=--------------------------------------------------------------------------=
  102. // CAutomationObject
  103. //=--------------------------------------------------------------------------=
  104. // global class that all automation objects can inherit from to give them a
  105. // bunch of implementation for free, namely IDispatch and ISupportsErrorInfo
  106. //
  107. //
  108. class CAutomationObject : public CUnknownObject {
  109.  
  110.   public:
  111.     // aggreation query interface support
  112.     //
  113.     virtual HRESULT InternalQueryInterface(REFIID riid, void **ppvObjOut);
  114.  
  115.     // IDispatch methods
  116.     //
  117.     STDMETHOD(GetTypeInfoCount)(UINT *);
  118.     STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo **);
  119.     STDMETHOD(GetIDsOfNames)(REFIID, OLECHAR **, UINT, LCID, DISPID *);
  120.     STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  121.  
  122.     //  ISupportErrorInfo methods
  123.     //
  124.     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID);
  125.  
  126.     CAutomationObject(IUnknown *, int , void *, BOOL fExpandoEnabled=FALSE);
  127.     virtual ~CAutomationObject();
  128.  
  129.     // callable functions -- things that most people will find useful.
  130.     //
  131.     virtual HINSTANCE GetResourceHandle(void);
  132.     HRESULT Exception(HRESULT hr, WORD idException, DWORD dwHelpContextID);
  133.  
  134.   protected:
  135.     // member variables that derived objects might need to get at information in the
  136.     // global object table
  137.     //
  138.     int   m_ObjectType;
  139.  
  140.   private:
  141.     // member variables we don't share.
  142.     //
  143.     BYTE  m_fLoadedTypeInfo;
  144.     BYTE  m_fExpandoEnabled;
  145.     CExpandoObject* m_pexpando;
  146. };
  147.  
  148.  
  149. #define _AUTOOBJ_H_
  150. #endif // _AUTOOBJ_H_
  151.  
  152.  
  153.