开发者

How to Register Sink Object for SENS Events

开发者 https://www.devze.com 2023-02-15 01:09 出处:网络
I\'m looking at MSDN documentation that says I can CoCreateInstance a SENS object using its CLSID.However, it is not clear if __uuidof(SENS) means anything - since it is just a forward declaration in

I'm looking at MSDN documentation that says I can CoCreateInstance a SENS object using its CLSID. However, it is not clear if __uuidof(SENS) means anything - since it is just a forward declaration in the Sensevts.h file. Furthermore, the SENS class only offers "outgoing" interfaces, and is labeled "noncreateable" (as viewed through MS Com Viewer) which leaves me not knowing how to refer to an instance of the SENS object itself.

This contrasts with sample code for getting an instance of IShellLink:

HRESULT     hr;
IShellLink* pISL;

hr = CoCreateInstance ( CLSID_ShellLink,         // CLSID of coclass
                    NULL,                    // not used - aggregation
                    CLSCTX_INP开发者_如何学JAVAROC_SERVER,    // type of server
                    IID_IShellLink,          // IID of interface
                    (void**) &pISL );        // Pointer to our interface pointer

Here ShellLink was referred to as "IShellLink." Fair enough. But what type (besides void*) should I use to to receive the instance of SENS? And besides the CLSID problem, what about the IID I'm meant to use for SENS? Ultimately I want to work with the IID_ISensLogon interface of SENS, but because it is an outgoing interface, I can't imagine it makes sense to use that here. Presumably I need to talk to the IConnectionPointContainer interface of SENS (assuredly it implements that, right?) so that I can get to ISensLogon.

In short, could someone show me what the sample code would look like so that I can get to the point where I can call "Advise()" and start receiving events from SENS?

UPDATE I'm making some progress, so that my code now looks like this:

#import <es.dll>
#include <EventSys.h>
using namespace EventSystemLib;

//...
::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
do {

    IEventSystemPtr evSystem;
    HRESULT hr = evSystem.CreateInstance(CLSID_CEventSystem);
    if (!SUCCEEDED(hr)){
        break;
    }

    IEventSubscriptionPtr evSubscriber;
    hr = evSystem.CreateInstance(CLSID_CEventSubscription);  
    if (!SUCCEEDED(hr)){
        break;
    }

}while (false);

The problem is that the creation of CLSID_CEventSubscription fails with HRESULT code E_NOINTERFACE. Online docs for that error suggest I'm using the wrong threading model. But I've tried both COINIT_MULTITHREADED and COINIT_APARTMENTTHREADED and neither changes the error. Any thoughts?

Incidentally, the closest thing I've seen to a working example is given in this link.


According to other parts of MSDN, you don't create a SENS object. If I'm reading this right, you create an instance of IEventSystem (CLSID_CEventSystem), query it for the SENS publisher / event classes of interest, and register your subscription with them.

Edit: For your new problem, I'm unsure of the root cause, however I've found that switching away from using IEventSubscriptionPtr seems to work:

    // Works
    CComPtr<::IEventSubscription> pSub2;
    hr = pSub2.CoCreateInstance(CLSID_CEventSubscription);

    // Doesn't work
    IEventSubscriptionPtr evSubscriber;
    hr = evSystem.CreateInstance(CLSID_CEventSubscription);  


NonCreateable objects are not designed for callers to create instances of. Usually this is because the object wouldn't make sense on its own. Imagine, for example, a cell subobject of an Excel spreadsheet. Callers can't CoCreateInstance a cell as it makes no sense outside of a spreadsheet. However, a caller can ask the spreadsheet for a pointer to a cell object.

I believe SENS is the same. The (really poor) documentation says something about subscribing to events via the Event System object CLSID_CEventSystem. This is where you need to start looking.


Sorry this is an answer, can't comment yet.

You have a mistake in your code, which is why you're getting E_NOINTERFACE

 // Doesn't work
IEventSubscriptionPtr evSubscriber;
hr = evSystem.CreateInstance(CLSID_CEventSubscription);  

Should be:

IEventSubscriptionPtr evSubscriber;
hr = evSubscriber.CreateInstance(CLSID_CEventSubscription); //Wrong object previously
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号