資源簡介
這是從別人那里copy來的,對于第一次使用vs的c++來開發的新手,可以借鑒學習一下。基本能用。win7注冊組件的時候注意一下權限問題。

代碼片段和文件信息
#include?“stdafx.h“
#include?se.h>
#include?
using?namespace?std;
#include?“CMPNT.h“
void?trace(const?char*?msg)?{?cout<
CA::CA()?:?m_cRef(1)
{
InterlockedIncrement(&g_cComponents);
}
CA::~CA()
{
InterlockedDecrement(&g_cComponents);
}
HRESULT?_stdcall?CA::QueryInterface(const?IID&?iid?void**?ppv)
{
if?(iid?==?IID_IUnknown)
{
*ppv?=?static_cast(this);
}
else?if?(iid?==?IID_IX)
{
*ppv?=?static_cast(this);
trace(“Components:\t\tReturn?pointer?to?IX.“);
}
else?if?(iid?==?IID_IY)
{
*ppv?=?static_cast(this);
trace(“Components:\t\tReturn?pointer?to?IY.“);
}
else
{
*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;
}
HRESULT?_stdcall?CFactory::QueryInterface(const?IID&?iid?void**?ppv)
{
if?((iid?==?IID_IUnknown)?||?(iid?==?IID_IClassFactory))
{
*ppv?=?static_cast(this);
}
else
{
*ppv?=?NULL;
return?E_NOINTERFACE;
}
reinterpret_cast(*ppv)->AddRef();
return?S_OK;
}
ULONG?_stdcall?CFactory::AddRef()
{
return?InterlockedIncrement(&m_cRef);
}
ULONG?_stdcall?CFactory::Release()
{
if?(InterlockedDecrement(&m_cRef)?==?0)
{
delete?this;
return?0;
}
return?m_cRef;
}
HRESULT?_stdcall?CFactory::CreateInstance(IUnknown*?pUnknownOuter?const?IID&?iid?void**?ppv)
{
trace(“Class?factory:\t\tCreate?component.“);
if?(pUnknownOuter?!=?NULL)
{
return?CLASS_E_NOAGGREGATION;
}
CA?*?pCA?=?new?CA;
if?(pCA?==?NULL)
{
return?E_OUTOFMEMORY;
}
HRESULT?hr?=?pCA->QueryInterface(iid?ppv);
pCA->Release();
return?hr;
}
HRESULT?_stdcall?CFactory::LockServer(BOOL?bLock)
{
if?(bLock)
{
InterlockedIncrement(&g_cServerLocks);
}
else
{
InterlockedDecrement(&g_cServerLocks);
}
return?S_OK;
}
CFactory::~CFactory()
{
trace(“Class?factory:\t\tDestory?self.“);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2011-07-04?17:16??Com\
?????目錄???????????0??2011-07-04?17:15??Com\ComImplementation\
?????目錄???????????0??2011-07-04?17:15??Com\ComImplementation\ComImplementation\
?????文件????????2154??2011-06-20?16:52??Com\ComImplementation\ComImplementation\CMPNT.cpp
?????文件????????1098??2011-07-04?17:00??Com\ComImplementation\ComImplementation\CMPNT.h
?????文件????????1161??2011-07-04?17:00??Com\ComImplementation\ComImplementation\ComImplementation.cpp
?????文件?????????162??2011-07-04?16:57??Com\ComImplementation\ComImplementation\ComImplementation.def
?????文件????????5124??2011-07-04?16:57??Com\ComImplementation\ComImplementation\ComImplementation.vcproj
?????文件????????1383??2011-07-04?17:09??Com\ComImplementation\ComImplementation\ComImplementation.vcproj.ZCH-PC.ZCH.user
?????文件?????????705??2011-07-04?17:04??Com\ComImplementation\ComImplementation\GUIDS.cpp
?????文件?????????345??2011-06-20?15:22??Com\ComImplementation\ComImplementation\IFace.h
?????文件????????1289??2011-07-04?16:54??Com\ComImplementation\ComImplementation\ReadMe.txt
?????文件????????4933??2011-07-04?16:43??Com\ComImplementation\ComImplementation\Register.cpp
?????文件?????????505??2011-06-24?10:42??Com\ComImplementation\ComImplementation\Register.h
?????文件?????????222??2011-07-04?16:54??Com\ComImplementation\ComImplementation\stdafx.cpp
?????文件????????1049??2011-07-04?16:54??Com\ComImplementation\ComImplementation\stdafx.h
?????文件?????5852160??2011-07-04?17:09??Com\ComImplementation\ComImplementation.ncb
?????文件?????????916??2011-07-04?16:54??Com\ComImplementation\ComImplementation.sln
?????文件???????15360??2011-07-04?17:09??Com\ComImplementation\ComImplementation.suo
?????目錄???????????0??2011-07-04?17:14??Com\ComTest\
?????目錄???????????0??2011-07-04?17:15??Com\ComTest\ComTest\
?????文件?????????313??2011-07-04?17:12??Com\ComTest\ComTest\ComTest.cpp
?????文件????????4091??2011-07-04?17:12??Com\ComTest\ComTest\ComTest.vcproj
?????文件????????1409??2011-07-04?17:14??Com\ComTest\ComTest\ComTest.vcproj.ZCH-PC.ZCH.user
?????文件?????????684??2011-07-04?17:13??Com\ComTest\ComTest\GUIDS.cpp
?????文件?????????345??2011-06-20?15:22??Com\ComTest\ComTest\IFace.h
?????文件????10144768??2011-07-04?17:14??Com\ComTest\ComTest.ncb
?????文件?????????886??2011-07-04?17:10??Com\ComTest\ComTest.sln
?????文件???????10752??2011-07-04?17:14??Com\ComTest\ComTest.suo
評論
共有 條評論