用的是WM_COPYDATA消息和COPYDATASTRUCT这个结构。
注意的是数据类型:C++中用char*,delphi中用PChar。
void CTestCydataDlg::OnButton1()
{
CWnd *pWnd = CWnd::FindWindow(NULL,_T("Form1"));
if(pWnd==NULL)
{
AfxMessageBox("Unable to find Form1!");
return;
}
COPYDATASTRUCT cpd;
cpd.cbData = 2425;
cpd.dwData = m_strCopydata.GetLength();
char *buf = m_strCopydata.GetBuffer(cpd.dwData);
cpd.lpData = (void*)buf;
pWnd->SendMessage(WM_COPYDATA,NULL,(LPARAM)&cpd);
}
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Class