FormatMessage FORMAT_MESSAGE_FROM_STRING
-
Hi, I tried to use FormatMessage API to format variable argument that passed to a fuction, but it only delete all '%' characater with no thing else! please help me. my code : void CEllepsisDlg::Log(CString x,...) { CString strTempInput; strTempInput = x; va_list marker; va_start( marker, x ); LPTSTR lpFprmatedMessage; va_start( marker, x ); strTempInput=x; FormatMessage(FORMAT_MESSAGE_FROM_STRING, LPCSTR(strTempInput), NULL, NULL, (LPTSTR) &lpFprmatedMessage, 2048, &marker); char * tt=(char*)&lpFprmatedMessage; va_end( marker ); } :confused::((
-
Hi, I tried to use FormatMessage API to format variable argument that passed to a fuction, but it only delete all '%' characater with no thing else! please help me. my code : void CEllepsisDlg::Log(CString x,...) { CString strTempInput; strTempInput = x; va_list marker; va_start( marker, x ); LPTSTR lpFprmatedMessage; va_start( marker, x ); strTempInput=x; FormatMessage(FORMAT_MESSAGE_FROM_STRING, LPCSTR(strTempInput), NULL, NULL, (LPTSTR) &lpFprmatedMessage, 2048, &marker); char * tt=(char*)&lpFprmatedMessage; va_end( marker ); } :confused::((
Well looking at your code I think you got the params for FormatMessage slightly wrong. Try changing it to
void CEllepsisDlg::Log(CString x,...)
{
TCHAR fprmatedMessage[2048];va_list marker;
va_start( marker, x );FormatMessage(FORMAT_MESSAGE_FROM_STRING, (LPCVOID)((LPCTSTR)x), NULL, NULL,
fprmatedMessage, sizeof(fprmatedMessage), marker);va_end( marker );
}I havn't tested it, but I think that might work better. [EDIT]Be aware that in this new scheme that i've created, nothing happens to fprmatedMessage when FormatMessage has finished. Make sure you copy the string into a CString before using outside the Log function, otherwise your program will crash. e.g.
CString myresult = fprmatedMessage;
If you only want to use it within the function, then you can use fprmatedMessage just like any LPTSTR.[/EDIT] Hope this helps. Joel Holdsworth Wanna give me a job this summer? Check out my online CV and project history[^]