gpt4 book ai didi

delphi - FASM - 将字符串传递给 Delphi DLL

转载 作者:行者123 更新时间:2023-12-03 18:03:18 26 4
gpt4 key购买 nike

我有一个使用以下代码在 Delphi XE2 中编码的 dll:

procedure xMain(MSG:String);export;
begin
MessageBox(0,PWideChar(MSG),'Title',0);
end;

exports xMain;

现在,我在 FASM 应用程序中导入此函数,如下所示:

library  dllfile, "testdll.dll"

import dllfile,\
xMain, "xMain"

利用是这样的:

section ".data" data readable writeable

szMSG db "Message from FASM application!",0

section ".code" code readable executable

invoke xMain,szMSG

但是生成的消息框显示的字符是这样的:

enter image description here

这是函数调用的确切结果。

我该如何解决这个问题?

最佳答案

这里有两个工作示例(使用适用于 Windows 的 FASM 1.70.03):

安西版,
动态链接库:

library testdll;

uses
windows;

procedure xMain(MSG: PAnsiChar); export; stdcall;
begin
MessageBoxA(0, PAnsiChar(MSG), 'Title', 0);
end;

exports xMain;

begin
end.

执行:

format PE CONSOLE 4.0
entry start

include 'win32a.inc'

section '.code' code readable executable
start:
invoke xMain, szMSG
invoke ExitProcess, 0

section '.data' data readable writeable
szMSG db 'Message from FASM application!', 0

section '.idata' import data readable writeable
library kernel32, 'kernel32.dll',\
dllfile, 'testdll.dll'

include 'api\kernel32.inc'

import dllfile,\
xMain, 'xMain'


Unicode版本,
动态链接库:

library testdll;

uses
windows;

procedure xMain(MSG: PChar); export; stdcall;
begin
MessageBox(0, PChar(MSG), 'Title', 0);
end;

exports xMain;

begin
end.

执行:

format PE CONSOLE 4.0
entry start

include 'win32w.inc'

section '.code' code readable executable
start:
invoke xMain, szMSG
invoke ExitProcess, 0

section '.data' data readable writeable
szMSG du 'Message from FASM application!', 0

section '.idata' import data readable writeable
library kernel32, 'kernel32.dll',\
dllfile, 'testdll.dll'

include 'api\kernel32.inc'

import dllfile,\
xMain, 'xMain'

关于delphi - FASM - 将字符串传递给 Delphi DLL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13009012/

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