Implementing sink interface in raw C++?
-
Hi guys. I have an ATL module with an outgoing dispinterface. I have no problem implementing an sink interface using MFC or ATL. But now I'm working on a strait C++ project, no MFC and no ATL, where I need to create an sink interface. Could someone give me some hints on how to implement this? All the information I have been able to find assumes that MFC or ATL is beeing used. TIA .Henrik
-
Hi guys. I have an ATL module with an outgoing dispinterface. I have no problem implementing an sink interface using MFC or ATL. But now I'm working on a strait C++ project, no MFC and no ATL, where I need to create an sink interface. Could someone give me some hints on how to implement this? All the information I have been able to find assumes that MFC or ATL is beeing used. TIA .Henrik
Since sink interfaces are dispinterfaces, you will have to implement IDispatch on your object. This also implies you'll have to implement IUnknown, since IDispatch is derived from it. Your version of the Invoke method will basically switch on the dispid of the event, unpack the event parameters from the DISPPARMS struct, and delegate to whatever method you want to be invoked when the event is fired. You will also need code for advising and unadvising the connection point. So for IUknown, you need an implementation of QueryInterface, AddRef and Release. For your implementation of IDispatch for the event interface, you can proably take some shortcuts and just implement Invoke, and return E_NOTIMPL from the remaining methods, since the Connection Point would only make use of this method to fire events. Make sure your object is publicly derived from IDispatch. Your implementation for QueryInterface can then just use a static cast of the this pointer to implement QueryInterface. Look at the ATL code that does this for normal objects for an example. Good Luck!