home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Troubleshooting Netware Systems
/
CSTRIAL0196.BIN
/
attach
/
msj
/
v10n12
/
oleq1295.exe
/
COQUUX2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-01
|
3KB
|
122 lines
/////////////////////////////////////////////
//
// CoQuux2.cpp - an implementation of a dual-interface
//
#include <windows.h>
// bring in ODL generated header
#include "CoQuux2.h"
LPCOLESTR szTypeLibName = OLESTR("CoQuux2.tlb");
class CoQuux2 : public DIQuux // ->IDispatch->IUnknown
{
ULONG m_cRef;
short m_sum;
static ITypeInfo *s_pTypeInfo;
public:
// ctor/dtor
CoQuux2()
: m_cRef(0), m_sum(0)
{
if (s_pTypeInfo != 0)
return;
// load the type info to implement IDispatch members
ITypeLib *ptl;
if (SUCCEEDED(LoadTypeLib(szTypeLibName, &ptl))) {
ptl->GetTypeInfoOfGuid(IID_IQuuxLogical, &s_pTypeInfo);
ptl->Release();
}
}
virtual ~CoQuux2() { }
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR* ppv) {
if (riid==IID_IUnknown || riid==IID_IDispatch || riid==IID_DIQuux)
*ppv = (DIQuux *)this;
else
*ppv = 0;
if (*ppv)
AddRef();
return *ppv ? S_OK : E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) AddRef() {
return ++m_cRef;
}
STDMETHODIMP_(ULONG) Release() {
ULONG result = --m_cRef;
if (!result)
delete this;
return result;
}
// IDispatch methods
STDMETHODIMP GetTypeInfoCount(UINT FAR* pctinfo) {
*pctinfo = s_pTypeInfo ? 1 : 0;
return NOERROR;
}
STDMETHODIMP GetTypeInfo( UINT itinfo, LCID lcid,
ITypeInfo FAR* FAR* pptinfo) {
*pptinfo = 0;
if (itinfo != 0)
return E_INVALIDARG;
else if (s_pTypeInfo == 0)
return E_NOTIMPL;
(*pptinfo = s_pTypeInfo)->AddRef();
return NOERROR;
}
STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR * * rgszNames,
UINT cNames, LCID lcid,
DISPID * rgdispid) {
if (s_pTypeInfo == 0)
return E_NOTIMPL;
return s_pTypeInfo->GetIDsOfNames(rgszNames, cNames, rgdispid);
}
// forward invoke to the type info object, providing an implementation
// of the logical interface as the first paramter
STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
WORD wFlags, DISPPARAMS FAR* pdispparams,
VARIANT FAR* pvarResult,
EXCEPINFO FAR* pexcepinfo, UINT FAR* puArgErr) {
if (s_pTypeInfo == 0)
return E_NOTIMPL;
return s_pTypeInfo->Invoke((DIQuux*)this, dispidMember, wFlags,
pdispparams, pvarResult,
pexcepinfo, puArgErr);
}
// DIQuux methods
STDMETHODIMP Dialog(short arg1) {
m_sum += arg1;
return NOERROR;
}
STDMETHODIMP Dissension(short *pResult) {
*pResult = m_sum;
return NOERROR;
}
STDMETHODIMP Debate(short arg1) {
m_sum *= arg1;
return NOERROR;
}
STDMETHODIMP Diatribe(short arg1) {
m_sum -= arg1;
return NOERROR;
}
};
// give the type info pointer linkage
ITypeInfo *CoQuux::s_pTypeInfo;