アプリケーション間でデータの送受信(WM_COPYDATAを使う)
|
BCB1で記述してます。3用に手直しがあるかもしれません。
送り側アプリ
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HANDLE handle;
WPARAM wParam;
LPARAM lParam;
char msgbuf[]="hogehoge";
COPYDATASTRUCT cds;
cds.dwData = 1;
cds.cbData = strlen(msgbuf);
cds.lpData = (LPVOID)msgbuf;
handle = ::FindWindow(NULL,"受けアプリ");
wParam = (WPARAM)Application->Handle;
lParam = (LPARAM)&cds;
::SendMessage(handle,WM_COPYDATA,wParam,lParam);
}
//---------------------------------------------------------------------------
受け側アプリのヘッダ
public: // ユーザー宣言
void __fastcall EvWmCOPYDATA( TMessage message );
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_COPYDATA,TMessage, EvWmCOPYDATA)
END_MESSAGE_MAP(TForm)
浮け側アプリのソース
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Form1->Caption = "受けアプリ";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EvWmCOPYDATA( TMessage message )
{
COPYDATASTRUCT *cds;
char buf[80];
cds = (COPYDATASTRUCT *)message.LParam;
::ZeroMemory(buf,sizeof(buf));
memmove(buf,cds->lpData,cds->cbData);
::MessageBox(0,buf,"Oh!",MB_OK);
}
|
|