ccomthread_src.zip
LegacyCOMObject1
LegacyCOMObject1.def
LegacyCOMObject1.dsp
LegacyCOMObject1.dsw
LegacyCOMObject1.rgs
LegacyCOMObject1.tlb
LegacyCOMObject1ps.def
LegacyCOMObject1ps.mk
Shared
SimpleCOMObject1
SimpleCOMObject1.def
SimpleCOMObject1.dsp
SimpleCOMObject1.dsw
SimpleCOMObject1.rgs
SimpleCOMObject1.tlb
SimpleCOMObject1ps.def
SimpleCOMObject1ps.mk
SimpleCOMObject2
SimpleCOMObject2.def
SimpleCOMObject2.dsp
SimpleCOMObject2.dsw
SimpleCOMObject2.rgs
SimpleCOMObject2.tlb
SimpleCOMObject2ps.def
SimpleCOMObject2ps.mk
Test Programs
VBTest
FormMain.frm
MSSCCPRJ.SCC
VBTest.exe
VBTest.vbp
VBTest.vbw
VCTests
DemonstrateDefaultSTA
VCTest01
SimpleCOMObject2.tlh
SimpleCOMObject2.tli
VCTest01.dsp
VCTest01.dsw
VCTest02
SimpleCOMObject2.tlh
SimpleCOMObject2.tli
VCTest02.dsp
VCTest02.dsw
DemonstrateExeServerSTA
Client
VCTest01
VCTest01.dsp
VCTest01.dsw
Implementation
ExeServerImpl
ExeServerImpl.dsp
ExeServerImpl.dsw
Interface
ExeServerInterfaces
ExeObj01.rgs
ExeObj02.rgs
ExeObj03.rgs
ExeServerInterfaces.def
ExeServerInterfaces.dsp
ExeServerInterfaces.dsw
ExeServerInterfaces.tlb
ExeServerInterfacesps.def
ExeServerInterfacesps.mk
DemonstrateLegacySTA
VCTest01
LegacyCOMObject1.tlh
LegacyCOMObject1.tli
VCTest01.dsp
VCTest01.dsw
VCTest02
VCTest02.dsp
VCTest02.dsw
DemonstrateNoMessageLoop
VCTest01
SimpleCOMObject2.tlh
SimpleCOMObject2.tli
VCTest01.dsp
VCTest01.dsw
DemonstrateSTA
VCTest01
SimpleCOMObject2.tlh
SimpleCOMObject2.tli
VCTest01.dsp
VCTest01.dsw
|
#include "refcountobj.h"
CReferenceCountedObject::CReferenceCountedObject() :
m_cRef(1)
{
// Increment the global count of objects.
InterlockedIncrement(&g_lObjsInUse);
}
CReferenceCountedObject::~CReferenceCountedObject()
{
// Decrement the global count of objects.
InterlockedDecrement(&g_lObjsInUse);
CClassFactory::AttemptToTerminateServer();
}
STDMETHODIMP CReferenceCountedObject::QueryInterface(REFIID riid, void** ppvObject)
{
if (riid == IID_IUnknown)
{
*ppvObject = (IUnknown*)this;
AddRef();
return S_OK;
}
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) CReferenceCountedObject::AddRef()
{
InterlockedIncrement(&m_cRef);
return m_cRef;
}
STDMETHODIMP_(ULONG) CReferenceCountedObject::Release()
{
InterlockedDecrement(&m_cRef);
if (m_cRef == 0)
{
delete this;
return 0;
}
return m_cRef;
}
CClassFactory::CClassFactory() :
m_cRef(1)
{
}
CClassFactory::~CClassFactory()
{
}
STDMETHODIMP CClassFactory::QueryInterface(REFIID riid, void** ppvObject)
{
if (riid == IID_IUnknown)
{
CReferenceCountedObject* pCReferenceCountedObject = (CReferenceCountedObject*)this;
*ppvObject = (IUnknown*)pCReferenceCountedObject;
((CReferenceCountedObject*)this) -> AddRef();
return S_OK;
}
if (riid == IID_IClassFactory)
{
*ppvObject = (IClassFactory*)this;
((CReferenceCountedObject*)this) -> AddRef();
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
STDMETHODIMP_(ULONG) CClassFactory::AddRef()
{
InterlockedIncrement(&m_cRef);
return m_cRef;
}
STDMETHODIMP_(ULONG) CClassFactory::Release()
{
InterlockedDecrement(&m_cRef);
if (m_cRef == 0)
{
delete this;
return 0;
}
return m_cRef;
}
// IClassFactory method.
STDMETHODIMP CClassFactory::CreateInstance
(
IUnknown __RPC_FAR *pUnkOuter,
REFIID riid,
void __RPC_FAR *__RPC_FAR *ppvObject
)
{
return E_NOTIMPL;
}
// IClassFactory method.
STDMETHODIMP CClassFactory::LockServer
(
BOOL fLock
)
{
if (fLock)
{
::InterlockedIncrement(&g_lServerLocks) ;
}
else
{
::InterlockedDecrement(&g_lServerLocks) ;
}
// If this is an out-of-proc server, check to see
// whether we should shut down.
AttemptToTerminateServer() ; //@local
return S_OK ;
}
// Shut down the application.
void CClassFactory::AttemptToTerminateServer()
{
if ((g_lObjsInUse > 0) || (g_lServerLocks > 0))
{
}
else
{
::PostThreadMessage(g_dwMainThreadID, WM_QUIT, 0, 0);
}
}
|
By viewing downloads associated with this article you agree to the Terms of use and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.