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

📄 eventmonitor.cpp

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

// include files 
#include <windows.h>
#include <crtdbg.h>
#include "pgpdebug.h"
#include "gwoapi.h"
#include "gwc3po.h"
#include "gwc3cmd.h"
#include "EventMonitor.h"
#include "util.h"
#include "globdefs.h"
#include "globals.h"
#include "resource.h"
#include "pgpLnLib.h"
#include "pgpWin32Errors.h"

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

///////////////////////////////////////////////////////////////////
//  Name:EventMonitor::EventMonitor				
//
//  Description:EventMonitor constructor 
//
//  In:none
//
//  Out:none
//
//  Comments:		
/////////////////////////////////////////////////////////////////////
EventMonitor::EventMonitor(IUnknown *pUnk)
{
	PgpGwTrace("EventMonitor::EventMonitor\n");
	m_pUnkOuter = pUnk;
	m_pIUnkDispFact = NULL;
}

///////////////////////////////////////////////////////////////////
//  Name:EventMonitor::~EventMonitor				
//
//  Description:EventMonitor destructor	
//
//  In:none
//
//  Out:none
//
//  Comments:		
/////////////////////////////////////////////////////////////////////
EventMonitor::~EventMonitor()
{
	PgpGwTrace("EventMonitor::~EventMonitor\n");
	if(NULL != m_pIUnkDispFact)
	{
		m_pIUnkDispFact->Release();
		m_pIUnkDispFact=NULL;
	}
}

///////////////////////////////////////////////////////////////////
//  Name:EventMonitor::QueryInterface				
//
//  Description:QueryInterface for EventMonitor
//
//  In:REFIID riid -  Reference id
//
//  Out:LPVOID FAR* ppv
//
//  Comments:		
/////////////////////////////////////////////////////////////////////
STDMETHODIMP EventMonitor::QueryInterface(REFIID riid, LPVOID FAR* ppv)
{
 	PgpGwTrace("EventMonitor::QueryInterface\n");
	if(NULL == ppv)
		return E_INVALIDARG;

   *ppv=NULL;


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

	if(IID_IDispatch == riid)
	{
		if (NULL == m_pIUnkDispFact)
		{
			m_pIUnkDispFact = BuildIUnkDispatch(LIBID_PgpGwTypeLibrary,
				IID_IEventMonitor, (IUnknown *)(IEventMonitor *)this,
				(void *)(IEventMonitor *)this);
		}

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

	return E_NOINTERFACE;
}


///////////////////////////////////////////////////////////////////////
//	 Name:EventMonitor::Notify
//
//   Description: This interface is passed to monitor "low level" 
//				  actions that occur in GW. Such as:
//     eGW_CMDEVTID_NEWMESAGE = Indicates that an item has been delivered
//                to the GroupWise mailbox.
//	   eGW_CMDEVTID_ONREADY = This notification occurs during the GroupWise
//                initialization procedure, just after GroupWise is 
//				  initialized. The following services are running at the 
//				  time this method is called: DDE server OLE objects 
//				  registered and placed in the COM running object table
//
//	   eGW_CMDEVTID_ONSHUTDOWN = Simply a notification to the C3PO server
//                that shutdown is occurring.  System services are still 
//				  available when this notification is received. Immediately 
//				  after returning from this method call, however, the C3PO
//                should assume that the calling client has shutdown.  If 
//				  the calling client is the last client to use the C3PO 
//				  manager, calls to the manager will fail after this call
//                has returned.
//
//   In:Context: string - Class of the object
//                evt: variant - Is an GWEvent. The GwEvent object defines 
//				  an instance of an event.It is subclassed by GWClientState. 
//				  For more information see the documentation.
//
//   Out:none
//
//   Comments:
//
/////////////////////////////////////////////////////////////////////////
STDMETHODIMP EventMonitor::Notify(THIS_ BSTR bstrContext, IDispatch * pIDispGWEvent)
{
	PgpGwTrace("EventMonitor::Notify (%S)\n", bstrContext);
	IGWEvent *pIEvent=NULL;
	HRESULT	hrRet=S_OK;
	BSTR bstrPersistentID=NULL;
	TCHAR *ptszBuf=NULL;
	int	iResult=0;

	//this should be always in the client context
	pgpAssert(0 == _wcsicmp(bstrContext, CLIENTCONTEXTW));

	hrRet=pIDispGWEvent->QueryInterface(IID_IGWEvent, (void**)&pIEvent);
	if(FAILED(hrRet) || (NULL == pIEvent))
	{
		pgpAssert(FALSE);
		goto cleanup;
	}

    hrRet = pIEvent->get_PersistentID(&bstrPersistentID);
	if(FAILED(hrRet) || (NULL == bstrPersistentID))
	{
		pgpAssert(FALSE);
		goto cleanup;
	}

	ptszBuf = FROM_OLE_STRING(bstrPersistentID);
	pgpAssert(NULL != ptszBuf);
	if(NULL == ptszBuf)
	{
		pgpAssert(FALSE);
		hrRet=E_FAIL;
		goto cleanup;
	}

	//if it is the onready event
	if (strcmp(ptszBuf, eGW_CMDEVTID_ONREADY) == 0)
	{
		hrRet=CoInitialize(NULL);
		pgpAssert(SUCCEEDED(hrRet));
		if(FAILED(hrRet))
			goto cleanup;

		pgpAssert(NULL == g_pigwcCommander);
		hrRet= CoCreateInstance(CLSID_GWCommander,NULL,CLSCTX_LOCAL_SERVER,
				IID_IGWCommander,(LPVOID *)&g_pigwcCommander);
		pgpAssert(SUCCEEDED(hrRet) && (NULL != g_pigwcCommander));
		if(FAILED(hrRet) || (NULL == g_pigwcCommander))
			goto cleanup;

		pgpAssert(NULL == g_bstrValidateCmd);
		g_bstrValidateCmd=A2WBSTR("ItemMessageIDFromView()");
		pgpAssert(NULL != g_bstrValidateCmd);
		if(NULL == g_bstrValidateCmd)
		{
			hrRet=E_OUTOFMEMORY;
			goto cleanup;
		}

		hrRet=InitPGP();

	}
	//else if it is the shutdown event
	else if (strcmp(ptszBuf, eGW_CMDEVTID_ONSHUTDOWN) == 0)
	{
		pgpAssert(NULL != g_pigwcCommander);
		if(NULL != g_pigwcCommander)
		{
			g_pigwcCommander->Release();
			g_pigwcCommander=NULL;
		}

		CoUninitialize();

		pgpAssert(NULL != g_bstrValidateCmd);
		if(NULL != g_bstrValidateCmd)
		{
			SysFreeString (g_bstrValidateCmd);
			g_bstrValidateCmd=NULL;
		}
	}
	
cleanup:
	if(NULL != bstrPersistentID)
	{
		SysFreeString(bstrPersistentID);
		bstrPersistentID=NULL;
	}

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

	if(NULL != ptszBuf)
	{
		FREE_OLE_STRING(ptszBuf);
		ptszBuf=NULL;
	}

	return S_OK;
}

STDMETHODIMP EventMonitor::InitPGP()
{
	HRESULT hrRet=S_OK;
	PGPError pgpErrRet=kPGPError_NoErr;

	pgpAssert(NULL == g_pgpContext);
	if(NULL != g_pgpContext)
		return S_OK;

	pgpErrRet = PGPclInitLibrary(&g_pgpContext, kPGPclEnableNewUserWizard);
	if (IsPGPError(pgpErrRet))
	{
		if (pgpErrRet == kPGPError_FeatureNotAvailable)
			DisplayMessage(NULL/*hwnd*/, IDS_E_EXPIRED);
		else
			PGPclErrorBox(NULL/*hwnd*/, pgpErrRet);

		PGPclCloseLibrary();
		g_pgpContext=NULL;
		return S_FALSE;
	}
	
	//check for beta/demo expiration. this call shows the user a dialog
	//that lets her know that the grace period is over she need to renew
	PGPlnLicenseCheck (g_pgpContext);
	pgpErrRet=PGPlnIsExpired(NULL/*hwnd*/, kPGPlnModuleGraceExpiration);
	if (IsPGPError(pgpErrRet))
	{
		//should be because the license has expired
		pgpAssert(kPGPError_Win32_Expired == pgpErrRet);

		//remember that plug in has expired. we use this value
		//to disable commands subsequently. note if there is a 
		//failure return other than expired we still consider
		//the plugin to have expired
		g_bPlugInExpired = TRUE;

		//cleanup
		PGPclCloseLibrary();
		g_pgpContext=NULL;
		return S_FALSE;
	}
	
	return S_OK;
}



⌨️ 快捷键说明

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