将C API调用转换为delphi
convert C API call to delphi
我正在努力将以下C代码转换为Dephi。假设DLL是myDLL.DLL:
struct ConfEx_Participant {
DWORD dwID;
DWORD dwPath;
};
LONG WINAPI AddtoConfEx(
IN OUT LPVOID lpParams, // parameter block
IN OUT DWORD* lpSize, // pointer to var holding size of lpParams
IN DWORD dwPath,
IN const ConfEx_Participant* pParticipant, //array of participants
IN DWORD cParticipant // number of participants
);
我正在尝试这样做:
PConfEx_Participant := ^TConfEx_Participant
TConfEx_Participant = record
dwCallID: DWORD;
dwPath: DWORD;
end;
type TAddtoConfEx = function {
lpParams: DWORD_PTR;
lpsize: DWORD_PTR;
dwPath: DWORD;
ConfEx_Participant: PConfEx_participant;
cParticipant: Integer;
end;
然后在实现部分:
Procedure Connect();
lResult: Integer;
Func := TAddToConfEx;
begin
Handle := SafeLoadLibrary('myDLL.DLL');
@Func := GetProcAddress(Handle, 'AddToConfEx');
lResult := Func(lpParams, lpSize, dwPath, @PConfEx_Participant, 2);
...
我在设置结构,填充它们然后将它们连接在一起时有点迷失了。
你的函数声明是错误的,你调用它的方式也是错误的。
试试这样写:
type
PConfEx_Participant = ^ConfEx_Participant;
ConfEx_Participant = record
dwID: DWORD;
dwPath: DWORD;
end;
function AddtoConfEx(
lpParams: Pointer; // parameter block
var lpSize: DWORD; // pointer to var holding size of lpParams
dwPath: DWORD;
const pParticipant: PConfEx_Participant; //array of participants
cParticipant: DWORD // number of participants
): LONG; stdcall; external 'myDLL.DLL';
procedure Connect;
var
Params: Pointer;
Size: DWORD;
Path: DWORD;
Participants: array of ConfEx_Participant;
lResult: LONG;
begin
Params := ...; // whatever it needs to point at...
Size := ...; // however many bytes Params is pointing at...
Path := ...; // whatever value you need...
SetLength(Participants, ...); // whatever length you need...
// populate Participants as needed...
lResult := AddtoConfEx(Params, Size, Path, PConfEx_Participant(Participants), Length(Participants));
...
end;
或:
type
PConfEx_Participant = ^ConfEx_Participant;
ConfEx_Participant = record
dwID: DWORD;
dwPath: DWORD;
end;
TAddtoConfEx = function(
lpParams: Pointer; // parameter block
var lpSize: DWORD; // pointer to var holding size of lpParams
dwPath: DWORD;
const pParticipant: PConfEx_Participant; //array of participants
cParticipant: DWORD // number of participants
): LONG; stdcall;
procedure Connect;
var
Func: TAddToConfEx;
Params: Pointer;
Size: DWORD;
Path: DWORD;
Participants: array of ConfEx_Participant;
lResult: LONG;
begin
Handle := SafeLoadLibrary('myDLL.DLL');
if Handle = 0 then RaiseLastOSError;
@Func := GetProcAddress(Handle, 'AddToConfEx');
if not Assigned(Func) then RaiseLastOSError;
...
Params := ...; // whatever it needs to point at...
Size := ...; // however many bytes Params is pointing at...
Path := ...; // whatever value you need...
SetLength(Participants, ...); // whatever length you need...
// populate Participants as needed...
lResult := Func(Params, Size, Path, PConfEx_Participant(Participants), Length(Participants));
...
end;
相关文章:
- 将 Delphi 的字符串转换为 std::字符串用于C++
- 如何将C/C 回调函数转换为Delphi
- 将C 回调功能转换为Delphi
- 如何将C 代码转换为Delphi
- 将数组指针访问从C++转换为Delphi
- 从C++到Delphi的类型转换
- Delphi中的类型转换指针添加
- 将 C 中的按位语句转换为 Delphi
- 使用消息处理程序将 c++ dll 调用转换为 delphi
- Delphi - 从 dll 调用转换(读取)C++ NULL 终止数组
- 将 Direct3D C++ 函数转换为 Delphi
- 如何将MQL4代码转换为C++/Delphi DLL(Forex Tester API)
- Delphi在将VirtualProtect EAT钩子例程从C转换为Delphi时出现问题
- 更正从C++到delphi AnsiString的字节转换
- 代码从C/C++转换为Delphi
- 将C++内联汇编函数转换为delphi内联汇编函数
- c++到Delphi的指针转换
- 可以将带有类的c++头文件转换为Delphi单元吗?
- 将C头中的__declspec转换为Delphi
- 如何将c++头文件转换为delphi