http://msdn.microsoft.com/en-us/library/windows/desktop/ms684969(v=vs.85).aspx
error C2664: ‘ReadConsoleOutputCharacterW’ : cannot convert parameter 2 from ‘char *’ to ‘LPWSTR’
#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hOut;
char letter;
char letters[5];
DWORD numberRead;
COORD where_;
SetConsoleTitle(L"Hello!");
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
where_.X = 0;
where_.Y = 0;
ReadConsoleOutputCharacter(hOut, &letter, 1, where_, &numberRead);
printf("letter at (0,0) is %c letter", letter);
return 0;
}
It seems you are compiling with unicode support enabled (because
ReadConsoleOutputCharacterresolves toReadConsoleOutputCharacterW, otherwise it would resolve toReadConsoleOutputCharacterA).This means all strings and characters used with any WinAPI functions need to be wide characters
WCHARinstead ofcharandLPWSTRinstead ofLPSTR, …. Or you disable unicode by undefining the appropriate preprocessor symbols (UNICODEand_UNICODE, I think). But in this case yourSetConsoleTitlecall won’t work anymore, as you explicitly pass it a wide string.But the most flexible would be to use
TCHARinstead ofcharandLPTSTRinstead ofLPSTRand the like. These are just defined to the correct types depending on the definition of theUNICODEpreprocessor symbol. In this case the code stays widely independent of unicode support. But in this case you have to wrap all string literals in the_T,TorTEXTmacro:See here for an introduction to the problem.
If you don’t really need unicode support and only need some simple WinAPI functions and want them to interface well with the C standard library (like in your case it seems), it would be the best idea to just undefine
UNICODEand_UNICODEand use standardchars. In this case also remove theLmodifier from your string literals.