CLSFACT.CPP
资源名称:MSDN_VC98.zip [点击查看]
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:5k
源码类别:
Windows编程
开发平台:
Visual C++
- /**************************************************************************
- THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
- ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- PARTICULAR PURPOSE.
- Copyright 1997 Microsoft Corporation. All Rights Reserved.
- **************************************************************************/
- /**************************************************************************
- File: ClsFact.cpp
- Description: CClassFactory implementation
- **************************************************************************/
- /**************************************************************************
- #include statements
- **************************************************************************/
- #include "ClsFact.h"
- /**************************************************************************
- global variables
- **************************************************************************/
- extern DWORD g_DllRefCount;
- /**************************************************************************
- CClassFactory::CClassFactory
- **************************************************************************/
- CClassFactory::CClassFactory()
- {
- OutputDebugString(TEXT("CClassFactory's constructorn"));
- m_ObjRefCount = 0;
- }
- /**************************************************************************
- CClassFactory::~CClassFactory
- **************************************************************************/
- CClassFactory::~CClassFactory()
- {
- OutputDebugString(TEXT("CClassFactory's destructorn"));
- }
- /**************************************************************************
- CClassFactory::QueryInterface
- **************************************************************************/
- STDMETHODIMP CClassFactory::QueryInterface( REFIID riid,
- LPVOID *ppReturn)
- {
- OutputDebugString(TEXT("CClassFactory::QueryInterfacen"));
- if(IsEqualIID(riid, IID_IUnknown))
- {
- *ppReturn = (LPUNKNOWN)(LPCLASSFACTORY)this;
- m_ObjRefCount++;
- return ResultFromScode(S_OK);
- }
- if(IsEqualIID(riid, IID_IClassFactory))
- {
- *ppReturn = (LPCLASSFACTORY)this;
- m_ObjRefCount++;
- return ResultFromScode(S_OK);
- }
- *ppReturn = NULL;
- return ResultFromScode(E_NOINTERFACE);
- }
- /**************************************************************************
- CClassFactory::AddRef
- **************************************************************************/
- STDMETHODIMP_(DWORD) CClassFactory::AddRef()
- {
- OutputDebugString(TEXT("CClassFactory::AddRefn"));
- return ++m_ObjRefCount;
- }
- /**************************************************************************
- CClassFactory::Release
- **************************************************************************/
- STDMETHODIMP_(DWORD) CClassFactory::Release()
- {
- TCHAR szText[MAX_PATH];
- wsprintf(szText, TEXT("CClassFactory::Release - ref count will be %dn"), m_ObjRefCount - 1);
- OutputDebugString(szText);
- if(--m_ObjRefCount == 0)
- delete this;
- return m_ObjRefCount;
- }
- /**************************************************************************
- CClassFactory::CreateInstance
- **************************************************************************/
- STDMETHODIMP CClassFactory::CreateInstance( LPUNKNOWN pUnknown,
- REFIID riid,
- LPVOID *ppObject)
- {
- OutputDebugString(TEXT("CClassFactory::CreateInstancen"));
- *ppObject = NULL;
- if(pUnknown != NULL)
- return ResultFromScode(CLASS_E_NOAGGREGATION);
- COleDocument *pOleDoc = new COleDocument;
- if(NULL == pOleDoc)
- return ResultFromScode(E_OUTOFMEMORY);
- //get the QueryInterface return for our return value
- HRESULT hr = pOleDoc->QueryInterface(riid, ppObject);
- //return the result from QueryInterface
- return hr;
- }
- /**************************************************************************
- CClassFactory::LockServer
- **************************************************************************/
- STDMETHODIMP CClassFactory::LockServer(BOOL fLock)
- {
- OutputDebugString(TEXT("CClassFactory::LockServer - "));
- if(fLock)
- {
- OutputDebugString(TEXT("Lockn"));
- g_DllRefCount++;
- }
- else
- {
- OutputDebugString(TEXT("Unlockn"));
- g_DllRefCount--;
- }
- return S_OK;
- }