vc++ 与delphi开发的程序传递数据

用的是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, Classes, Graphics, Controls, Forms,
  Dialogs ;

type
  TForm1 = class(TForm)
  procedure WndProc(var Message : TMessage); override;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

procedure TForm1.WndProc(var Message: TMessage);
var
  cdds : TcopyDataStruct;
  mypchar:Pchar;
begin
  if message.Msg=WM_COPYDATA then
  begin
    cdds := PcopyDataStruct(message.LParam)^;
    mypchar :=  PChar(cdds.lpData);
    showmessage(mypchar);
  end;
  inherited WndProc(Message);
end;

{$R *.dfm}

end.



你可能感兴趣的:(vc++ 与delphi开发的程序传递数据)