【发布时间】:2012-09-06 08:45:23
【问题描述】:
我为我们无法控制的第 3 方 DLL 定义了以下函数:
const
DLL = 'Qarapea.dll';
function QARapid_Open(IniFile: shortstring; Section: shortstring): integer; stdcall; external DLL;
procedure QARapid_EndSearch(); stdcall; external DLL;
function QARapid_Count: integer; stdcall; external DLL;
function QARapid_Search(vs: shortstring): integer; stdcall; external DLL;
function QARapid_FormatAddr(ItemNumber: integer; Buffer: PAnsiChar; BufferSize: integer): integer; stdcall; external DLL;
procedure QARapid_Close; stdcall; external DLL;
我通过以下方式调用函数:
procedure TFormMain.ButtonStaticLookupClick(Sender: TObject);
var
Res: integer;
ACode: shortstring;
IniFile, Section: shortstring;
begin
try
ACode := PrepareCode(EditCode.Text);
IniFile := ExtractFilePath(ParamStr(0)) + 'DllIni.ini';
Section := 'Default';
QARapid_Open(IniFile, Section);
try
Res := QARapid_Search(ACode);
Res := QARapid_Count;
finally
QARapid_Close;
end;
Except on E: Exception do
MessageDlg(E.Message, mtError, [mbOK], 0);
end;
end;
在我调用QARapid_Count 函数之前,一切似乎都正常,当我收到以下错误时:
QAS.exe 出现错误消息:0x0012eff4 处的特权指令。 进程停止。使用 step 或 run 继续。
由于打开了 CPU 调试窗口,我不知道从哪里开始查找故障。
如何追踪出了什么问题?
【问题讨论】:
-
'QARapid_Open' 的调用约定不同吗?还是复制粘贴错误?
-
您确定您正确翻译了 API 吗?使用 DLL,您无法保证您的标头不会过时或通过其他方式正确。假设您的 DLL 本身是用 C++Builder 或 Delphi 编写的,它可能具有不同版本的 FastMM4,并且当 EXE 和 DLL 尝试合并它们的堆池时 - 会破坏彼此的结构。不过只是推测。希望它不应该是这样的。
-
我的意思是它缺少 stdcall 指令。是故意的吗?
-
另外,什么样的糟糕 DLL 使用短字符串?一个只能从 Delphi 合理调用的 DLL!
-
@PietervanWyk 所以你只是在猜测如何调用这个 DLL?
shortstring不太合适。