0

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?

Mike Pateras
  • 14,715
  • 30
  • 97
  • 137
  • Please don't make us guess at the exception. – Hans Passant Feb 15 '10 at 23:12
  • You did read up on http://www.codeproject.com/KB/cs/subscriptionviewer.aspx? – t0mm13b Feb 15 '10 at 23:32
  • The type of the exception isn't important, but it's an IndexOutOfRange exception, because there are no attributes of type GuidAttribute. The lack of those attributes is the problem, not the exception that results. I did look at that article, but it's scope seems to go well beyond what I'm trying to do, it's far more complex. I'm not sure what to apply to what I'm currently doing. Here are the two classes I've written: http://codepaste.net/x3xfsj and http://codepaste.net/khdefj if that clears up what I might be missing at all. – Mike Pateras Feb 16 '10 at 00:18
  • Mike can you repost your snipit codepaste.net/x3xfsj as the original one you posted isn't working. I've been working to follow the same article you followed [this link][1] and i'm not having much luck. I'd really like to have a good SENS dll that I can use for several projects I'm working on. Any help you could provide would be appreciated. Alternatively, if you've updated your code since your original posting of this article, I'd be interested to see the new version. [1]: http://richardarthur.sys-con.com/node/105651/mobile –  Feb 20 '11 at 05:22
  • Here you go: http://codepaste.net/nijc71 and http://codepaste.net/2t28bw. I hope it helps! – Mike Pateras Feb 20 '11 at 15:43

2 Answers2

1

I think your code is unsafe, because you're assuming the call to type.GetCustomAttributes(...) worked without checking....I would wrap this in a try/catch block to see what's happening...and inspect the exception...

private static String GetInterfaceGuid(Type type) 
{ 
    string sGuid = string.Empty;
    try{
        Object[] attributes = type.GetCustomAttributes(typeof(GuidAttribute), true); 
        if (attributes != null && attributes.Length >= 1){
           sGuid = String.Format("{{{0}}}", ((GuidAttribute)attributes[0]).Value); 
        }else{
           // FAIL!
        }
    }catch(System.Exception up){
        throw up;
    }
    return sGuid;
} 

Did the ess.dll get registered at all? You may have to register it manually? Check the registry for those class id's under HKEY_CLASSES_ROOT, look at the typelib id...if they are not there then issue this regsvr32 ess.dll where-ever the dll file is located in the current folder.

Hope this helps, Best regards, Tom.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
0

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
  • 14,715
  • 30
  • 97
  • 137