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

📄 pgpgwserver.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//
//  In:IDispatch * FAR* ppIDispEventMonitor
//
//  Out:EventMonitor object or null if not supported
//
//  Comments:We do not support event monitor at this time, so 
//			 return S_FALSE
/////////////////////////////////////////////////////////////////////
STDMETHODIMP CPgpGwC3PO::get_EventMonitor(IDispatch * FAR* ppIDispEventMonitor)
{
	PgpGwTrace("CPgpGwC3PO::get_EventMonitor\n");		

	//check parameters passed
	pgpAssert(NULL != ppIDispEventMonitor);
	if(NULL == ppIDispEventMonitor)
		return 	E_INVALIDARG;

	//nullify the param before writing anything
	*ppIDispEventMonitor=NULL;

	if(NULL != m_pIEventMonitor)//if we have inited an event monitor object
	{
		//return the dispatch interface to the object
		return m_pIEventMonitor->QueryInterface(IID_IDispatch, (void**)ppIDispEventMonitor);
	}

	return S_FALSE;
}

///////////////////////////////////////////////////////////////////
//
//  Name:CPgpGwC3PO::get_IconFactory	
//
//  Description:This property returns the IconFactory for the C3PO.  
//				The C3PO server may return NULL.
//
//  In:IDispatch * FAR* ppIDispIconFactory
//
//  Out:IconFactory object or null if not supported
//
//  Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP CPgpGwC3PO::get_IconFactory(IDispatch * FAR* ppIDispIconFactory)
{
	PgpGwTrace("CPgpGwC3PO::get_IconFactory\n");

	//check parameters passed
	pgpAssert(NULL != ppIDispIconFactory);
	if(NULL == ppIDispIconFactory)
		return 	E_INVALIDARG;

	//nullify the param before writing anything
	*ppIDispIconFactory = NULL;

	if(NULL != m_pIIconFactory)//if we have inited an icon factory object
	{
		//pass the dispatch interface to the object
		return m_pIIconFactory->QueryInterface(IID_IDispatch, (void**)ppIDispIconFactory);
	}

	return S_FALSE;
}

///////////////////////////////////////////////////////////////////
//  Name:			CPgpGwC3PO::CanShutdown	
//
//  Description:This method is invoked to query whether the C3PO server can
//  shutdown.  Typically, this is used when the C3PO server has a window open 
//  on the UI screen and is not in a state where shutdown is possible.  Each 
//  C3PO server is guaranteed to have CanShutdown queried at least once before 
//  the C3PO system shuts down.

//  Semantically, CanShutdown is a request from the C3POManager to a given C3PO.
//  It's not a request for shutting down a C3PO as much as it is a request to 
//  shutdown the C3POManager and consequently disconnect the C3PO.  Typically, a 
//  C3PO would shutdown along with the C3POManager, but this is not strictly required.
//
//  No particular C3PO order can be relied on for querying the CanShutdown property.
//
//
//  In:VARIANT_BOOL FAR* pbCanShutdown
//
//  Out:TRUE if it is OK to shutdown
//      FALSE if it is not OK to shutdown
//  Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP CPgpGwC3PO::CanShutdown(VARIANT_BOOL FAR* pbCanShutdown)
{
	PgpGwTrace("CPgpGwC3PO::CanShutdown\n");

	//check parameters
	pgpAssert(NULL != pbCanShutdown);
	if(NULL == pbCanShutdown)
		return E_INVALIDARG;

	//always allow shutdown since we do not have any situations
	//as of now when we want GW not to shutdown. return false here
	//for GW to suspend shutdown if required.
	*pbCanShutdown = VARIANT_TRUE;

	return S_OK;
}

///////////////////////////////////////////////////////////////////
//  Name:			CPgpGwC3PO::Init	
//
//  Description:  This method is the first method invoked in the C3POServer object
//                when loading a C3PO server.  If the server fails this call
//                (via the HRESULT), the C3PO server is unloaded.
//
//                One Init call will be issued to the C3POServer for each C3PO
//                Client using the C3PO system.  C3POs that wish to be capable of
//                loading into multiple Clients (irrespective of process boundaries)
//                should be multiple-instance OLE servers.  That is, a new C3POServer
//                object should be created for each C3POManager that wished to use
//                the services of the C3PO.  By tracking the Manager pointer for
//                each C3POServer, the C3PO can sort out which requests are being
//                issued from which clients.
//
//                The Manager object is valid until a future DeInit() call.
//                That is, the C3PO does not need to AddRef() this object but can
//                simply store it for the life of the C3PO (until DeInit is called).
//
//
//  In:			IDispatch * pIDispManager - C3POManager object
//
//  Out:
//
//  Comments:
///////////////////////////////////////////////////////////////////
STDMETHODIMP CPgpGwC3PO::Init(IDispatch * pIDispManager)
{
	PgpGwTrace("CPgpGwC3PO::Init\n");

	//check parameters
	pgpAssert(NULL != pIDispManager);
	if(NULL == pIDispManager)
		return E_POINTER;

	//cache the manager
	pgpAssert(NULL == m_pIMgr);//should not have been inited already
	HRESULT hrRes = pIDispManager->QueryInterface
				(IID_IC3POManager, (void**)&m_pIMgr);
	if(FAILED(hrRes))
	{
		pgpAssert(FALSE);//request for manager iface failed !!
		return hrRes;
	}

	return S_OK;
}

///////////////////////////////////////////////////////////////////
//  Name:				CPgpGwC3PO::DeInit	
//
//  Description:Terminates the relationship of the C3PO Manager with 
//				the C3PO server. Note that this is a separate issue 
//				from the shutdown sequence (including shutdown events).  
//				For example, a C3PO may be unloaded from memory as a 
//				runtime optimization.  In that scenario, the C3PO 
//				server first receives CanShutdown() calls followed by 
//				DeInit() the C3PO is unloaded, but the client application 
//				has not necessarilly terminated.
//
//  In:none
//
//  Out:none			
//
//  Comments:The C3POManager pointer passed in to C3POServer::Init() is still 
//			 valid during this call.  However, when DeInit() returns, the 
//			 C3POManager pointer is not guaranteed to be valid.  The C3POServer 
//			 must release all holds to the C3POManager during the DeInit call.
//
//			 One DeInit call will be issued to the C3POServer for each C3PO Client 
//			 using the C3PO system.  C3POs that wish to be capable of loading into 
//			 multiple Clients (irrespective of process boundaries) should be 
//			 multiple-instance OLE servers.  That is, a new C3POServer object 
//			 should be created for each C3POManager that wished to use the 
//			 services of the C3PO.  By tracking the Manager pointer for each 
//			 C3POServer, the C3PO can sort out which requests are being issued 
//			 from which clients.
//	
/////////////////////////////////////////////////////////////////////
STDMETHODIMP CPgpGwC3PO::DeInit()
{
	PgpGwTrace("CPgpGwC3PO::DeInit\n");
	if(NULL != m_pIMgr)
	{
		m_pIMgr->Release(); 
		m_pIMgr=NULL;
	}

	return S_OK;
}

///////////////////////////////////////////////////////////////////
//  Name:InsertUsInTPHChain
//
//  Description:Inserts ourselves onto the TPH chain. If another 
//  pgpgw.dll is found in the chain the path is updated to this path.
//  otherwise we insert ourselves at the end of the chain.
//
//  In: pszModulePath - the path of this module
//
//  Out:none
//
//  Comments:
///////////////////////////////////////////////////////////////////
BOOL InsertUsInTPHChain(char *pszModulePath)
{
	LONG lRet=0;
	HKEY hKey=NULL;
	BOOL bRet=FALSE, bFoundOurselves=FALSE;
	UINT uiIndex=0;
	DWORD dwNoOfValues=0, dwTempBufLen=0, dwMaxValueLen=0;
	char szTmpBuffer[100]={0};
	char *pszValue=NULL, *pszFileName=NULL;

	//check parameters passed to us
	pgpAssert(NULL != pszModulePath);
	if(NULL == pszModulePath)
		return FALSE;

	//make the TPH related entries. open the key at HKCU\Software\Novell\GroupWise\Client\Third Party
	//if it does not exist create the key
	pgpAssert(NULL == hKey);
	lRet=RegCreateKeyEx(HKEY_CURRENT_USER, TPHKEY, 0, NULL, NULL, KEY_ALL_ACCESS,
			NULL, &hKey, NULL);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hKey));
	if((ERROR_SUCCESS != lRet) || (NULL == hKey))
		goto cleanup;

	//get the number and max length of values involved
	pgpAssert(NULL != hKey);
	lRet=RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
			&dwNoOfValues, NULL, &dwMaxValueLen, NULL, NULL);
	pgpAssert(ERROR_SUCCESS == lRet);
	if(ERROR_SUCCESS != lRet)
		goto cleanup;

	//allocate the value buffer
	pgpAssert(NULL == pszValue);
	pszValue=(char *)calloc(dwMaxValueLen+1, 1);
	pgpAssert(NULL != pszValue);
	if(NULL == pszValue)
		goto cleanup;

	//check if we already appear in the chain
	//for each of the DLLx values under the registry key
	for(uiIndex=1; uiIndex <= dwNoOfValues; uiIndex++)
	{
		//prepare the value name
		ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
		sprintf(szTmpBuffer, "DLL%d", uiIndex);

		//read the value data
		pgpAssert(NULL != hKey);
		dwTempBufLen=dwMaxValueLen;
		lRet = RegQueryValueEx(hKey, szTmpBuffer, 0, NULL, 
						(LPBYTE)pszValue, &dwTempBufLen);
		pgpAssert((ERROR_SUCCESS == lRet) && (dwTempBufLen > 0));
		pgpAssert(dwTempBufLen < dwMaxValueLen);//damaged TPH chain ?

		//get at the file name from the path
		pszFileName=strrchr(pszValue, '\\');//find the last slash
		pgpAssert(NULL != pszFileName);
		if(NULL == pszFileName)
			continue;//junk entry in chain. skip it.
		pszFileName++;

		//if the entry is an entry for us
		if(0 == strcmpi(pszFileName, MODULEFILENAME))
		{
			//we will update the path instead of inserting into the chain again
			//this puts to rest all problems because of double registration
			lRet = RegSetValueEx(hKey, szTmpBuffer, 0, REG_SZ, (const BYTE*)pszModulePath, 
						lstrlen(pszModulePath));
			pgpAssert(ERROR_SUCCESS == lRet);
			if(ERROR_SUCCESS == lRet)
				bRet=TRUE;//success

			goto cleanup;//we are done
		}
	}

	//the control comes here only if we could not find ourselves in the
	//TPH chain. so let us set ourselves as the last entry in the chain
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "DLL%d", dwNoOfValues+1);
    lRet = RegSetValueEx(hKey, szTmpBuffer, 0, REG_SZ, (const BYTE*)pszModulePath, lstrlen(pszModulePath));
	pgpAssert(ERROR_SUCCESS == lRet);
	if(ERROR_SUCCESS == lRet)
		bRet=TRUE;//success

cleanup:
	if(NULL != pszValue)
	{
		free(pszValue);
		pszValue=NULL;
	}

	if(NULL != hKey)
	{
		RegCloseKey(hKey);
		hKey=NULL;
	}

	return bRet;
}

///////////////////////////////////////////////////////////////////
//  Name:RegServer
//
//  Description:Sets up the system registery for the plugin
//
//  In:none
//
//  Out:none
//
//  Comments:
///////////////////////////////////////////////////////////////////
void RegServer()
{
	char szTmpBuffer[512]={0};
	char szTmpBuffer2[100]={0};
	HMODULE hModPgpGw=NULL;
	DWORD dwNoOfValues=0;
	
	HKEY hKey=NULL, hSubKey=NULL, hSubKey1=NULL;
	LONG lRet=ERROR_SUCCESS;

	//open/create the key at HKLM\Software\Novell\GroupWise\5.0\C3PO\DataTypes
	pgpAssert(NULL == hKey);
	lRet = RegCreateKey(HKEY_LOCAL_MACHINE, C3POKEY, &hKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hKey));

	//create the modulename\objects hierarchy under GW.MESSAGE.MAIL subkey
	pgpAssert(NULL == hSubKey);
	sprintf(szTmpBuffer, "%s\\%s\\Objects", MAILMESSAGECONTEXTA, MODULENAME);
	lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);

⌨️ 快捷键说明

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