1

My issue is that visual studio is reading char as as a wide char.

char newChar ;
ReadProcessMemory(handle, (LPCVOID)(baseAddr), &newChar, 1, NULL);
std::cout << "Read char: "<<newChar << std::endl;

Has the output of

Read char: ╠ 

The output is unicode, but I had it declared as char, which should just be a byte of data. This code works in visual studio code, but not in visual studio 19.

273K
  • 29,503
  • 10
  • 41
  • 64
Max K
  • 41
  • 4
  • 1
    `char newChar = (char)"a";` is undefined behaviour. And I'm surprised that your compiler accepted this code. Did you maybe mean `char newChar = 'a';`? With single quotes? – Lukas-T Aug 19 '22 at 06:42
  • Yes you are right, single strings worked but I updated the question tho with an example that better highlights the problem. – Max K Aug 19 '22 at 06:49
  • This is not a Unicode char. It's a char from the extended part of ASCII table. – 273K Aug 19 '22 at 06:52
  • Bet you're using a single-byte code page that includes box drawing characters. – Shawn Aug 19 '22 at 06:53
  • 1
    @273K: Since Unicode is a superset of pretty much every character encoding, _any_ character including a plain `a` is Unicode. – MSalters Aug 19 '22 at 07:36
  • @MSalters What are you talking about? `╠` is not `a`. – 273K Aug 19 '22 at 14:16
  • @273K: Obviously not. Both are in Unicode, though. `╠` is U+2560 and `a` is U+0061. – MSalters Aug 20 '22 at 00:36
  • Hi, glad to know you've found the solution to resolve this issue! Please consider answering it and accepting it as an answer to change its status to Answered. It will also help others to solve a similar issue. See [can I answer my own question..](https://stackoverflow.com/help/self-answer), Just a reminder :) – Yujian Yao - MSFT Aug 25 '22 at 07:05

1 Answers1

1

Sorry I was mistaken. It has nothing to do with wchar or unicode. The ReadProcessMemory function failed. Not sure why, I have requireAdministrator permission but that is the issue

Max K
  • 41
  • 4
  • Perhaps you should check the error to find out why? https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-readprocessmemory – VLL Aug 19 '22 at 07:13