📄 pgpgw.cpp
字号:
////////////////////////////////////////////////////////////////////////////////
// File : pgpgw.cpp
//
// Copyright (C) 2002 PGP Corporation
//
// ABSTRACT
// Create and handle dll
//
// Author: Satya S. Das
//
////////////////////////////////////////////////////////////////////////////////
// include files
#include <objbase.h>
#include <initguid.h>
#include <ole2.h>
#include <crtdbg.h>
#include "pgpgw.h"
#include "pgpdebug.h"
#include "pgpgwGUID.h"
#include "classfactory.h"
#include "odma.h"
#include "ofcmndr.h"
#include "globdefs.h"
#include "pgpclientlib.h"
#include "gwcmdinfohash.h"
// local definitions
IUnknown * BuildIUnkDispatch(REFCLSID libid, REFCLSID iid, IUnknown *pIUnk, void *pIFac);
// default settings
// external functions
// external data
extern ULONG g_cObj;
extern ULONG g_cLock;
extern void RegServer();
extern void UnRegServer();
//module global data. please init all global data elements here.
//refer to globals.h for further details.
HMODULE g_hInstance=NULL;
//ODMHANDLE g_hODMA=NULL;
IGWCommander *g_pigwcCommander=NULL;
BSTR g_bstrValidateCmd=NULL;
PGPContextRef g_pgpContext=NULL;
BOOL g_bPlugInExpired=FALSE;
CCmdInfoHash *g_pccihCmdHash=NULL;
#ifdef _DEBUG
DWORD g_dwModuleOptions=GWMO_TRACE;
#else
DWORD g_dwModuleOptions=0;
#endif
GWTOKENINFO g_gtiLastTokenInfo={0};
///////////////////////////////////////////////////////////////////
// Name: DllMain
//
// Description: Get hInstance for DLL
//
// In: HANDLE hModule - hInstance for DLL
// DWORD dwReason - Reason for call
// LPVOID lpReserved
//
// Out: TRUE
//
//
// Comments:
//////////////////////////////////////////////////////////////////
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
BOOL bRet=TRUE;
if (DLL_PROCESS_ATTACH == dwReason)
{
#ifdef _DEBUG
DebugBreak();
#endif
//must be getting dynamically loaded
pgpAssert(NULL == lpReserved);
pgpAssert(NULL == g_hInstance);
g_hInstance = (HMODULE)hModule;
pgpAssert(NULL != g_hInstance);
try
{
pgpAssert(NULL == g_pccihCmdHash);
g_pccihCmdHash = new CCmdInfoHash;
pgpAssert(NULL != g_pccihCmdHash);
if(NULL == g_pccihCmdHash)
bRet=FALSE;//let there be a load failure
}
catch(...)
{
bRet=FALSE;//let there be a load failure
}
//disable thread notifications to this dll
bRet=DisableThreadLibraryCalls((HINSTANCE)hModule);
pgpAssert(0 != bRet);
bRet=TRUE;//we ignore the error in this step
//init ODMA handle
//g_hODMA=NULL;
//register with ODMA Connection Manager 1.0
//pgpAssert(NULL == g_hODMA);
//ODMRegisterApp(&g_hODMA, 100, MODULENAME, NULL, NULL);
//pgpAssert(NULL != g_hODMA);
}
if(DLL_PROCESS_DETACH == dwReason)
{
if(NULL != g_pccihCmdHash)
{
delete g_pccihCmdHash;
g_pccihCmdHash=NULL;
}
//if(NULL != g_hODMA)
//{
// ODMUnRegisterApp(g_hODMA);//Unregister with ODMA Connection Manager
// g_hODMA=NULL;
//}
}
return bRet;
}
///////////////////////////////////////////////////////////////////
// Name:DllGetClassObject
//
// Description:Return pointer to PgpNwClsFactory object.
//
// In: REFCLSID rclsid - Class ID
// REFIID riid - Reference iid
//
// Out:void **ppv - pointer to factory object
//
//
// Comments:
///////////////////////////////////////////////////////////////////
HRESULT __stdcall DllGetClassObject( REFCLSID rclsid, REFIID riid, void **ppv)
{
if(riid != IID_IUnknown && riid != IID_IClassFactory)
return E_FAIL;
if (CLSID_PGPGWC3PO != rclsid)
return E_FAIL;
PgpNwClsFactory *pIFact=NULL;
try
{
pIFact = new PgpNwClsFactory;
}
catch(...)
{
}
if(NULL == pIFact)
return E_OUTOFMEMORY;
*ppv = pIFact;
return S_OK;
}
///////////////////////////////////////////////////////////////////
// Name:DllCanUnloadNow
//
// Description:Respond to query to unload
//
// In:none
//
// Out:none
//
// Comments:
/////////////////////////////////////////////////////////////////////
HRESULT __stdcall DllCanUnloadNow(void)
{
if(g_cObj || g_cLock) // is lock non zero or the object created
return S_FALSE; // yes return false
else
return S_OK;
}
///////////////////////////////////////////////////////////////////
// Name:BuildIUnkDispatch
//
// Description:Build IDispatch interface.
//
// In: REFCLSID libid - ID of the library.
// REFCLSID iid - unique ID
// IUnknown *pIUnk - IUnknown
// void *pIFac - pointer to the interface
//
// Out:
//
// Comments:
///////////////////////////////////////////////////////////////////
IUnknown * BuildIUnkDispatch(REFCLSID libid, REFCLSID iid,
IUnknown *pIUnk, void *pIFac )
{
HRESULT hrRet=S_OK;
ITypeInfo *pITypeInfo=NULL;
ITypeLib *pTypeLib=NULL;
IUnknown *pIUnkDisp=NULL;
//load type library 1.0
hrRet=LoadRegTypeLib(libid, 1, 0, LANG_NEUTRAL, &pTypeLib);
if (FAILED(hrRet) || (NULL == pTypeLib))
{
pgpAssert(FALSE);//failed to load the type library
goto cleanup;
}
//retrieve the type description corresponding to the specified GUID.
pgpAssert(NULL == pITypeInfo);
hrRet=pTypeLib->GetTypeInfoOfGuid(iid, &pITypeInfo);
if(FAILED(hrRet) || (NULL == pITypeInfo))
{
pgpAssert(FALSE);//failed to get the typeinfo iface
goto cleanup;
}
//create dispatch interface
hrRet = CreateStdDispatch(pIUnk,/*controlling unknown*/ pIFac, /*pointer to the interface*/
pITypeInfo,/*type information*/ &pIUnkDisp);/*IUnknown implementation of IDispatch*/
if (FAILED(hrRet) || (NULL == pIUnkDisp))
{
pgpAssert(FALSE);//failed to get the dispatch
goto cleanup;
}
cleanup:
if(NULL != pITypeInfo)
{
pITypeInfo->Release();
pITypeInfo=NULL;
}
if(NULL != pTypeLib)
{
pTypeLib->Release();
pTypeLib=NULL;
}
return pIUnkDisp;
}
///////////////////////////////////////////////////////////////////
// Name:DllRegisterServer
//
// Description:Register server
//
// In:none
//
// Out:none
//
// Comments:
/////////////////////////////////////////////////////////////////////
STDAPI DllRegisterServer(void)
{
RegServer();
return S_OK;
}
///////////////////////////////////////////////////////////////////
// Name:DllUnregisterServer
//
// Description:unregister server
//
// In:none
//
// Out:none
//
// Comments:
/////////////////////////////////////////////////////////////////////
STDAPI DllUnregisterServer(void)
{
UnRegServer();
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -