如何在Delphi中使用dll导出的C ++类

编程入门 行业动态 更新时间:2024-10-27 06:19:12
本文介绍了如何在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 ++类

本文发布于:2023-06-10 18:30:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616412.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Delphi   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!