帮我看个程序写的对不?
type
TCopyDataStruct = packed record
dwData: DWORD; // 条件
cbData: DWORD; // 信息长度 需要 + 1,加一个结束符的位
lpData: Pointer; // 数据指针,传送数据的地址
end;
PCopyDataStruct = ^TCopyDataStruct;
type
TCardInfo = packed record
CardNO: array[0..24] of char;
Balance: integer;
end;
PCardInfo = ^TCardInfo;
procedure TMainForm.WMReceiveMsgFromCircul(var Msg: TMessage);
var
cdData: TCopyDataStruct;
cdInfo: TCardInfo;
begin
cdData := (PCopyDataStruct(Msg.LParam))^;
end;
一个程序按照TCopyDataStruct结构体的格式取地址强制转成整形,然后通过sendmessage,将值放在最后一个参数里,然后我的程序接收这个消息,将最后一个参数的值取出来,按照上面的写法来得到结果,但是有时报错,有时得不到结果。谁能帮我分析下?
[解决办法]
检查SendMessage部分吧,你这个部分没有问题。
[解决办法]
以共享内存的形式,你是以指针访问,Msg.LParam就是地址
http://msdn.microsoft.com/en-us/library/ms649011%28VS.85%29.aspx
Remarks
The data being passed must not contain pointers or other references to objects not accessible to the application receiving the data.
While this message is being sent, the referenced data must not be changed by another thread of the sending process.
The receiving application should consider the data read-only. The lParam parameter is valid only during the processing of the message. The receiving application should not free the memory referenced by lParam. If the receiving application must access the data after SendMessage returns, it must copy the data into a local buffer.
注意下remark