Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <OleAuto.h>
- #include <OCIdl.h>
- #include <stdio.h>
- IID iid_events;
- class EventSink : IDispatch {
- // Inherited via IDispatch
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppvObject) override
- {
- if (riid == IID_IUnknown || riid == IID_IDispatch || riid == iid_events) {
- *ppvObject = (void*)this;
- return S_OK;
- }
- return E_NOTIMPL;
- }
- virtual ULONG STDMETHODCALLTYPE AddRef(void) override
- {
- return 0;
- }
- virtual ULONG STDMETHODCALLTYPE Release(void) override
- {
- return 0;
- }
- virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT * pctinfo) override
- {
- return E_NOTIMPL;
- }
- virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo ** ppTInfo) override
- {
- return E_NOTIMPL;
- }
- virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR * rgszNames, UINT cNames, LCID lcid, DISPID * rgDispId) override
- {
- return E_NOTIMPL;
- }
- virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS * pDispParams, VARIANT * pVarResult, EXCEPINFO * pExcepInfo, UINT * puArgErr) override
- {
- return E_NOTIMPL;
- }
- };
- int main()
- {
- IRunningObjectTable *prot;
- IMoniker *pmon;
- IUnknown *punk;
- IConnectionPointContainer *pcpc;
- IConnectionPoint *pcp;
- DWORD cookie;
- HRESULT hr;
- EventSink sink;
- IIDFromString(L"{9009311a-c0b2-42a4-8e7c-f42091d71594}", &iid_events);
- CoInitialize(NULL);
- GetRunningObjectTable(0, &prot);
- CreateFileMoniker(L"comTestApp", &pmon);
- prot->GetObjectW(pmon, &punk);
- punk->QueryInterface(IID_IConnectionPointContainer, (void**)&pcpc);
- hr = pcpc->FindConnectionPoint(iid_events, &pcp);
- hr = pcp->Advise((IUnknown*)&sink, &cookie);
- printf("%x", hr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement