Apparently there is a bug in TLBIMP which means…

less than 1 minute read

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:

  1. Use Tlbimp.exe to generate a Messenger interop assembly (this is located in C:Program FilesMessenger by default):
tlbimp msmgs.exe /out:Messenger.dll
  1. Disassemble the interop assembly, and then save it as an IL file:
ildasm /text Messenger.dll /out:Messenger.il
  1. 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

to

.class public auto ansi sealed DMsgrObjectEvents_SinkHelper

and just below that

.class private auto ansi sealed DMsgrObjectEvents_EventProvider

to

.class public auto ansi sealed DMsgrObjectEvents_EventProvider
  1. Compile the IL file:
ilasm /dll Messenger.il
  1. This DLL is now ready to be referenced in a project.

Updated: