📄 factory.cpp
字号:
return cRefs;
}
/*---------------------------------------------------------------------------
CFBall's nested implementation of the IClassFactory interface
including Constructor, Destructor, QueryInterface, AddRef, Release,
CreateInstance, and LockServer methods.
---------------------------------------------------------------------------*/
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::CImpIClassFactory
Summary: Constructor for the CImpIClassFactory interface instantiation.
Args: CFBall* pBackObj,
Back pointer to the parent outer object.
IUnknown* pUnkOuter,
Pointer to the outer Unknown. For delegation.
CServer* pServer)
Pointer to the server's control object.
Modifies: m_pBackObj, m_pUnkOuter, m_pServer.
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
CFBall::CImpIClassFactory::CImpIClassFactory(
CFBall* pBackObj,
IUnknown* pUnkOuter,
CServer* pServer)
{
// Init the Back Object Pointer to point to the parent object.
m_pBackObj = pBackObj;
// Init the pointer to the server control object.
m_pServer = pServer;
// Init the CImpIClassFactory interface's delegating Unknown pointer.
// We use the Back Object pointer for IUnknown delegation here if we are
// not being aggregated. If we are being aggregated we use the supplied
// pUnkOuter for IUnknown delegation. In either case the pointer
// assignment requires no AddRef because the CImpIClassFactory lifetime is
// quaranteed by the lifetime of the parent object in which
// CImpIClassFactory is nested.
if (NULL == pUnkOuter)
m_pUnkOuter = pBackObj;
else
m_pUnkOuter = pUnkOuter;
return;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::~CImpIClassFactory
Summary: Destructor for the CImpIClassFactory interface instantiation.
Args: void
Modifies: .
Returns: void
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
CFBall::CImpIClassFactory::~CImpIClassFactory(void)
{
return;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::QueryInterface
Summary: The QueryInterface IUnknown member of this IClassFactory
interface implementation that delegates to m_pUnkOuter,
whatever it is.
Args: REFIID riid,
[in] GUID of the Interface being requested.
PPVOID ppv)
[out] Address of the caller's pointer variable that will
receive the requested interface pointer.
Modifies: .
Returns: HRESULT
Returned by the delegated outer QueryInterface call.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP CFBall::CImpIClassFactory::QueryInterface(
REFIID riid,
PPVOID ppv)
{
// Delegate this call to the outer object's QueryInterface.
return m_pUnkOuter->QueryInterface(riid, ppv);
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::AddRef
Summary: The AddRef IUnknown member of this IClassFactory interface
implementation that delegates to m_pUnkOuter, whatever it is.
Args: void
Modifies: .
Returns: ULONG
Returned by the delegated outer AddRef call.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP_(ULONG) CFBall::CImpIClassFactory::AddRef(void)
{
// Delegate this call to the outer object's AddRef.
return m_pUnkOuter->AddRef();
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::Release
Summary: The Release IUnknown member of this IClassFactory interface
implementation that delegates to m_pUnkOuter, whatever it is.
Args: void
Modifies: .
Returns: ULONG
Returned by the delegated outer Release call.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP_(ULONG) CFBall::CImpIClassFactory::Release(void)
{
// Delegate this call to the outer object's Release.
return m_pUnkOuter->Release();
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::CreateInstance
Summary: The CreateInstance member method of this IClassFactory
interface implementation. Creates an instance of the COBall
COM component.
Args: IUnknown* pUnkOuter,
[in] Pointer to the controlling IUnknown.
REFIID riid,
[in] GUID of the Interface being requested.
PPVOID ppvCob)
[out] Address of the caller's pointer variable that will
receive the requested interface pointer.
Modifies: .
Returns: HRESULT
Standard OLE result code.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP CFBall::CImpIClassFactory::CreateInstance(
IUnknown* pUnkOuter,
REFIID riid,
PPVOID ppv)
{
HRESULT hr = E_FAIL;
COBall* pCob = NULL;
// NULL the output pointer.
*ppv = NULL;
// If the creation call is requesting aggregation (pUnkOuter != NULL),
// the COM rules state the IUnknown interface MUST also be concomitantly
// be requested. If it is not so requested (riid != IID_IUnknown) then
// an error must be returned indicating that no aggregate creation of
// the CFBall COM Object can be performed.
if (NULL != pUnkOuter && riid != IID_IUnknown)
hr = CLASS_E_NOAGGREGATION;
else
{
// Instantiate a COBall COM Object.
pCob = new COBall(pUnkOuter, m_pServer);
if (NULL != pCob)
{
// We initially created the new COM object so tell the server
// to increment its global server object count to help ensure
// that the server remains loaded until this partial creation
// of a COM component is completed.
m_pServer->ObjectsUp();
// We QueryInterface this new COM Object not only to deposit the
// main interface pointer to the caller's pointer variable, but to
// also automatically bump the Reference Count on the new COM
// Object after handing out this reference to it.
hr = pCob->QueryInterface(riid, (PPVOID)ppv);
if (FAILED(hr))
{
m_pServer->ObjectsDown();
delete pCob;
}
}
else
hr = E_OUTOFMEMORY;
}
return hr;
}
/*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
Method: CFBall::CImpIClassFactory::LockServer
Summary: The LockServer member method of this IClassFactory interface
implementation.
Args: BOOL fLock)
[in] Flag determining whether to Lock or Unlock the server.
Modifies: .
Returns: HRESULT
Standard OLE result code.
M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
STDMETHODIMP CFBall::CImpIClassFactory::LockServer(
BOOL fLock)
{
HRESULT hr = NOERROR;
if (fLock)
m_pServer->Lock();
else
m_pServer->Unlock();
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -