在Delphi中通过COM对象使用.NET类有时会挂起 [英] Using .Net classes through COM Objects in Delphi sometimes hangs
问题描述
有时,在重建DLL之后,当我尝试实例化通过COM公开的对象时,Win32应用程序挂起在 CreateComObject
调用。如何解决这个问题?
要通过COM公开Delphi.NET库,我会在每个类减速之后添加以下属性:
[Comvisible(true)]
[Guid('some guid')]
[ClassInterface(ClassInterfaceType.AutoDual)]
编译DLL后,我会生成一个 TLB.pas
文件中,该文件包含DLL中所有公共和COM可见类和接口的定义。这个文件允许我更容易地使用我的Delphi Win32应用程序中的COM对象。最后,我使用 regasm $ c注册
.dll
和 .tlb
$ c>。
我尝试取消注册并运行Win32应用程序,它引用了该DLL;我预计会收到运行时错误,但应用程序再次挂在 CreateComObject()
调用。
我也尝试取消注册和注册DLL,没有任何运气。
ps我使用的是BDS 2006
COM有时可能是一个真正的痛苦,以获得稳定,所以如果不需要,我经常采取anoter路线。
在这种情况下,你可以尝试使用COM反向P / Invoke。
以下是一些可以帮助您的文章:
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
您可以在google上获取更多点击Delphi Inverse PInvoke,但上述都是最好的文章。
亲爱的,
Jeroen Pluimers
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
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
这篇关于在Delphi中通过COM对象使用.NET类有时会挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!