我需要帮助将LPARAM
类型转换为Structure。例如,在C ++中,我们有:
struct MyStructure
{
int data01;
int data02;
};
BOOL CALLBACK CallbackProc(int number, LPARAM param)
{
MyStructure *myStruct = (MyStructure *) param;
}
在Delphi中,我尝试了此操作,但是编译器在高亮行中给出了注释不兼容类型的错误:
type
TMyStructure = record
data01: Integer;
data02: Integer;
end;
PMyStructure = ^TMyStructure;
function CallbackProc(number: Integer; param: LPARAM): BOOL; stdcall;
var
myStruct: TMyStructure;
begin
myStruct := param; // How stays here?
end;
最佳答案
C ++代码将LPARAM
强制转换为指向结构的指针。在Delphi中,将如下所示:
type
TMyStructure = record
data01: Integer;
data02: Integer;
end;
PMyStructure = ^TMyStructure;
function CallbackProc(number: Integer; param: LPARAM): BOOL; stdcall;
var
myStruct: PMyStructure;
begin
myStruct := PMyStructure(param);
end;
关于delphi - 如何将LPARAM转换为Delphi中的结构?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55559333/