我需要帮助将LPARAM
类型转换为结构。例如,在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;
答案 0 :(得分:5)
C ++代码将LPARAM
强制转换为 pointer 的结构。在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;