⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 classfactory.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////////////
//  File : ClassFactory.cpp
//
//  Copyright (C) 2002 PGP Corporation
//
//  ABSTRACT
//		Create and handle ClassFactory Object.
// 
//  Author: Satya S. Das
//
////////////////////////////////////////////////////////////////////////////////

// include files 
#include "windows.h"
#include <initguid.h>
#include <objbase.h>
#include <ole2.h>

#include "gwoapi.h"
#include "gwc3cmd.h"
#include "classfactory.h"
#include "pgpgwserver.h"
#include <crtdbg.h>
#include "pgpdebug.h"
#include "globals.h"
#include "util.h"

ULONG g_cObj=0;
ULONG g_cLock=0;

// public functions 

///////////////////////////////////////////////////////////////////
//  Name:PgpNwClsFactory::PgpNwClsFactory
//
//  Description:PgpNwClsFactory constructor. Set reference count to 1;
//
//  In:none
//
//  Out:none
//
//  Comments:
/////////////////////////////////////////////////////////////////////
PgpNwClsFactory::PgpNwClsFactory()
{
	PgpGwTrace("PgpNwClsFactory::PgpNwClsFactory\n");
	m_cRef=1;
}

///////////////////////////////////////////////////////////////////
//  Name:PgpNwClsFactory::~PgpNwClsFactory
//
//  Description:PgpNwClsFactory destructor. Incase you need to clean up.
//
//  In:none
//
//  Out:none
//
//  Comments:
///////////////////////////////////////////////////////////////////
PgpNwClsFactory::~PgpNwClsFactory()
{
	PgpGwTrace("PgpNwClsFactory::~PgpNwClsFactory\n");
}

///////////////////////////////////////////////////////////////////
//  Name:			PgpNwClsFactory::QueryInterface
//
//  Description:
//
//  In:			REFIID riid
//				LPVOID FAR* ppvObj
//
//  Out:
//
//  Comments:
/////////////////////////////////////////////////////////////////////
STDMETHODIMP PgpNwClsFactory::QueryInterface(REFIID riid, LPVOID FAR* ppvObj)
{
	PgpGwTrace("PgpNwClsFactory::QueryInterface\n");
	if(NULL == ppvObj)
		return E_INVALIDARG;

	*ppvObj = NULL;


	if((riid == IID_IClassFactory) || (riid == IID_IUnknown))
	{
		*ppvObj = this;
	}

	if(*ppvObj)
	{
		((IUnknown*)*ppvObj)->AddRef();
		return S_OK;
	}

	return E_NOINTERFACE;
}

///////////////////////////////////////////////////////////////////
//  Name:PgpNwClsFactory::AddRef	
//
//  Description:Add to reference count.
//
//  In:none
//
//  Out:m_cRef - reference count.
//
//	Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) PgpNwClsFactory::AddRef()
{
	PgpGwTrace("PgpNwClsFactory::AddRef\n");
	return ++m_cRef;
}

///////////////////////////////////////////////////////////////////
//  Name:PgpNwClsFactory::Release	
//
//  Description:Drop reference count and delete if it goes to zero.
//
//  In:none
//
//  Out:m_cRef - reference count.
//
//  Comments:
/////////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) PgpNwClsFactory::Release()
{
	PgpGwTrace("PgpNwClsFactory::Release\n");
	ULONG cRef = --m_cRef;
	if(0 == m_cRef)
	{
		delete this;
	}
	return cRef;
}

///////////////////////////////////////////////////////////////////
//  Name:PgpNwClsFactory::CreateInstance	
//
//  Description:Create PgpNwClsFactory
//
//  In:IUnknown *pUnkOuter - 
//
//  Out:REFIID riid, void** ppv - 
//
//	Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP PgpNwClsFactory::CreateInstance(IUnknown *pUnkOuter, REFIID riid, void** ppv)
{
	PgpGwTrace("PgpNwClsFactory::CreateInstance\n");
	//check parameters
	pgpAssert(NULL != ppv);
	if(NULL == ppv)
		return E_INVALIDARG;//null pointer passed to us

	//if an outer unknown was passed to us
	if(NULL != pUnkOuter)
	{
		pgpAssert(FALSE);//no aggregation allowed on us
		return CLASS_E_NOAGGREGATION;//we do not support aggregation
	}
	
	//create an instance of the server object
	CPgpGwC3PO *ppgc3po = new CPgpGwC3PO;
	pgpAssert(NULL != ppgc3po);
	if(ppgc3po == NULL)
		return E_OUTOFMEMORY;

	//initialize the server object
	BOOL bRet=ppgc3po->Create();
	pgpAssert(TRUE == bRet);
	if(FALSE == bRet)
	{
		delete ppgc3po;//delete the object we have created
		return E_OUTOFMEMORY;//we presume that memory was insufficient
							 //during new operations for the member pointers
	}

	//get the interface requested
	HRESULT hrRes = ppgc3po->QueryInterface(riid, ppv);
	if(FAILED(hrRes))
		delete ppgc3po;
	else
		g_cObj++;

	return hrRes;
}

///////////////////////////////////////////////////////////////////
//	Name:PgpNwClsFactory::LockServer	
//
//	Description:
//
//  In:BOOL bLock
//
//  Out:none
//
//	Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP PgpNwClsFactory::LockServer(BOOL bLock)
{
	PgpGwTrace("PgpNwClsFactory::LockServer\n");
	if(bLock)
		g_cLock++;
	else
		g_cLock--;

	return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -