views:

898

answers:

3

I have a set of libraries written in Delphi.NET (.NET 1.1) which I want to use in my Win32 (Delphi) application. For performance related issues, I've decided to follow the COM route.

Sometimes, after rebuilding the DLL, when I try to instantiate the objects exposed through COM the win32 application hangs at the CreateComObject call--how can I solve this problem?

To expose the Delphi.NET libraries through COM, I add the following attributes above each class deceleration:

[Comvisible(true)] [Guid('some guid')] [ClassInterface(ClassInterfaceType.AutoDual)]

After compiling the DLL, I generate a *TLB.pas file, this file contains definition for all public and COM visible classes and interfaces in DLL, this file allows me to more easily use the COM objects in my Delphi Win32 application. Finally, I register the dll and the .tlb flie using regasm.

I've tried unregistering and running the win32 app. which references the DLLS; I expected to receive a run-time error but the application once again hung at the CreateComObject call.

I've also tried unregistering and registering the dll without any luck.

Thanks.

p.s. I am using BDS2006

A: 

Be sure that you shut down the code in a proper manner, and do not just stop it in the debugger. I've found that killing inter-process applications using the debugger can cause all sorts of problems, usually needing a reboot to clear them away. It takes discipline to do this as normally you can do it without problem.

mj2008
The app. was shutdown properly, I've also tried restarted my machine.
The Alchemist
+1  A: 

I have mixed experiences with COM; COM can sometimes be a real pain to get stable, so if not needed, I often take anoter route.

In this case, you could try to go around COM by using inverse P/Invoke.

Here are a few articles that can help you on this:

http://blogs.codegear.com/timjarvis/2006/11/10/29270 http://www.blong.com/Conferences/BorConUK2002/Interop1/Win32AndDotNetInterop.htm http://www.blong.com/Conferences/BorCon2004/Interop1/Win32AndDotNetInterop.htm

You can gets more hits when you google on "Delphi Inverse PInvoke" but the above ones are the best articles.

Kind regards,

Jeroen Pluimers

Jeroen Pluimers
A: 

Using RemObjects Hydra is an easy way to mix managed and unmanaged Delphi code. But unfortunatly it's quite expensive - $499 :(

Update: try Delphi.Net open source project. This project is inactive, but you can use it for Win32 -> dotNet1.1 assembly interaction.

macropas