In Windows' FormatMessage() function, the parameter:
_Out_ LPTSTR lpBuffer
Is doing my head in. Following along from Hart's Windows System Programming book, I'm declaring an LPTSTR
pointer to be used as the lpBuffer
(e.g. LPTSTR errortext;
), and then calling the FormatMessage()
function.
The correct way to pass in this parameter is: (LPTSTR)&errorText
This works fine. But I don't understand why I need to write (LPTSTR)
. I understand that's typecasting and I read about it but it doesn't make sense to me, because I'm not changing the variable type or anything, I declared it as an LPTSTR
and I'm passing its memory address to the function, the function expects an LPTSTR
and I passed it an LPTSTR
, so why do I need to put (LPTSTR)
as part of the lpBuffer
parameter?