I am writing an application in C++ which will send a message to an application written in Delphi.
This is my receiver app:
When the button is clicked, Edit1.Text
will be sent via ShellExecute()
as a command line parameter to the sender app (C++).
The sender app will send back the parameter as a WM_COPYDATA
message to the receiver app, which will show it in the Edit2
text box.
This is the Delphi app's code (Delphi 10.3 Rio):
procedure TForm1.Button1Click(Sender: TObject);
begin
ShellExecute(0, 'open', 'deneme.exe', PWideChar(Edit1.Text), nil, SW_HIDE);
end;
procedure TForm1.MesajAl(var Mesaj: TMessage);
var
Veri: PCopyDataStruct;
begin
Veri := Pointer(Mesaj.LParam);
Edit2.Text := PChar(Veri^.lpData);
end;
This is my C++ app's code (Code::Blocks IDE):
#include <iostream>
#include <windows.h>
#include <tchar.h>
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 2)
{
return 0;
}
else
{
HWND hwnd = FindWindow(NULL, "Form1");
string alinanMesaj;
LPCTSTR gonderilecekMesaj = alinanMesaj.c_str();
COPYDATASTRUCT cds;
cds.cbData = sizeof(TCHAR)*(_tcslen(gonderilecekMesaj) + 1);
cds.dwData = 1;
cds.lpData = (PVOID)gonderilecekMesaj;
SendMessage(hwnd, WM_COPYDATA, (WPARAM)hwnd, (LPARAM)(LPVOID)&cds);
return 0;
}
}
The problem is the Edit2
text box shows nothing.
By the way, I have made a research in this website about WM_COPYDATA
. But despite the fact that this situation, I could not fix my issue myself.
So, what should I do in order to fix my issue?