如何在Delphi中使用dll导出的C ++类 [英] How to use C++ Classes exported by a dll in Delphi

查看:94
本文介绍了如何在Delphi中使用dll导出的C ++类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在Delphi中使用win32 dll导出的C ++类作为win32?有没有别的方法来处理类似的东西(COM,.NET,...)?

解决方案

类。您只能导入功能。 Rudy Velthuis已经详细介绍了该主题。虽然您不能直接使用导出的C ++类,他描述了几种技术来实现相同的效果:




  • 对平化对象,所以在调用一边没有任何对象,只是一个指针,连同其他参数一起传递给一个包含对象的方法的函数的参数。编写包装很简单,虽然可能很乏味。


  • 使用纯虚拟类。 Windows C ++编译器和Delphi通常具有相同的VMT布局,因此如果可以通过纯虚拟方法列表描述C ++类,则可以创建一个等效的Delphi声明,使用DLL返回的对象指针进行一些类型转换,然后继续。




文章中给出了两种方法的完整示例。


is there a way to use C++ classes exported by a win32 dll in Delphi for win32? Are there other ways to archieve similar things (COM, .NET, ...)?

解决方案

You can't import a class. You can only import functions. Rudy Velthuis has written at length on the topic. Although you can't directly use an exported C++ class, he describes a couple of techniques to achieve the same effect:

  • "Flatten" the object, so on the calling side there is no object anymore, just a pointer that gets passed to the DLL along with other parameters for a series of functions that wrap the object's methods. Writing the wrapper is very simple, although it can be tedious.

  • Use pure virtual classes. Windows C++ compilers and Delphi have generally the same VMT layouts, so if the C++ class can be described by a list of pure virtual methods, you can create an equivalent Delphi declaration, do some type-casting with the object pointer returned by the DLL, and proceed.

Complete examples of both ways are given in the article.

这篇关于如何在Delphi中使用dll导出的C ++类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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