Using .Net classes through COM Objects in Delphi s

2019-07-21 07:47发布

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 definitions for all public and COM visible classes and interfaces in the 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 DLL; 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.

p.s. I am using BDS 2006

3条回答
Root(大扎)
2楼-- · 2019-07-21 08:28

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.

查看更多
smile是对你的礼貌
3楼-- · 2019-07-21 08:36

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.

查看更多
干净又极端
4楼-- · 2019-07-21 08:48

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

查看更多
登录 后发表回答