帮我看个程序写的对不?

虎滴小猪猪 2013-07-25 03:06:09
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,将值放在最后一个参数里,然后我的程序接收这个消息,将最后一个参数的值取出来,按照上面的写法来得到结果,但是有时报错,有时得不到结果。谁能帮我分析下?
...全文
132 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
pathletboy 2013-07-25
  • 打赏
  • 举报
回复
以共享内存的形式,你是以指针访问,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
虎滴小猪猪 2013-07-25
  • 打赏
  • 举报
回复
cdData := (PCopyDataStruct(Msg.LParam))^; 直接这样写,不用分配地址啥的,能娶到共享内存的地址的值?
pathletboy 2013-07-25
  • 打赏
  • 举报
回复
检查SendMessage部分吧,你这个部分没有问题。

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧