Embed the source interface in your code (using any mechanism, including, possibly, generating simple C code using the midl compiler). In your external library (the one you consume). Look at the interface, which looks like this:
[source] interface IOutGoing;
After you have implemented it, register it using the Advise object that sends events (unregister using Unadvise )
Here is a snippet that shows typical usage, assuming you have taken the MIDL path (with ATL / MFC you will have to write less code, but know more macros / templates)
class CSink : public IOutGoing { public: // IUnknown ULONG __stdcall AddRef(); ULONG __stdcall Release(); HRESULT __stdcall QueryInterface(REFIID riid, void** ppv); // IOutGoing HRESULT __stdcall GotMessage(int Message); CSink() : m_cRef(0) { } ~CSink() { } private: long m_cRef; }; IUnknown* pUnknown; CoCreateInstance(CLSID_XXXXXXXXX, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown); IConnectionPointContainer* pConnectionPointContainer; hr = pUnknown->QueryInterface(IID_IConnectionPointContainer, (void**)&pConnectionPointContainer); hr = pConnectionPointContainer->FindConnectionPoint(IID_IOutGoing, &pConnectionPoint); // Instantiate the sink object. CSink* mySink = new CSink; // Give the connectable object a pointer to the sink. DWORD dwCookie; pConnectionPoint->Advise((IUnknown*)mySink, &dwCookie);
sehe
source share