Home > Software engineering >  Delphi2010 and COPYDATA VC2010 to deliver the message to accept is not complete? Please help to solv
Delphi2010 and COPYDATA VC2010 to deliver the message to accept is not complete? Please help to solv

Time:09-28

The sender is delphi2010
 
Procedure TForm1. Btn1Click (Sender: TObject);
Var DataStruct: TCopyDataStruct;
Buffsize: Integer;
Buff: PChar;
H: HWND;
The begin
H:=StrToInt (edt1. Text);//vc window handle
Buffsize:=length (edt2. Text) * sizeof (Char) + 2;//a character standing 2 bytes
Buff:=StrAlloc (buffsize);//allocate memory
StrCopy (buff, PChar (edt2. Text));//copy data to the buffer
DataStruct. DwData:=0;
DataStruct. CbData:=buffsize;
DataStruct. LpData:=buff;
SendMessage (h, WM_COPYDATA, 0, LongInt (@ DataStruct));
end;


Receiver is vc2010

 
//accept message
BOOL CMyView: : OnCopyData (CWnd * pWnd, COPYDATASTRUCT * pCopyDataStruct)
{
If (pCopyDataStruct!=NULL)
{
LPCTSTR pszText=(LPCTSTR) (pCopyDataStruct - & gt; LpData);
DWORD dwLength=(DWORD) (pCopyDataStruct - & gt; CbData);
TCHAR szRecvText [1024]={0};
Memcpy (szRecvText pszText, dwLength);
MessageBox (szRecvText, _T (" Test "), MB_OK);
}
Return the CWnd: : OnCopyData (pWnd, pCopyDataStruct);
}


The problem is, I accept the message written in Delphi is full, with vc this show only the first character, there is something wrong with it?

CodePudding user response:

Character set might be the problem, check the VC is unicode

CodePudding user response:

Try WCHAR szRecvText [1024]={0};
Or project into a UNICODE
  • Related