我正在用 C++ 创建一个用于 Delphi 7 项目的 DLL,这个 DLL 将使用 OpenMP 并将替换项目中已经存在的一些方法,这是为了有望加快应用程序的速度。
其中一个函数是这样定义的:
function ReplaceFunction(chain:String;functionTE:TEFunction):string;
对象 functionTE
是这样声明的,
TEFunction = class(TObject)
private
FFunctionName: string;
procedure SetFunctionName(const Value: string);
function GetFunctionNameCapital: string;
public
Handle:THandle;
Funcion:Pointer;
FileName:string;
ParamNumber:integer;
Description:string;
property FunctionNameCapital:string read GetFunctionNameCapital;
property FunctionName:string read FFunctionName write SetFunctionName;
end;
如何将此类的对象传递给 dll 并使用它?
最佳答案
How can I pass an object of this class to the dll and use it?
你不能。只有 Delphi 代码可以使用 Delphi 类。即便如此,也只有使用相同运行时实例的代码。这需要运行时包。
您需要以互操作友好的方式公开功能。普通 C 风格函数或 COM 风格接口(interface)都是显而易见的选择。
而且您不仅不能传递该对象,而且还不得尝试跨互操作边界使用 Delphi native 字符串。同样,您需要使用互操作友好的类型。对于字符串,这包括 C 字符串(以 null 结尾的字符数组)和 COM BSTR
。
关于c++ - 如何将对象从 Delphi 7 传递到 C++ dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22153645/