Well, SendMessage gives me no such problem! In the below examples, the AHK script receives the message, but then you're hit with ANSI vs Unicode problems.
The idea for this script + exe bundle is to be able to run it in both AHK ANSI and AHK Unicode. All I want to do is send strings of data the the AHK script, and let the script handle it from there. I just want whatever is the easiest way (i.e. changing settings in the VS project, and/or changing handling in the AHK script). Any guidance here?
By the way, thanks for all the help, everyone. I have always had so much trouble trying to set up my projects in Visual Studio choosing things like MFC vs. Console, Ansi vs Unicode, etc. It's frustrating when all you want is a simple little app. Especially because this little app is a design in a much bigger idea. I'll be posting that within a week or two, hopefully -- I want to start giving back to the AHK community.
Code: Select all
{
; At least for me, it is unnecessary to call ChangeMessageFilterEx
OnMessage(WM_COPYDATA:=74, "OnWMCopyData")
Run, C:\Test.exe %A_ScriptHwnd%
return
}
OnWMCopyData(wParam, lParam, msg, hWnd)
{
Msgbox % StrGet(NumGet(lParam + 2*A_PtrSize))
return
}
Code: Select all
#include <iostream>
#include "Windows.h"
using namespace std;
int main(int argc, char* argv[])
{
if (argv[1])
{
string s = argv[1];
int iHwnd = stoi(s, 0, 16);
HWND hWnd = (HWND)iHwnd;
cout << "char:" << argv[1] << "|int:" << iHwnd << "|hWnd:" << hWnd << endl;
LPCTSTR lpszString = "Hello AHK";
COPYDATASTRUCT cds;
cds.dwData = 1; // arbitrary
cds.cbData = sizeof(TCHAR) * (strlen(lpszString) + 1);
cds.lpData = &lpszString;
cout << SendMessage(hWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)&cds) << endl;
cout << GetLastError() << endl;
// Must be syncronous to use PostMessage
//cout << ::PostMessage(hWnd, WM_COPYDATA, (WPARAM)hWnd, (LPARAM)(LPVOID)&cds) << endl;
//cout << GetLastError() << endl;
}
return 0;
}