C++结构到德尔福记录dll调用
C++ struct to Delphi Record dll call
我正在尝试将c ++结构转换为德尔菲 dll 调用记录
// c++ struct
typedef struct dll_info_t
{
char version[32];
char r_type[128];
char b_date[32];
char c_list[32];
char build[32];
}dll_info_t;
LIBEX_EXPORT int LIB_API Dll_get_lib_info(dll_info_t* info);
// Delphi Converted
dll_info_t = record
version:AnsiChar;
r_type:AnsiChar;
b_date:AnsiChar;
c_list:AnsiChar;
build:AnsiChar;
end;
Dll_get_lib_info: Function (info : dll_info_t) : Integer; stdcall;
var
hHandle:THandle;
begin
hHandle := LoadLibrary(Dl_path);
@Dll_get_lib_info:=GetProcAddress(hHandle, PChar('Dll_get_lib_info'));
if Assigned(Dll_get_lib_info) then begin
Dll_get_lib_info(info);
ShowMessage(info.version); // <- I Get Empty Output
ShowMessage(info.release_type); // <- I Get Empty Output
ShowMessage(info.build_date); // <- I Get Empty Output
ShowMessage(info.change_list); // <- I Get Empty Output
end;
end;
我得到空输出
我不确定转换后的记录是否正确?
我已经检查了德尔菲的在线字符是安西查尔吗?
char version[32]
与AnsiChar
不同,因为AnsiChar是一个单一的字符。你需要一个AnsiChar数组,(version: array [0..31] of AnsiChar
(,就像C代码中使用的一样。您需要记录的所有成员的正确声明。
type
dll_info_t = record
version: array [0..31] of AnsiChar;
r_type: array [0..127] of AnsiChar;
b_date: array [0..31] of AnsiChar;
c_list: array [0..31] of AnsiChar;
build: array [0..31] of AnsiChar;
end;
var
Dll_get_lib_info: Function(out info: dll_info_t): Integer; stdcall;
hMod: HMODULE;
info: dll_info_t;
begin
hMod := LoadLibrary(Dl_path);
@Dll_get_lib_info := GetProcAddress(hMod, 'Dll_get_lib_info');
if Assigned(Dll_get_lib_info) then begin
Dll_get_lib_info(info);
ShowMessage(info.version);
ShowMessage(info.release_type);
ShowMessage(info.build_date);
ShowMessage(info.change_list);
end;
end;
stdcall
是否正确取决于LIB_API
宏的定义。
相关文章:
- 如何安全地从 DLL 调用返回对象
- C++结构到德尔福记录dll调用
- 从 C#-DLL 调用函数的 C++ 失败
- 可视C++:XGBoost 从 DLL 调用时不起作用
- Unity3D的OpenCV dll调用导致FPS下降
- 创建一个C++DLL以从C#DLL调用方法
- 从 dll 调用 opencv 垫到 Windows 表单,图像出现故障
- 努力使用 C# 从本机 DLL 调用该方法
- WinAPI - GetLastError 在通过 COM ATL DLL 调用时始终返回 0
- 必须使用C DLL调用C#.NET方法
- 如何直接从 pdfium.dll 调用 v8 函数
- 为什么从 DLL 调用类方法需要虚拟说明符?
- VBA 中的多个 DLL 调用
- 挂钩VirtualAlloc在系统DLL调用时返回NULLPTR
- 无法从 C DLL 调用该函数
- DLL 调用涉及 strncpy() 的方法
- JNA从DLL调用C++对象-java.lang.IollegalArgumentException:Structure
- 德尔福动态DLL调用中的奇怪行为
- 从非托管 DLL 调用 UWP api
- boost::从 DLL 调用时日志格式不起作用