3
votes

I have developed a COM library in Delphi. When I try to "add reference" in a Visual Studio project, VS crashes. I tried to build Interop assembly by tlbimp.exe and it failed with:

TlbImp : error TI1000 : The type library importer encountered an unexpected exception: System.AccessViolationException - Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Interestingly when I "add reference" to a Web Application (or a Web Site) project, it successfully generates Interop dll and adds the reference.

It is important to me to know how tlbimp.exe is employed by Web Application project because I want to customize Interop generation.

1
Try the open-source TlbImp, you can debug it: clrinterop.codeplex.com/releases/view/17579 - noseratio
@Noseratio It was a good idea. I debugged down the code and found an access violation when TlbImp tries to retrieve a function description using a function DISPID. I didn't have enough time to exactly spot the problem but possibly it's a bug in TlbImp. - Bahribayli
I guess the best thing you could do (besides reporting a bug) is to try to change the interface of your Delphi component, so it doesn't upset TlbImp. - noseratio
@Noseratio I will report the bug as soon as I gather enough information to reproduce the bug. The problem occurs just for one CoClass. Other interfaces and CoClasses are well. - Bahribayli

1 Answers

1
votes

There is most likely an error in your Delphi code. You can debug the COM library in Delphi like so:

enter image description here Choose run-> parameters...

enter image description here

(Never mind the fact that this says project28.exe; it works the same for Projectx.dll)

I commonly develop plugins for Excel using COM.
In that case my host application is Excel.exe.

When you've entered this info you'll be able to run the library.
When you do Delphi will start the host application and wait until it somehow invokes your library.
If you've set any breakpoints Delphi will pause the action and allow you to debug.

Because you know which functions you call in your C# code, it shouldn't be difficult to see where to set the first breakpoint.

Delphi will also break on any exceptions.