c++ - 如何将对象从 Delphi 7 传递到 C++ dll?

标签 c++ delphi dll

我正在用 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/

相关文章:

c++ - 使用 C++ 的 Google Cloud 语音 API,第一步是什么?

android - 如何在 Delphi 中禁用显示建议

delphi - Delphi 7 中找不到文件

python - 将多条数据从 Python 传递到 C 程序

C++ 简单 if 语句不检查?

c++ - 使用 C++ 更改 QML 单例的属性

c++ - 预处理器 `_AFXDLL` 是什么意思?

c++ - 将项目添加到 Internet Explorer 的右键单击上下文菜单

C++ 从 8 位位图构建像素数据并访问 bmiColor 表信息

c++ - 如何禁用XE6中的嵌入式设计器?