PowerPoint events in COM dll

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Can anyone tell me how to handle PowerPoint events in a COM dll? It works fine for a exe. But it doesnt work with a COM dll. Please help me out

Thanks.
 
Ok. Here is it. The following code is from EventController.cpp which creates Application object interface and waits for events

///*********************** Start of code to get connection point *************
// Declare the events that you want to catch
//
// Look for the coclass for Application in the Msppt9.olb typelib
// then look for the word "source." The EApplication interfac
// is the next search target. When you find it, you will see the
// following GUID for the event interface
// 914934C2-5A91-11CF-8700-00AA0060263
static const GUID IID_IEApplication
{0x914934C2,0x5A91,0x11CF, {0x87,0x00,0x00,0xAA,0x00,0x60,0x26,0x3b}}


// Steps for setting up events
// 1. Get the IConnectionPointContainer interface of the server
// 2. Call IConnectionPointContainer::FindConnectionPoint(
// to find the event that you want to catch
// 3. Call IConnectionPoint::Advise() with the IUnknow
// interface of your implementation of the events

tr

HRESULT hrReturn
COleException oleException

if(!g_pptApplication.CreateDispatch(POWERPOINT_PROGRID,&oleException)

AfxMessageBox("Could not create Powerpoint object.")
return false


// Get the (PPT) IConnectionPointContainer interface of the server
IConnectionPointContainer *pConnPtContainer
hrReturn = g_pptApplication.m_lpDispatch->QueryInterface
IID_IConnectionPointContainer
(void **)&pConnPtContaine
)
if(FAILED(hrReturn))

DISPLAY_ERROR("LaunchAndEstablish","Couldn't get IConnectionPointContainer interface.")
return false

ASSERT(!FAILED(hrReturn))

// Find a connection point for the events that you are interested in
hrReturn = pConnPtContainer->FindConnectionPoint
IID_IEApplication
&g_pConnectionPoin
)
if(FAILED(hrReturn))

DISPLAY_ERROR("LaunchAndEstablish" ,"Couldn't find connection point via event GUID.")
return false

ASSERT(!FAILED(hrReturn))

//Instantiate the sink object
g_pEventsSink = new CPBTEventsHandler()


// Get the IUnknown interface of your event implementation
LPUNKNOWN pUnk = NULL
pUnk = g_pEventsSink->GetInterface(&IID_IUnknown)
ASSERT(pUnk)

// Setup advisory connection
hrReturn = g_pConnectionPoint->Advise(pUnk, &g_pEventsSink ->cookie);
ASSERT(!FAILED(hrReturn));

// Release the IConnectionPointContainer interface
pConnPtContainer->Release()



In the PBTEventsHandler.cpp, the following code is there which is supposed get the event notication.

BEGIN_DISPATCH_MAP(CPBTEventsHandler, CCmdTarget
DISP_FUNCTION_ID(CPBTEventsHandler,"WindowSelectionChange",2001,WindowSelectionChange,VT_EMPTY, VTS_DISPATCH
END_DISPATCH_MAP(

//The GUUID is different from the one originally generated by Class Wizard. This GUUID is the same as the one for the EApplication outgoing event interface
static const IID IID_IMyPPTEventsHandler
{0x914934C2,0x5A91,0x11CF, {0x87,0x00,0x00,0xAA,0x00,0x60,0x26,0x3b}}

BEGIN_INTERFACE_MAP(CPBTEventsHandler, CCmdTarget
INTERFACE_PART(CPBTEventsHandler, IID_IMyPPTEventsHandler, Dispatch
END_INTERFACE_MAP(

In windowselectionchange event handling function

void CPBTEventsHandler::WindowSelectionChange(LPDISPATCH Pres

TRACE("WindowSelectionChange")

if(g_bSuspend) // table is being created. windowselectionchange should be
return; // deactivated
Selection seleCurrent(Pres)
seleCurrent.GetType(
..................


This code is taken from a exe. The same code is used even to work with a dll. Please help me out how can I do this

Thanks in advance
 
Back
Top