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

📄 pgpgwserver.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

    //create a "CommandFactory" value of null value
	pgpAssert(NULL != hSubKey);
	lRet = RegSetValueEx(hSubKey, "CommandFactory", 0, REG_SZ,(const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey);
	hSubKey=NULL;

   //create the modulename\events hierarchy under GW.MESSAGE.MAIL subkey
	//NOTE: we do not create any values under this newly created hierarchy
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s\\Events", MAILMESSAGECONTEXTA, MODULENAME);
	pgpAssert((NULL != hKey) && (NULL == hSubKey));
	lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

	//create a value to trap the open event (GW#C#OPEN)
	pgpAssert(NULL != hSubKey);
	lRet = RegSetValueEx(hSubKey, eGW_CMDID_OPEN, 0, REG_SZ,(const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey);
	hSubKey=NULL;
 
	//create the modulename\objects hierarchy under GW.CLIENT.WINDOW.BROWSER subkey
	pgpAssert(NULL == hSubKey);
	sprintf(szTmpBuffer, "%s\\%s\\Objects", MAINWINDOWCONTEXTA, MODULENAME);
	lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

    //create a "CommandFactory" value of null value
	pgpAssert(NULL != hSubKey);
	lRet = RegSetValueEx(hSubKey, "CommandFactory", 0, REG_SZ,(const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey);
	hSubKey=NULL;

	//create the modulename\objects hierarchy under GW.CLIENT.WINDOW.ATTACHVIEWER subkey
	//pgpAssert(NULL == hSubKey);
	//sprintf(szTmpBuffer, "%s\\%s\\Objects", ATTCHVIEWERCONTEXTA, MODULENAME);
	//lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);
	//pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

    //create a "CommandFactory" value of null value
	//pgpAssert(NULL != hSubKey);
	//lRet = RegSetValueEx(hSubKey, "CommandFactory", 0, REG_SZ,(const BYTE*)"", 1);
	//pgpAssert(ERROR_SUCCESS == lRet);
    //RegCloseKey(hSubKey);
	//hSubKey=NULL;

    //create the modulename\objects hierarchy under GW.CLIENT subkey
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s\\Objects", CLIENTCONTEXTA, MODULENAME);
	pgpAssert((NULL != hKey) && (NULL == hSubKey));
	lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

    //create an EventMonitor value of null string in that key
	lRet = RegSetValueEx(hSubKey, "EventMonitor", 0, REG_SZ,(const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey);
	hSubKey=NULL;
    
   	//create the modulename\events hierarchy under GW.CLIENT subkey
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s\\Events", CLIENTCONTEXTA, MODULENAME);
	pgpAssert((NULL != hKey) && (NULL == hSubKey));
	lRet = RegCreateKey(hKey, szTmpBuffer, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey));

    //create "OnReady" and "OnShutdown" values under that key
	lRet = RegSetValueEx(hSubKey, "OnReady", 0, REG_SZ, (const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    lRet = RegSetValueEx(hSubKey, "OnShutdown", 0, REG_SZ, (const BYTE*)"", 1);
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey);
	hSubKey=NULL;

    
	RegCloseKey(hKey);
	hKey=NULL;

	//prepare the path of this server from the location
	//where it lies at the point of registration
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	hModPgpGw=GetModuleHandle(MODULENAME);
	pgpAssert(NULL != hModPgpGw);
	_VERIFY(0 != GetModuleFileName(hModPgpGw, szTmpBuffer, sizeof(szTmpBuffer)));
	
	//put ourselves in the TPH chain
	_VERIFY(TRUE == InsertUsInTPHChain(szTmpBuffer));

	//setup the COM infrastructure for ourselves

    //create the module name key under classes root 
	pgpAssert(NULL == hSubKey);
	lRet = RegCreateKey(HKEY_CLASSES_ROOT, MODULENAME, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) &&(NULL != hSubKey));

    //put the description as the unnamed(default) value of the key
	char *p = MODULEDESCRIPTION;
    lRet = RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (const BYTE*)p,lstrlen(p));
	pgpAssert(ERROR_SUCCESS == lRet);

    //create a clsid key under the module name key
	lRet = RegCreateKey(hSubKey,"CLSID", &hSubKey1);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey1));
	RegCloseKey(hSubKey);
	hSubKey=NULL;

    //set the CLSID string as the default value of the key
	p = MODULECLSID;
    lRet = RegSetValueEx(hSubKey1, NULL, 0, REG_SZ, (const BYTE*)p, lstrlen(p));
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey1);
	hSubKey1=NULL;
    
    //set up the reverse lookup infrastructure. so lets open the clsid key
	//under class root hive
	lRet = RegOpenKey(HKEY_CLASSES_ROOT,"CLSID", &hKey);
	pgpAssert((ERROR_SUCCESS == lRet) &&(NULL != hKey));

	//create the clsid string under that as a key
    lRet = RegCreateKey(hKey, MODULECLSID, &hSubKey);
	pgpAssert((ERROR_SUCCESS == lRet) &&(NULL != hSubKey));
	RegCloseKey(hKey);
	hKey=NULL;

    //set the description as the default value of the key
	p = MODULEDESCRIPTION;
    lRet = RegSetValueEx(hSubKey, NULL, 0, REG_SZ, (const BYTE*)p,lstrlen(p));
	pgpAssert(ERROR_SUCCESS == lRet);

    //create ProgId key under that
	lRet = RegCreateKey(hSubKey,"ProgID", &hSubKey1);
	pgpAssert((ERROR_SUCCESS == lRet) &&(NULL != hSubKey1));

	//put the module name as the default value of the key
	//NOTE:the version info is normally put at the end as a dotted suffix
    p = MODULENAME;
    lRet = RegSetValueEx(hSubKey1, NULL, 0, REG_SZ, (const BYTE*)p,lstrlen(p));
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey1);
	hSubKey1=NULL;

    //create inprocserver32 key under the module clsid key
	lRet = RegCreateKey(hSubKey,"InProcServer32", &hSubKey1);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hSubKey1));

	//set the default value of the key to the path of the server
    p = szTmpBuffer;
    lRet = RegSetValueEx(hSubKey1, NULL, 0, REG_SZ, (const BYTE*)p,lstrlen(p));
	pgpAssert(ERROR_SUCCESS == lRet);
    RegCloseKey(hSubKey1);
	hSubKey1=NULL;
}


///////////////////////////////////////////////////////////////////
//  Name:RemoveUsFromTPHChain
//
//  Description:Removes us from the TPH chain and makes sure that
//		 other TPH's behave well after we unregister
//
//  In:none
//
//  Out:none
//
//  Comments:
///////////////////////////////////////////////////////////////////
BOOL RemoveUsFromTPHChain()
{
	char szPgpGwPath[1024]={0};
	HKEY hKey=NULL;
	HMODULE hModPgpGw=NULL;
	LONG lRet=ERROR_SUCCESS;
	DWORD dwNoOfValues=0, dwMaxValueNameLen=0, dwMaxValueLen=0, dwTempBufLen=0;
	char *pszValueName=NULL, *pszValue=NULL;
	BOOL bRet=FALSE, bFoundOurselves=FALSE;
	unsigned int uiIndex=0;

	//get the full path of pgpgw module
	ZeroMemory(szPgpGwPath, sizeof(szPgpGwPath));
	hModPgpGw=GetModuleHandle(MODULENAME);
	pgpAssert(NULL != hModPgpGw);
	_VERIFY(0 != GetModuleFileName(hModPgpGw, szPgpGwPath, sizeof(szPgpGwPath)));
	
	//open the key at HKCU\Software\Novell\GroupWise\Client\Third Party
	pgpAssert(NULL == hKey);
	lRet=RegOpenKey(HKEY_CURRENT_USER, TPHKEY, &hKey);
	pgpAssert((ERROR_SUCCESS == lRet) && (NULL != hKey));

	//get the number of values, the max length of the value name and value data
	pgpAssert(NULL != hKey);
	lRet=RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL,
			&dwNoOfValues, &dwMaxValueNameLen, &dwMaxValueLen, NULL, NULL);
	pgpAssert(ERROR_SUCCESS == lRet);

	//allocate appropriately for the strings used to store the value name and value data
	pszValueName=(char *)calloc(dwMaxValueNameLen+1, 1);
	pgpAssert(NULL != pszValueName);

	pszValue=(char *)calloc(dwMaxValueLen+1, 1);
	pgpAssert(NULL != pszValue);

	//if either of the allocations failed
	if((NULL == pszValueName) || (NULL == pszValue))
		goto cleanup;

	//for each of the DLLx values under the registry key
	for(uiIndex=1; uiIndex <= dwNoOfValues; uiIndex++)
	{
		//prepare the value name
		sprintf(pszValueName, "DLL%d", uiIndex);

		//read the value data
		pgpAssert(NULL != hKey);
		dwTempBufLen=dwMaxValueLen;
		lRet = RegQueryValueEx(hKey, pszValueName, 0, NULL, 
						(LPBYTE)pszValue, &dwTempBufLen);
		pgpAssert(ERROR_SUCCESS == lRet);

		if(FALSE == bFoundOurselves)//if we have not found ourselves yet
		{
			//check to see if it is us
			if(0 == strcmpi(pszValue, szPgpGwPath))
				bFoundOurselves=TRUE;
		}
		else//ie. we have found the entry for pgpgw.dll
		{
			//time to keep pushing back all the tph's registered after pgpgw

			//prepare the value name for the previous entry
			sprintf(pszValueName, "DLL%d", uiIndex-1);

			//set the previous value to this value
			lRet=RegSetValueEx(hKey, pszValueName, 0, REG_SZ, 
							(const BYTE*)pszValue, lstrlen(pszValue));
			pgpAssert(ERROR_SUCCESS == lRet);
		}
	}

	if(TRUE == bFoundOurselves)//if we did find ourselves
	{
		//we must remove the last DLLx entry as the data has been
		//put into the last but one entry
		sprintf(pszValueName, "DLL%d", dwNoOfValues);
		lRet=RegDeleteValue(hKey, pszValueName);
		pgpAssert(ERROR_SUCCESS == lRet);
	}

	bRet=TRUE;

cleanup:
	if(NULL != hKey)
	{
		RegCloseKey(hKey);
		hKey=NULL;
	}
	if(NULL != pszValueName)
	{
		free(pszValueName);
		pszValueName=NULL;
	}
	if(NULL != pszValue)
	{
		free(pszValue);
		pszValue=NULL;
	}
	return bRet;
}

///////////////////////////////////////////////////////////////////
//  Name:UnRegServer
//
//  Description:Unregisters the pgpgw plugin
//
//  In:none
//
//  Out:none
//
//  Comments:
///////////////////////////////////////////////////////////////////
void UnRegServer()
{
	char szTmpBuffer[1024]={0};
	HKEY hKey=NULL, hSubKey=NULL;
	LONG lRet=ERROR_SUCCESS;

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

   	//delete the module name key under GW.CLIENT
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s", CLIENTCONTEXTA, MODULENAME);
	lRet = SHDeleteKey(hKey, szTmpBuffer);
	pgpAssert(ERROR_SUCCESS == lRet);

   	//delete the module name key under GW.CLIENT.WINDOW.BROWSER
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s", MAINWINDOWCONTEXTA, MODULENAME);
	lRet = SHDeleteKey(hKey, szTmpBuffer);
	pgpAssert(ERROR_SUCCESS == lRet);

   	//delete the module name key under GW.CLIENT.WINDOW.ATTACHVIEWER
	//ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	//sprintf(szTmpBuffer, "%s\\%s", ATTCHVIEWERCONTEXTA, MODULENAME);
	//lRet = SHDeleteKey(hKey, szTmpBuffer);
	//pgpAssert(ERROR_SUCCESS == lRet);
   	
	//delete the module name key under GW.MESSAGE.MAIL
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s", MAILMESSAGECONTEXTA, MODULENAME);
	lRet = SHDeleteKey(hKey, szTmpBuffer);
	pgpAssert(ERROR_SUCCESS == lRet);

	RegCloseKey(hKey);
	hKey=NULL;
    
	//remove ourselves from the TPH chain
	_VERIFY(TRUE == RemoveUsFromTPHChain());

	//cleanup com entries

	//delete the HKEY_CLASSES_ROOT\<module name> entry
	lRet = SHDeleteKey(HKEY_CLASSES_ROOT, MODULENAME);
	pgpAssert(ERROR_SUCCESS == lRet);

	//delete the HKEY_CLASSES_ROOT\clsid\<module clsid> entry
	ZeroMemory(szTmpBuffer, sizeof(szTmpBuffer));
	sprintf(szTmpBuffer, "%s\\%s", "CLSID", MODULECLSID);
	lRet = SHDeleteKey(HKEY_CLASSES_ROOT, szTmpBuffer);
	pgpAssert(ERROR_SUCCESS == lRet);
}


⌨️ 快捷键说明

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