Search code examples
c#comtlbimp

Different Results from TLBIMP and AXIMP


I have a ActiveX COM control and its source code. I wanted to change one of the method's input parameter, so I changed the IDL etc and generated the COM DLL and TLB.

But when I imported the COM DLL in a .NET project the method had retained its old signature. So I tried to generate the ActiveX DLL using AXIMP (though it is all the same, I wanted to give a try).

Still the method's signature did not change to what I changed to.

But when I generated the interop DLL using TLBIMP from the TLB file generated, the method signature changed correctly.

Where can I be wrong?

Thanks.


Solution

  • There are a lot of manual steps involved so it easy to miss one. It rather depends on how you imported the type library, there's more than one way to do it. If you picked the reference from the Add Reference + COM tab then the likely mistake is that you forgot to re-register the new COM server. Or you accidentally picked the old one instead of the new one, which can happen when you change the guids, like you should, and forgot to cleanup the old one. Cleaning up is pretty important and easily missed since it needs to be done before you rebuild the COM server. You can end up with a lot of garbage in the registry.

    And yes, using Tlbimp.exe directly is the most reliable way to avoid accidents. Since you run it directly on the type library and don't use the registry at all.

    A recipe for having the least possible amount of trouble could look like this:

    1. Unregister the old COM server first by running regsvr.exe -u
    2. Delete the old DLL and TLB files
    3. Change the IDL to add your new method
    4. Assign a new IID for the interface you changed
    5. Assign a new CLSID for the coclass that uses the interface
    6. Increment the library version
    7. Change the name of the output DLL, favor including the major+minor version in the name
    8. Build the new COM server
    9. Register the server with regsvr32.exe
    10. Run Tlbimp.exe to generate the interop library
    11. Remove the reference to the old interop library in your .NET project
    12. Use Add Reference + Browse to add the new interop library

    Skipping any of these steps can invoke build trouble, registry pollution, DLL Hell and having an all-around lousy wrecked day without getting anything done.