Okay, after a bit of work, I discovered quite a few errors in my console program. AFAICT, I have a working Unicode project...except that it does not work. I also cannot find in error on my AHK script. The problem still seems likely to be a project setting...maybe not?
At first, I did my best to match the project settings for AHK. That did not make a difference. Next, I looked at how AHK handled the Post/SendMessage commands; they use _T macro for string, so now I am using that, too.
This annoyance is just a small bottleneck in a rather fun project I am working on. *Any* help at all is greatly appreciated because it will save me enormous amounts of time with researching this issue.
VS 2010 Project can be downloaded here:
https://www.dropbox.com/s/pgj2jg2vngzr2 ... essage.zip
Code: Select all
OnMessage(WM_COPYDATA:=74, "OnWMCopyData")
Run, C:\Users\%A_UserName%\Documents\Visual Studio 2010\Projects\SendMessage\Debug\SendMessage.exe %A_ScriptHwnd%
return
OnWMCopyData(wParam, lParam)
{
StringAddress := NumGet(lParam * A_PtrSize) ; Retrieves the CopyDataStruct's lpData member.
CopyOfData := StrGet(StringAddress)
CopyOfData2 := StrGet(StringAddress, "cp0")
CopyOfData3 := StrGet(StringAddress, "cp1200")
CopyOfData4 := StrGet(StringAddress, "UTF-8")
CopyOfData5 := StrGet(StringAddress, "UTF-16")
Msgbox %CopyOfData%`n%CopyOfData2%`n%CopyOfData3%`n%CopyOfData4%`n%CopyOfData5%
return true
}
Code: Select all
// SendMessage.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "Windows.h"
using namespace std;
int _httoi(const TCHAR *value)
{
struct CHexMap
{
TCHAR chr;
int value;
};
const int HexMapL = 16;
CHexMap HexMap[HexMapL] =
{
{'0', 0}, {'1', 1},
{'2', 2}, {'3', 3},
{'4', 4}, {'5', 5},
{'6', 6}, {'7', 7},
{'8', 8}, {'9', 9},
{'A', 10}, {'B', 11},
{'C', 12}, {'D', 13},
{'E', 14}, {'F', 15}
};
TCHAR *mstr = _tcsupr(_tcsdup(value));
TCHAR *s = mstr;
int result = 0;
if (*s == '0' && *(s + 1) == 'X') s += 2;
bool firsttime = true;
while (*s != '\0')
{
bool found = false;
for (int i = 0; i < HexMapL; i++)
{
if (*s == HexMap[i].chr)
{
if (!firsttime) result <<= 4;
result |= HexMap[i].value;
found = true;
break;
}
}
if (!found) break;
s++;
firsttime = false;
}
free(mstr);
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
if (argv[1])
{
int iHwnd = _httoi(argv[1]);
HWND hWnd = (HWND)iHwnd;
cout << "char:" << argv[1] << "|int:" << iHwnd << "|hWnd:" << hWnd << endl;
LPCTSTR lpszString = (LPCTSTR)_T("Hello AHK");
COPYDATASTRUCT cds;
cds.dwData = 1; // arbitrary
cds.cbData = sizeof(TCHAR) * (_tcslen(lpszString) + 1);
cds.lpData = &lpszString;
cout << SendMessage(hWnd, WM_COPYDATA, (WPARAM) hWnd, (LPARAM) (LPVOID)&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;
}
cout << "Press Enter to quit..." << endl;
cin.get();
return 0;
}