So I kinda followed this :
https://msdn.microsoft.com/en-us/library/ms649009(v=vs.85).aspx
and this:
Use WM_COPYDATA to send data between processes
For sending data between a openframeworks application and unreal engine 4. Now everything seems to be fine, except I cant seem to find why I am getting an error that lParam is undefined. It's probably something simple, but I cant find how to do it.
So in unreal engine 4 I have an actor which send a message every 10 sec (for test purposes):
void ACOMActor::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
timer += DeltaTime;
if (timer > sendtime) {
timer = 0.f;
std::string string = "a message";
const wchar_t* wstring = new wchar_t[string.length() +1];
std::copy(string.begin(), string.end(), wstring);
SendWMCOPYDATA(wstring);
}
}
void ACOMActor::SendWMCOPYDATA(const wchar_t* string)
{
HWND WINAPI GetActiveWindow(void);
LPCTSTR lpszString = string;
COPYDATASTRUCT cds;
cds.dwData = 1;
cds.cbData = sizeof(TCHAR) * (_tcslen(lpszString) + 1);
cds.lpData = &lpszString;
SendMessage(GetActiveWindow(), WM_COPYDATA, (WPARAM)GetActiveWindow(), (LPARAM)(LPVOID)&cds);
GEngine->AddOnScreenDebugMessage(-1, 5.F, FColor::Green, FString::Printf(TEXT("Sending a message")));
}
Some code is still a bit rough but I was just trying to get it to work first.
I also created code for receiving the message in openframeworks. I wasn't exactly sure how to do this so I added this to the update function of my ofApp.cpp
void ofApp::update() {
GM->update();
PCOPYDATASTRUCT pMyCDS;
void WINAPI MyDisplay(LPSTR, LPSTR, DWORD);
pMyCDS = (PCOPYDATASTRUCT)lParam;
if (pMyCDS->dwData == 1)
{
LPCTSTR lpszString = (LPCTSTR)(pMyCDS->lpData);
cout << "receiving a message" << endl;
}
}
So this doesn't work, because lParam is undefined. I also tried to do something with LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
But I am unfamiliar with this and I am not sure how to use it. My error was gone but the message was not received... I used it like this, wrong probably:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PCOPYDATASTRUCT pMyCDS;
void WINAPI MyDisplay(LPSTR, LPSTR, DWORD);
pMyCDS = (PCOPYDATASTRUCT)lParam;
if (pMyCDS->dwData == 1)
{
LPCTSTR lpszString = (LPCTSTR)(pMyCDS->lpData);
cout << "receiving a message" << endl;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
Any tips how to achieve this? It is probably really simple but I can't find any clear information. Thanks!