Apparently there is a bug in TLBIMP which means that, under certain circumstances, the interop DLL that it generates won’t support events properly. This is probably a well-known issue that everyone except me knows about, but I didn’t find too much about it on Google.
For example, capturing events from Windows Messenger doesn’t work by default and you need to take the following steps:
- Use Tlbimp.exe to generate a Messenger interop assembly (this is located in C:Program FilesMessenger by default):
tlbimp msmgs.exe /out:Messenger.dll
- Disassemble the interop assembly, and then save it as an IL file:
ildasm /text Messenger.dll /out:Messenger.il
- Open the IL file in any text editor, and then change the following line (mark the class as public instead of private):
.class private auto ansi sealed DMsgrObjectEvents_SinkHelper
.class public auto ansi sealed DMsgrObjectEvents_SinkHelper
and just below that
.class private auto ansi sealed DMsgrObjectEvents_EventProvider
.class public auto ansi sealed DMsgrObjectEvents_EventProvider
- Compile the IL file:
ilasm /dll Messenger.il
- This DLL is now ready to be referenced in a project.