DEFINE_GUID(IID_IX,
0x32bb8320, 0xb41b, 0x11cf, 0xa6, 0xbb, 0x0, 0x80, 0xc7, 0xb2, 0xd6, 0x82);
______________________________________________________________________
"Iface.h"
#pragma once
#include
// Interfaces
interface IX : IUnknown
{
virtual void __stdcall Fx() = 0 ;
} ;
_______________________________________________________________________
"***.cpp"
#include "stdafx.h"
#include
#include "Iface.h"
#include
#include
#include "MyGuids.h"
using namespace std;
void trace(const char* msg) { cout << "Component 1:\t" << msg << endl ;}
//
// Component
//
class CA : public IX
{
// IUnknown implementation
virtual HRESULT __stdcall QueryInterface(const IID& iid, void** ppv) ;
virtual ULONG __stdcall AddRef() ;
virtual ULONG __stdcall Release() ;
// Interface IX implementation
virtual void __stdcall Fx() { cout << "Fx" << endl ;}
public:
// Constructor
CA() : m_cRef(0) {}
// Destructor
~CA() { trace("Destroy self.") ;}
private:
long m_cRef ;
} ;
HRESULT __stdcall CA::QueryInterface(const IID& iid, void** ppv)
{
if (iid == IID_IUnknown)
{
trace("Return pointer to IUnknown.") ;
*ppv = static_cast(this) ;
}
else if (iid == IID_IX)
{
trace("Return pointer to IX.") ;
*ppv = static_cast(this) ;
}
else
{
trace("Interface not supported.") ;
*ppv = NULL ;
return E_NOINTERFACE ;
}
reinterpret_cast(*ppv)->AddRef() ;
return S_OK ;
}
ULONG __stdcall CA::AddRef()
{
return InterlockedIncrement(&m_cRef) ;
}
ULONG __stdcall CA::Release()
{
if (InterlockedDecrement(&m_cRef) == 0)
{
delete this ;
return 0 ;
}
return m_cRef ;
}
//
// Creation function
//
extern "C" IUnknown* CreateInstance()
{
IUnknown* pI = static_cast(new CA) ;
pI->AddRef() ;
return pI ;
}
return pI ;
}
___________________________________________________________________________
"***.def"
LIBRARY Cmpnt1.dll
DESCRIPTION '(c)1996-1997 Dale E. Rogerson'
EXPORTS
CreateInstance @1 PRIVATE