Hi!
I'm currently working on implementing events to an existing COM interface. The interface use connection points to send the events and it's all generated using the built in generators of Visual Studio 2010.
I use Python and the win32com extension to hook up with the application and the COM interface. Calling methods work fine and I can even receive events when I send them on method requests.
My problem is that I can't figure out how to send events from the application to the client without making a method request from the client. I wan't the user to be able to start OperationX using method "StartOperationX" form the interface. This operation will take some time and the user can continue using other functionality. When OperationX is finished I want to send the event "OperationXCompleted" to the client from the application.
If I send "OperationXCompleted" in the "StartOperationX" method everything works fine and I receive the event. This means the connection between server and client works fine using the normal method calls.
Some code:
IDL file:
interface IInterfaceClass: IDispatch { [id(1))] HRESULT OperationX(); }; dispinterface IInterfaceClassEvents { properties: methods: [id(1), helpstring("event ExecutionOver")] HRESULT OperationXCompleted(); };
InterfaceClass.h:
class ATL_NO_VTABLE CInterfaceClass: public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CInterfaceClass, &CLSID_InterfaceClass>, public IConnectionPointContainerImpl<CInterfaceClass>, public CProxyInterfaceClassEvents<CInterfaceClass>, public IDispatchImpl<IInterfaceClass, &IID_IInterfaceClass, &LIBID_InterfaceClassLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
InterfaceClass.CPP:
STDMETHODIMP CInterfaceClass::SendOperationXCompleted() { AFX_MANAGE_STATE(AfxGetAppModuleState()); Fire_OperationXCompleted(); return S_OK; }
I tried an ugly hack simply saving the "this" object in the CInterfaceClass constructor just to see if I could successfully send an event from the application:
static CInterfaceClass * temp; CInterfaceClass() { temp= (CInterfaceClass*)this; } temp->SendOperationXCompleted()
When calling CInterfaceClass->SendOperationXCompleted() from the static object the logic seem to work well (it will find a connection) but the client never receive the event. I guess that's because I am "cheating".
I'm very grateful for any help or idea to solve this!
Best regards,
Petter Gustafsson