views:

55

answers:

0

I've wrote a Interop Assembly for a COM library. Everything was fine, except when I've tried to support events. This is my coClass definition:

   coclass NetCustomWatcher
    {
     [default] interface INetCustomWatcher;
     [default, source] dispinterface _INetCustomWatcherEvents;
    };

It's pretty simple.

I read a lot of articles and everyone said that I need to add an event to the managed class (NetCustomWatcherClass), but this class must be defined with ComImportAttribute. If I don't define it with this attribute a Security Exception is raised when I try to access it. But If I add the ComImportAttribute I cannot define only extern and abstract members!

I've dissasemblied the interop assebly generated by tlimp, and I've got the following definition:

[ComImport, ClassInterface((short) 0), ComSourceInterfaces("NetWatcherLib._INetCustomWatcherEvents\0"), Guid("2933B2A9-3A60-4FD7-870F-72C499700E97"), TypeLibType((short) 2)]
public class NetCustomWatcherClass : INetCustomWatcher, NetCustomWatcher,
 _INetCustomWatcherEvents_Event
        {
            // Events
            public event _INetCustomWatcherEvents_OnValueChangeEventHandler OnValueChange;
        ...

which does not compile in VS2008

So, What is the correct way to support Connection Points? I would appreciate any guidance on this subject.

Thanks in advance.