home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n12 / oleq1295.exe / COQUUX2.CPP < prev    next >
C/C++ Source or Header  |  1995-12-01  |  3KB  |  122 lines

  1. /////////////////////////////////////////////
  2. //
  3. // CoQuux2.cpp - an implementation of a dual-interface
  4. //
  5.  
  6. #include <windows.h>
  7.  
  8. // bring in ODL generated header
  9. #include "CoQuux2.h"
  10.  
  11. LPCOLESTR szTypeLibName = OLESTR("CoQuux2.tlb");
  12.  
  13. class CoQuux2 :  public DIQuux // ->IDispatch->IUnknown
  14. {
  15.     ULONG   m_cRef;
  16.     short   m_sum;
  17.     static ITypeInfo *s_pTypeInfo;
  18. public:
  19.  
  20. // ctor/dtor
  21.     CoQuux2() 
  22.     :  m_cRef(0), m_sum(0) 
  23.     {
  24.         if (s_pTypeInfo != 0)
  25.             return;
  26.  
  27. // load the type info to implement IDispatch members
  28.         ITypeLib *ptl;
  29.         if (SUCCEEDED(LoadTypeLib(szTypeLibName, &ptl))) {
  30.             ptl->GetTypeInfoOfGuid(IID_IQuuxLogical, &s_pTypeInfo);
  31.             ptl->Release();            
  32.         }
  33.     }
  34.  
  35.     virtual ~CoQuux2() {  }
  36.  
  37. // IUnknown methods
  38.     STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv) {
  39.         if (riid==IID_IUnknown || riid==IID_IDispatch || riid==IID_DIQuux)
  40.             *ppv = (DIQuux *)this;
  41.         else
  42.             *ppv = 0;
  43.         if (*ppv)
  44.             AddRef();
  45.         return *ppv ? S_OK : E_NOINTERFACE;
  46.     }
  47.  
  48.     STDMETHODIMP_(ULONG) AddRef() {
  49.         return ++m_cRef;
  50.     }
  51.  
  52.     STDMETHODIMP_(ULONG) Release() {
  53.         ULONG result = --m_cRef;
  54.         if (!result)
  55.             delete this;
  56.         return result;
  57.     }
  58.  
  59. // IDispatch methods
  60.     STDMETHODIMP GetTypeInfoCount(UINT FAR* pctinfo) {
  61.         *pctinfo = s_pTypeInfo ? 1 : 0;
  62.         return NOERROR;
  63.     }
  64.  
  65.     STDMETHODIMP GetTypeInfo( UINT itinfo,  LCID lcid,
  66.                               ITypeInfo FAR* FAR* pptinfo) {
  67.         *pptinfo = 0;
  68.         if (itinfo != 0)
  69.             return E_INVALIDARG;
  70.         else if (s_pTypeInfo == 0)
  71.             return E_NOTIMPL;
  72.         
  73.         (*pptinfo = s_pTypeInfo)->AddRef();
  74.         return NOERROR;
  75.     }
  76.  
  77.     STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR * * rgszNames,
  78.                                UINT cNames, LCID lcid, 
  79.                                DISPID * rgdispid) {
  80.         if (s_pTypeInfo == 0)
  81.             return E_NOTIMPL;
  82.         return s_pTypeInfo->GetIDsOfNames(rgszNames, cNames, rgdispid);
  83.     }
  84.  
  85. // forward invoke to the type info object, providing an implementation
  86. // of the logical interface as the first paramter
  87.     STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  88.                         WORD wFlags, DISPPARAMS FAR* pdispparams,
  89.                         VARIANT FAR* pvarResult, 
  90.                         EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr) {
  91.         if (s_pTypeInfo == 0)
  92.             return E_NOTIMPL;
  93.         return s_pTypeInfo->Invoke((DIQuux*)this, dispidMember, wFlags, 
  94.                                     pdispparams, pvarResult, 
  95.                                     pexcepinfo, puArgErr);
  96.     }
  97.  
  98. // DIQuux methods 
  99.     STDMETHODIMP Dialog(short arg1)  {
  100.       m_sum += arg1;
  101.       return NOERROR;
  102.     }
  103.  
  104.     STDMETHODIMP Dissension(short *pResult)  {
  105.       *pResult = m_sum;
  106.       return NOERROR;
  107.     }
  108.  
  109.     STDMETHODIMP Debate(short arg1)  {
  110.       m_sum *= arg1;
  111.       return NOERROR;
  112.     }
  113.  
  114.     STDMETHODIMP Diatribe(short arg1)  {
  115.       m_sum -= arg1;
  116.       return NOERROR;
  117.     }
  118. };
  119.  
  120. // give the type info pointer linkage
  121. ITypeInfo *CoQuux::s_pTypeInfo;
  122.