How do I handle COM events regfree?

203 views Asked by At

I am trying to handle COM events from a C# server to a C++ client. I am able to use the server regfree but my events no longer work.

Previously, with registration, the events were handled in the client via IDispEventImpl from the ATL.

I haven't been able to find any articles directly addressing this but I did see a suggestion that IConnectionPoint does not inherently require registration.

I also saw some suggestion that IDispEventSimpleImpl may work regfree.

1

There are 1 answers

0
Aurora On

IDispEventImpl requires access to a type library. You'll need to include a reference in your server manifest, so that it can be loaded into the activation context:

<file name="mydll.tlb">
    <typelib
        tlbid="{TLBID}"
        version="1.0"
        helpdir=""
        flags="hasdiskimage"/>
</file>

Your client sink needs to be declared with the typelib ID as well:

class CMySink: public IDispEventImpl<1, CMySink, &IID_IEvent, &TLBID, 1, 0>

As an alternative, you can also implement IDispEventSimpleImpl, which works without a type library.