I am memory reading a string from a Japanese game and I am trying to display it in the console window and copy the string to clipboard. So far I've managed to display it in console, but whenever I try to copy it to my clipboard, the string gets distorted. I've tried to search the problem, but it was mostly people who were struggling displaying the string in console, something I have no problems with.
char StrTxt[500];
// TextAddress: The memory address of the string
ReadProcessMemory(hProcess, (LPCVOID)(TextAddress), &StrTxt, sizeof(StrTxt) / sizeof(*StrTxt), 0);
toClipboard(StrTxt);
cout << StrTxt << endl;
The Japanese text is correctly displayed in the console after cout, however the clipboard value that is being stored looks something like: y•zuƒXƒ~. I have no clue why it works fine when I output it into the console, because the string that is being read from memory is also distorted just as it appears in the clipboard. Here's the clipboard function if it will be of some help:
void toClipboard(const string &s) {
OpenClipboard(0);
EmptyClipboard();
HGLOBAL hg = GlobalAlloc(GMEM_MOVEABLE, s.size());
if (!hg) {
CloseClipboard();
return;
}
memcpy(GlobalLock(hg), s.c_str(), s.size());
GlobalUnlock(hg);
SetClipboardData(CF_TEXT, hg);
CloseClipboard();
GlobalFree(hg);
}
I've also tried handling the string using wchar_t and wstring, but I then got completely different symbols than expected.
My System Locale is currently set to Japanese if it matters.
What am I doing wrong here?