c++ - Delphi 访问冲突调用实现接口的 C++ DLL
问题描述
为了在 Delphi 中导入 DLL,我编写了一个翻译 .h 文件的单元。这个 DLL 允许我定义一个过程来监视两个值并在我的应用程序中使用它们。
原始 .h 文件是:
class MyINTERFACE
{
public:
virtual void MonitorProc(int value1, int value2) = 0;
};
extern MY_API MyHANDLE* Init();
extern MY_API UINT InitMonitorProc(MyHANDLE * handle, MyINTERFACE * pMyProc);
这是我的翻译:
unit myCdllUnit;
interface
const
TMyHANDLE = DWORD;
MyINTERFACE = class
public
procedure MonitorProc(value1: longint; value2: longint); virtual; cdecl; abstract;
end;
function Init(): TMyHANDLE; cdecl; external 'myCdll.dll';
function InitMonitorProc(handle: TMyHANDLE; pMyProc: MyINTERFACE):DWORD; cdecl; external 'myCdll.dll';
implementation
end.
在我的主要形式中,我覆盖了 MonitorProc(最初仅使用“继承”来测试调用)
TMyMonitor = class(MyINTERFACE)
public
procedure MonitorProc(value1: longint; value2: longint); override;
end;
procedure TMyMonitor.MonitorProc(value1: longint; value2: longint);
begin
inherited;
end; <--------------------------- here get an Access Violation
在我的 FormCreate 中,我将一个 istance 传递给 InitMonitorProc
MyMonitor := TMyMonitor.Create;
InitMonitorProc(Handle, MyMonitor);
DLL 调用正确但退出 MonitorProc 我收到访问冲突错误。我哪里错了?
解决方案
推荐阅读
- java - 当我使用事件输入切换意图时,用户存储变得清晰
- sparql - Jena 似乎缓存了 BIND(RAND()) 查询
- generics - 将泛型从 Java 转换为 Kotlin
- angularjs - AngularJS服务功能在while循环完成后没有返回完整的承诺
- svelte - 如何像 Vue 一样在 Svelte 中制作无标签插槽模板
- vue.js - 如何向 v-data-table 添加点击事件?
- c# - 旋转 UILabel 的拉伸宽度
- python - 根据 MultiIndex DataFrame 中的第一级列删除重复项
- buildkite - 如何在 buildkite 中为存储库/管道级别添加访问控制?
- java - 错误:SqlExceptionHelper:HOUR_OF_DAY:2 -> 3