【发布时间】:2010-12-12 04:16:13
【问题描述】:
我在 C++ 程序中有一个抽象类,看起来像
class Interface {
virtual void blah() = 0;
virtual int asdf() = 0;
};
并且该 C++ 程序允许您使用 LoadLibrary 加载 DLL。加载 DLL 时,它使用 GetProcAddress 调用 DLL 中称为 Setup 的函数,并将指向 Interface 子类的指针作为参数传递。
我有一个 Delphi DLL 模仿该类并像这样公开 Setup 函数:
type
Interface = class abstract
procedure blah(); virtual; abstract;
function asdf() : Integer; virtual; abstract;
end;
function Setup(I : Interface) : Integer; export; cdecl;
begin
Result := 0;
end
exports Setup;
但是当程序调用该函数时,它就崩溃了。如果我将功能设置更改为:
function Setup(I : Pointer) : Integer; export; cdecl;
它工作正常并且不会崩溃,但我当然不能就这样离开它,我需要能够使用该类。谁能告诉我我做错了什么?
【问题讨论】:
-
我不知道如何解决您的问题,因为我不太使用(也不关心?)调用约定。但我要说的是,看起来你在修改你的调用约定方面走在了正确的轨道上。您可能想为您的 C++ 接口更改它。
-
我无法控制 C++ 代码,只有 delphi。
-
您真的完全无法控制 C++ 代码吗?你甚至不能向 C++ 开发人员抱怨他们搞砸了,然后要求他们修复它?这不好。
标签: c++ delphi function dll crash