【发布时间】:2013-09-07 21:10:44
【问题描述】:
对不起,这对 Delphi 程序员来说可能也很容易,但对我来说不是。我有一个我正在调用的库函数,基本上它吃掉了我的堆栈。它通过将函数的变量推入堆栈来做到这一点,但不知何故,Delphi 不会将它们从堆栈中弹出。所以在函数结束后,我无处可去。有趣的是,我只要有参数就可以做“pop eax”,而且它可以工作。任何人都可以阐明发生了什么吗? 工作代码如下:
function LoadIntoMemory(sdiPath: String): Integer;
var
retValue: Integer;
begin
retValue := file_open(PAnsichar(AnsiString(sdiPath)), @filedata, @filedatasize);
asm
pop eax
pop eax
pop eax
end;
end;
如前所述,不从堆栈中弹出它就会崩溃。
函数本身来自一个 C DLL,静态链接如下:
function file_open (filename: PAnsichar; filedata: PPAnsichar; filedatasize: PLongInt): Integer; stdcall; external 'libLib';
动态链接不会改变行为。
【问题讨论】:
-
我会尝试“cdecl”。不确定它会有所帮助,因为变量的顺序会改变。
标签: delphi crash stack delphi-xe3