WM_COPYDATA 进程间通信 传结构体失败...
a.exe代码:
typedef struct backupinfo
{
String sign;
String backuppath;
}BackupInfo;
void __fastcall TForm1::btn1Click(TObject *Sender)
{
HWND hWnd = FindWindow("TForm1","Form2");
if(hWnd)
{
BackupInfo *backup = new BackupInfo() ;
backup->sign = "access";
backup->backuppath = "ddd";
COPYDATASTRUCT cds;
cds.dwData = 0 ;
cds.cbData = sizeof(BackupInfo);
cds.lpData = (PVOID)backup;
SendMessage(hWnd,WM_COPYDATA,NULL,(LPARAM)&cds);
}
}
b.exe代码:
typedef struct backupinfo
{
String sign;
String backuppath;
}BackupInfo;
void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{
switch (Message.Msg)
{
case WM_COPYDATA:
{
COPYDATASTRUCT *cds;
cds = (COPYDATASTRUCT*)Message.LParam;
BackupInfo * backup = (BackupInfo*)(cds->lpData);
String sign = backup->sign;
....
break;
}
}
TForm::WndProc(Message);
}
不知道为什么b.exe程序backup结构体接收的数据总是为空...
我a.exe明明给结构体赋值了的
请哪位大哥帮帮忙,我想了一上午都不知道怎么回事,怎么改正???
[解决办法]
好像毛毛回答过你这个问题啊,WM_COPYDATA传输的数据,不要用String类型,改成char数组。