gpt4 book ai didi

delphi - 调用库函数会占用堆栈。为什么?

转载 作者:行者123 更新时间:2023-12-03 15:54:46 25 4
gpt4 key购买 nike

抱歉,可能这对于 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';

动态链接不会改变行为。

最佳答案

好的,我现在有了。抱歉,RTFM 问题可能很简单。我应该使用 cdecl;而不是 stdcall。只希望所有这些 Delphi DLL 链接教程都能在某处提到它。

http://docwiki.embarcadero.com/RADStudio/XE4/en/Procedures_and_Functions

关于delphi - 调用库函数会占用堆栈。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18677947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com