在Delphi中通过COM对象使用.Net类有时会挂起 [英] Using .Net classes through COM Objects in Delphi sometimes hangs

查看:187
本文介绍了在Delphi中通过COM对象使用.Net类有时会挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组用Delphi.NET(.NET 1.1)编写的库,我想在我的Win32(Delphi)应用程序中使用。对于性能相关的问题,我决定按照COM路线。



有时,在重建DLL之后,当我尝试实例化通过COM暴露的对象时,win32应用程序在CreateComObject调用时挂起 - 我如何解决这个问题? / p>

要通过COM公开Delphi.NET库,我在每个类上面添加以下属性减速:





在编译DLL之后,可以使用下面的代码:














我生成一个* TLB.pas文件,这个文件包含所有公共和COM可见类和接口在DLL中的定义,这个文件允许我更容易使用COM对象在我的Delphi Win32应用程序。最后,我使用regasm注册dll和.tlb flie。



我尝试取消注册并运行win32应用程序。参考DLLS;我希望收到一个运行时错误,但应用程序再次挂在CreateComObject调用。



我也试过取消注册和注册dll没有任何运气。 / p>

感谢。



ps我使用BDS2006

解决方案

我有COM的经验; COM有时可以是一个真正的痛苦来获得稳定,所以如果不需要,我经常采取anoter路线。



在这种情况下,你可以尝试去使用COM



这里有一些文章可以帮助您:



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



您在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 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

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆