Search code examples
c#.netcomhookcode-generation

Changing the behavior of a COM object


I have a somewhat complex library (something.dll) that I can use via COM. This library is unmanaged. Among other things, this library connects to a system and allows me to communicate with it.

I have a lot of .NET (managed) applications that use this library. Because the way the library communicates with the system is deprecated, I would like to change the behavior of this library without touching the .NET applications.

One of my approaches is to hook COM calls, but I've had a lot of fights with this (e.g. I can intercept some calls but when returning from the hook function it seems that only nulls are received), so I was wondering if I could just "mock" the library.

In other words, is there some tool that I can use that will analyze the library (like as VS Object Browser) and generate all the stubs needed so that I can just change the way it communicates and fill by myself all properties and implement all the methods by myself? Or any other idea to solve the problem?

Cheers


Solution

  • You could try creating a new project that contains a class which instantiates your COM object. Expose it to COM with the same GUID. Then you'd just change and expose the methods as necessary and deploy the new DLL.

    Not sure where you'd stand with the existing DLL after that - can it's GUID be regenerated?