The code is as below.
when LogToMyFile(“%Z) error raises at _vstprintf and crashes the application. Please help.
void LogToMyFile(LPCTSTR pFormat, ...)
{
TCHAR chMsg[2048];
LPTSTR lpszStrings[1];
va_list pArg;
va_start(pArg, pFormat);
_vstprintf(chMsg, pFormat, pArg);
va_end(pArg);
lpszStrings[0] = chMsg;
}
Thanks.
Typically mismatches in any form of printf between placeholders, like %Z, and the actual argument will cause this kind of problem. I stopped using printf for this very reason, it’s just not safe. It’s very easy to forget to change the placeholder when you change the type of the argument. The iostream equivalents are much safer. If you have to use printf make sure whatever argument is matching your %Z is compatible with what is expected. Typically, lint will check this for you so if possible lint your code.