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

📄 gwcommand.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
////////////////////////////////////////////////////////////////////////////////
//
//  File : GwCommand.cpp
//
//  Copyright (C) 2002 PGP Corporation
//
//  ABSTRACT
//		Create CommandFactory, EventMonitor, IConFactory, and GWCommand objects.
// 
//  Author: Satya S. Das
//
////////////////////////////////////////////////////////////////////////////////

#include "windows.h"
#include "windowsx.h"
#include "gwoapi.h"
#include "gwc3po.h"
#include "gwc3cmd.h"
#include "gwdll.h"
#include "GwCommand.h"
#include "CommandFactory.h"
#include "util.h"
#include "EventNotif.h"
#include "globals.h"
#include "globdefs.h"
#include <ole2.h>
#include "resource.h"
#include <crtdbg.h>
#include <stdio.h>
#include <richedit.h>
#include <commctrl.h>

#include "pgpclientlib.h"
#include "pgpUtilities.h"
#include "decryptverify.h"
#include "pgpsc.h"
#include "pgpclientprefs.h"
#include "pgpdebug.h"


// Do the following define stuff in only one file in your project
#undef DEFINE_GUID
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
        EXTERN_C const GUID CDECL name \
                = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
// End of define stuff

extern IC3POManager *m_pIMgr;

// local definitions 

// default settings

// external functions 

// internal functions 
IUnknown * BuildIUnkDispatch(REFCLSID libid, REFCLSID iid, IUnknown *pIUnk, void *pIFac);

VOID WINAPI GWEventNotify (DWORD dwID, DWORD dwEvent);
extern HRESULT Publish(LPCSTR szTokenBuf, BSTR *pbstrResult);

// public data 

// private data 

// public functions 

// private functions 
// IGWCommand methods
//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::Set_BaseCommand				
//	
//  Description:remember the base command interface
//  				
//  In:	IGWCommand * pigwBaseCmd - the base command interface ptr
//
//  Out:none
//
//  Comments:		
///////////////////////////////////////////////////////////////////
void CGWCommand::Set_BaseCommand(IGWCommand *pigwBaseCmd)
{
	m_pigwBaseCmd=pigwBaseCmd;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::CGWCommand				
//
//  Description:CGWCommand constructor. Init reference count. Set 
//				command ID. Set IDispatch to null	
//  
//  In:	int nID - Command ID.
//  
//  Out:none
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
CGWCommand::CGWCommand(int nID, DWORD dwCmdUiInfo)
{
	PgpGwTrace("CGWCommand::CGWCommand %#x, m_nID=%d\n", this, nID);
	m_cRef=1;
	m_nID=nID;
	m_dwCmdUiInfo=dwCmdUiInfo;
	m_pIUnkDisp=NULL;
	m_pigwBaseCmd=NULL;
	m_pIDispOfCmd=NULL;
	m_bstrLongPrompt=NULL;
	m_bstrToolTip=NULL;
	m_hCtxtWindow=NULL;
	m_hOverlappingWnd=NULL;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::~CGWCommand				
//
//  Description:CGWCommand destructor. If we have a IDispatch release it.
//				Release our long prompt if we have one.	
//  
//  In:	none
//  
//  Out: none
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
CGWCommand::~CGWCommand()
{
	PgpGwTrace("CGWCommand::~CGWCommand - this=%#x, m_nID=%d\n", this, m_nID);	

	if((NULL != m_hCtxtWindow) && (NULL != g_pccihCmdHash))
	{
		BOOL bRet=g_pccihCmdHash->Remove((ULONG)m_hCtxtWindow);
		//pgpAssert(TRUE == bRet);
	}
		
	if(NULL != m_pIUnkDisp)
	{
		m_pIUnkDisp->Release();
		m_pIUnkDisp=NULL;
	}

	if(NULL != m_bstrLongPrompt)
	{
		SysFreeString(m_bstrLongPrompt);
		m_bstrLongPrompt=NULL;
	}

	if(NULL != m_bstrToolTip)
	{
		SysFreeString(m_bstrToolTip);
		m_bstrToolTip=NULL;
	}

	if(NULL != m_pigwBaseCmd)
	{
		m_pigwBaseCmd->Release();
		m_pigwBaseCmd=NULL;
	}

	if(NULL != m_pIDispOfCmd)
	{
		m_pIDispOfCmd->Release();
		m_pIDispOfCmd=NULL;
	}
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::QueryInterface				
//
//  Description:QueryInterface	for CGWCommand.
//
//  In:	REFIID riid
//	
//  
//  Out:LPVOID FAR* ppv
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::QueryInterface(REFIID riid, LPVOID FAR* ppv)
{
	//PgpGwTrace("CGWCommand::QueryInterface %#x\n", this);
	if(NULL == ppv)
		return E_INVALIDARG;

    *ppv=NULL;


	if((IID_ICommandFactory == riid) ||	(IID_IUnknown == riid))
	{
		*ppv  = this;
		((LPUNKNOWN)*ppv)->AddRef();
		return S_OK;
	}

	if(IID_IDispatch == riid)
	{
		if (NULL == m_pIUnkDisp)
		{
			m_pIUnkDisp=BuildIUnkDispatch(LIBID_PgpGwTypeLibrary,
					IID_IGWCommand,	(IUnknown *)(IGWCommand *)this,
					(void *)(IGWCommand *)this);
		}

		if (NULL != m_pIUnkDisp)
			return m_pIUnkDisp->QueryInterface(IID_IDispatch, ppv);
	}

	return E_NOINTERFACE;
}

//////////////////////////////////////////////////////////////////
//	Name: CGWCommand::AddRef				
//
//  Description:Add to reference count	
//
//  In:	none
//
//  Out:m_cRef - New reference count
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) CGWCommand::AddRef()
{
	//PgpGwTrace("CGWCommand::AddRef %#x, count after addref=%d\n", this, m_cRef+1);	
	return ++m_cRef;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::Release				
//
//  Description:Decrament reference count by one. If reference 
//		count goes to zero delete Command object.	
//  
//  In:none
//  
//  Out:cRef - New reference count.
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP_(ULONG) CGWCommand::Release()
{
	//PgpGwTrace("CGWCommand::Release %#x, count after rel=%d\n", this, m_cRef-1);	

	ULONG cRef = --m_cRef;
	if(0 == m_cRef)
	{
		delete this;
	}
	return cRef;
}

//////////////////////////////////////////////////////////////////
//	Name:			CGWCommand::get_BaseCmd				
//
//  Description:This routine should get the Base Command and 
//				return it as a CGWCommand.	
//  
//  In:	none
//  
//  Out: IDispatch * FAR* ppIDispBaseCmd - Base command
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::get_BaseCmd(IDispatch * FAR* ppIDispBaseCmd)
{
	//PgpGwTrace("CGWCommand::get_BaseCmd\n");	
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name: CGWCommand::get_LongPrompt				
//
//  Description:This routine should return the long prompt for the 
//				GWCommand.	
//
//  In:none
//
//  Out:BSTR FAR* pbstrLongPrompt - pointer to long prompt string 
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::get_LongPrompt(BSTR FAR* pbstrLongPrompt)
{
	//PgpGwTrace("CGWCommand::get_LongPrompt\n");	
	*pbstrLongPrompt = SysAllocString(m_bstrLongPrompt);
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name: CGWCommand::get_Parameters				
//
//  Description: This is for later use. (Always null)	
//
//  In:	none
//
//  Out: IDispatch * FAR* ppIDispBaseCmd
//
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::get_Parameters(IDispatch * FAR* ppIDispBaseCmd)
{
	//PgpGwTrace("CGWCommand::get_Parameters\n");	
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::get_PersistentID				
//
//  Description:This routine should return the persistent ID
//              for the command.	
//  
//  In:none
//  
//  Out:BSTR FAR* pbstrPersistentID
//  
//  Comments:		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::get_PersistentID(BSTR FAR* pbstrPersistentID)
{
	//PgpGwTrace("CGWCommand::get_PersistentID this=%#x\n", this);	
	return E_FAIL;
}

//////////////////////////////////////////////////////////////////
//	Name:CGWCommand::get_ToolTip				
//
//  Description:This routine should return the tool tip for custom 
//				toolbar commands only.	
//  
//  In:	none
//  
//  Out:BSTR FAR* pbstrToolTip
//  
//  Comments:Only commands genertated and placed on the toolbar with
//  CommandFactory.Customise Toolbar(or explicitly added by the user) have
//  this method invoked.		
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::get_ToolTip(BSTR FAR* pbstrToolTip)
{
	//PgpGwTrace("CGWCommand::get_ToolTip\n");	
	*pbstrToolTip = SysAllocString(m_bstrToolTip);
	return S_OK;
}

//////////////////////////////////////////////////////////////////
//	Name: CGWCommand::Execute				
//
//  Description: This routine should execute the command.	
//
//  In:	none
//
//  Out: none
//
//  Comments:At this point the processing of the command is the C3po's
//           responsiblity.
//
//      code for getting message object selected.
//	
//		IDispatch *pIDisp;
//		IGWClientState *pIClientState;
//		IGWMessage *pIMessage;
//		HRESULT hr;
//		//Get ClientState interfaces
//  	m_pIMgr->get_ClientState(&pIDisp);
//		hr = pIDisp->QueryInterface(IID_IClientState, (void**)&pIClientState);
//  		pIDisp->Release();
//
//		// get CommandMesage interfaces
//		pIClientState->get_CommandMessage(&pIDisp);
//		hr = pIDisp->QueryInterface(IID_IGWMessage, (void**)&pIMessage);
//		pIDisp->Release();
//
//		pIClientState->Release();			// release ClientState
///////////////////////////////////////////////////////////////////
STDMETHODIMP CGWCommand::Execute()
{
	PgpGwTrace("CGWCommand::Execute\n");	
	HRESULT hrRet=S_OK;
	PMSGINFO lpMsgInfo=NULL;
	PGPError pgpErrRet=kPGPError_NoErr;

	//fill up the members and the hash with relevant details that might be missing
	hrRet=LearnCommandContext();
	if(FAILED(hrRet))//if we have any problem determining the context
	{
		pgpAssert(FALSE);
		goto end;
	}

	//the hash should have been setup
	pgpAssert(NULL != g_pccihCmdHash);
	if(NULL == g_pccihCmdHash)
		goto end;

	//query the hash for info
	pgpAssert(0 != m_dwCmdUiInfo);
	if(NULL != m_hCtxtWindow)//if we have found the context window 
	{
		//get the info from the hash
		lpMsgInfo=g_pccihCmdHash->Get((ULONG)m_hCtxtWindow);
		pgpAssert(NULL != lpMsgInfo);
		if(NULL == lpMsgInfo)
			goto end;
	}

	//NOTE:in case of message open request we dont know the context
	//window until the very point where we are told to open the message

	switch (m_nID)//check the command ID
	{
		case IDM_LAUNCH_PGPKEYS://launch pgpkeys
			{
				//get the location where pgp keys is installed
				char szPgpKeysPath[MAX_PATH]={0};
				PGPclGetPath(kPGPclPGPkeysExeFile, szPgpKeysPath, MAX_PATH-1);

				//run the executable
				PGPclExecute(szPgpKeysPath, SW_SHOW);
				break;
			}
			break;

		case IDM_SHOW_PREFS://show the pgp options dialog
			{
				pgpAssert(NULL != g_pgpContext);
				pgpAssert(NULL != m_hCtxtWindow);

				pgpErrRet=PGPclPreferences(g_pgpContext, m_hCtxtWindow,/*main window handle*/
							kPGPclEmailPrefs, NULL);
				pgpAssert((pgpErrRet == kPGPError_UserAbort) || !IsPGPError(pgpErrRet));
				if ((pgpErrRet != kPGPError_UserAbort) && IsPGPError(pgpErrRet))

⌨️ 快捷键说明

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