home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / internet / scripting / spruuids / oleauto.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  5.8 KB  |  109 lines

  1. //---------------------------------------------------------------------------
  2. // OleAuto.h
  3. //---------------------------------------------------------------------------
  4. // Simple class for doing dual OLE Automation interfaces
  5. //---------------------------------------------------------------------------
  6. // (C) Copyright 1992-1997 by Microsoft Corporation.  All rights reserved.
  7. //
  8. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  9. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  10. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  11. // PARTICULAR PURPOSE.
  12. //---------------------------------------------------------------------------
  13.  
  14. //---------------------------------------------------------------------------
  15. // A little utility which simplifies firing dispatch events.
  16. //---------------------------------------------------------------------------
  17. HRESULT InvokeEvent
  18.   (
  19.   IDispatch  *pdisp,    // IDispatch of Sink
  20.   DISPID      dispid,   // DISPID of event
  21.   VARIANTARG *pvararg,  // Args to event
  22.   UINT        carg      // # args
  23.   );
  24.  
  25.  
  26. //---------------------------------------------------------------------------
  27. // This routine will load a TypeLib and (optionally) find the TypeInfo inside
  28. // which matches the given clsid.  The TypeLib and TypeInfo pointers are
  29. // in/out so you can simply:
  30. //      hr = LoadTypeInfo(..., &g_pMyTypeLib, &m_pMyObjectsTypeInfo);
  31. // and it will fill in g_pMyTypeLib and m_pMyObjectsTypeInfo, if necessary.
  32. //---------------------------------------------------------------------------
  33. HRESULT LoadTypeInfo
  34.   (
  35.   HINSTANCE   hinst,             // hinst of where to load TypeLib from, if not found
  36.   UINT        itinfo,            // index of TypeInfo requested, only 0 supported
  37.   USHORT      dwMaj,             // Maj version # of TypeLib
  38.   USHORT      dwMin,             // Min version # of TypeLib
  39.   LCID        lcid,              // Locale of TypeLib to load
  40.   REFGUID     libid,             // LIBID of TypeLib  to find
  41.   REFCLSID    clsid,             // CLSID of TypeInfo to find
  42.   REFIID      iid,               // IID   of TypeInfo to find
  43.   BOOL        fDispOnly,         // TRUE=ensure *ptinfoIntInOut is a TKIND_DISPATCH, not vtbl
  44.   ITypeLib  **pptlibInOut,       // Ptr to cache of pTypeLib, typically &g_ptlib
  45.   ITypeInfo **pptinfoClassInOut, // Ptr to cache of pTypeInfo, typically &m_ptinfoCls
  46.   ITypeInfo **pptinfoIntInOut    // Ptr to cache of pTypeInfo, typically &m_ptinfoInt
  47.   );
  48.  
  49.  
  50. //---------------------------------------------------------------------------
  51. // Derrive from this class to get the standard implementation of IDispatch
  52. // over a vtable.  Assumes that "this" is the proper vtable, so to use, your
  53. // class should first derive from IMyCustomDualInterface, then from COleAuto.
  54. // Then implement GetTypeLibInfo().
  55. //---------------------------------------------------------------------------
  56. class COleAuto : public IDispatch
  57.   {
  58. public:
  59.   // *** IUnknown methods ***
  60.   STDMETHOD(QueryInterface)(REFIID riid, void** ppvObj) PURE;
  61.   STDMETHOD_(ULONG, AddRef)(void) PURE;
  62.   STDMETHOD_(ULONG, Release)(void) PURE;
  63.  
  64.   // *** IDispatch methods ***
  65.   STDMETHOD(GetTypeInfoCount)(UINT* pctinfo);
  66.   STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfoOut);
  67.   STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR** rgszNames, UINT cNames, LCID lcid, DISPID* prgdispid);
  68.   STDMETHOD(Invoke)(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr);
  69.  
  70.   // *** IProvideMultipleClassInfo methods ***
  71.   STDMETHOD(GetMultiTypeInfoCount)(ULONG *pc);
  72.   STDMETHOD(GetInfoOfIndex)(ULONG itinfo, DWORD dwFlags, ITypeInfo** pptinfoCoClass, DWORD* pdwTIFlags, ULONG* pcdispidReserved, IID* piidPrimary, IID* piidSource);
  73.  
  74.   // *** Pure virtual methods for derived class to implement ***
  75.   virtual ITypeInfo **GetTinfoClsAddr(void) PURE;
  76.   virtual ITypeInfo **GetTinfoIntAddr(void) PURE;
  77.   virtual HRESULT GetTypeLibInfo(HINSTANCE *phinstOut, const GUID **pplibidOut, 
  78.                                  SHORT *pwMajLibOut, SHORT *pwMinLibOut,
  79.                                  const CLSID **ppclsidOut, const IID **ppiidOut, 
  80.                                  ITypeLib ***ppptlOut) PURE;
  81.   virtual IDispatch *GetPrimary(void) PURE;
  82.  
  83.   // *** Other methods for derived class to call ***
  84.   HRESULT CheckTypeInfo(UINT itinfo, LCID lcid);
  85.   HRESULT SetBaseObject(IDispatch *pdisp);
  86.  
  87.   // Member Variables
  88.   IDispatch *m_pdispBaseObject;   // The object this class is extending
  89.   };
  90.  
  91.  
  92. //---------------------------------------------------------------------------
  93. // Standard Dispatch
  94. //---------------------------------------------------------------------------
  95. // All objects should declare these in their class definitions so that they
  96. // get standard implementations of IDispatch and ISupportErrorInfo.
  97. //---------------------------------------------------------------------------
  98. #define DECLARE_STANDARD_DISPATCH() \
  99.     STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) \
  100.       { return COleAuto::GetTypeInfoCount(pctinfo); } \
  101.     STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **pptinfoOut) \
  102.       { return COleAuto::GetTypeInfo(itinfo, lcid, pptinfoOut); } \
  103.     STDMETHOD(GetIDsOfNames)(REFIID iid, OLECHAR **rgszNames, UINT cnames, LCID lcid, DISPID *rgdispid) \
  104.       { return COleAuto::GetIDsOfNames(iid, rgszNames, cnames, lcid, rgdispid); } \
  105.     STDMETHOD(Invoke)(DISPID dispid, REFIID iid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pVarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) \
  106.       { return COleAuto::Invoke(dispid, iid, lcid, wFlags, pdispparams, pVarResult, pexcepinfo, puArgErr); }
  107.  
  108. //--- EOF -------------------------------------------------------------------
  109.