views:

183

answers:

2

I'm following this article to registering SENS events via COM, but I think I'm missing something. I'm calling the SubscribeToEvents method the article says to write, like this:

EventSystemRegistrar.SubscribeToEvents("ManagedSENS EventSubscriber", "ManagedSENS.SensLogonInterop", subscriptionViewerID, this, typeof(SensLogon));

which leads to this method getting called:

private static String GetInterfaceGuid(Type type)
{
    Object[] attributes = type.GetCustomAttributes(typeof(GuidAttribute), true);

    return String.Format("{{{0}}}", ((GuidAttribute)attributes[0]).Value);
}

The problem is, the type there is the SensLogon class they advise writing, but it has no attributes on it, so that method throws an exception. The only attributes, which are, in fact, GuidAttributes, they say to write are on these classes, that have nothing to do with the SensLogon class (at least as far as I can tell):

[ComImport, Guid("4E14FBA2-2E22-11D1-9964-00C04FBBB345")]
class EventSystem { }
[ComImport, Guid("7542E960-79C7-11D1-88F9-0080C7D771BF")]
class EventSubcription { }
[ComImport, Guid("AB944620-79C6-11d1-88F9-0080C7D771BF")]
class EventPublisher { }
[ComImport, Guid("cdbec9c0-7a68-11d1-88f9-0080c7d771bf")]
class EventClass { }

Perhaps I'm missing something here? Was I to derive from these classes or something? The SensLogon class is shown, but it doesn't have any of these attributes.

Has anyone done something similar to register with COM events, or can, perhaps, see where I've followed the article improperly?

+1  A: 
tommieb75
Thanks. I'll be sure to catch that and other exceptions as well.
Mike Pateras
A: 

I figured it out. I was passing typeof(SensLogon) into EventSystemRegistrar.SubscribeToEvents, when I should have been passing typeof(ISensLogon) (ISensLogon does indeed have a GuidAttribute on it). Silly me.

Mike Pateras