i am trying to read a character on screen (to be fed to another function) using readconsoleoutputcharacter from windows.h (i know it is not ideal but i am using it to learn).
i tried using it and it works, but it returns an error when exiting the program.
the error says:
"run-time check failure #2 - stack around the variable 'buf' was corrupted"
it seems that if i create an infinite loop the error does not happen, and anything the program does after these lines of code still executes fine (with or without the infinite loop). at least thats how it seems to work, although i have had some experiments that seem to conflict that idea.
so in theory it works okay, but the error is obviously trying to point something out to me that i dont understand.
can anybody help me with this problem?
thanks! <3
and if there is a better way to read a character from a position on the screen i am open to learning it.
nLength [in]
The number of screen buffer character cells from which to read. The size of the buffer pointed to by the lpCharacter parameter should be nLength * sizeof(TCHAR).
You're assuming char, but chances are, you're compiling with UNICODE enabled (which has been the default for the last decade or so in visual studio).
Result - windows thinks the buffer is much larger than you say.
At least until it checks the stack.
You should be able to do this without all those casts.
All they do is serve to mask errors which might otherwise be reported.
Casts are a last resort when you know what you're doing.
i have read the documentation but it is hard to understand, i am still very new to C++
i am starting to piece things together a little though.
changing the char to TCHAR seems to have done the trick, thanks.
i would love to know more about how i can avoid the casts though. this code is a copy and paste code that i was trying to use to mould into my own code while learning how it works, but i couldnt get it to work until you helped.