类。您只能导入功能。 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 ++类
发布评论