Most often a question comes in my mind that why OutputDebugString does not take variable no of arguments like the TRACE or printf function. I dont know the reason why but I have a solution to the problem. This article is for those OutputDebugString fan's who are annoyed to use the CString and format the string with the variables like Code: CString OutMsg; OutMsg.Format("FUNCTION NAME >> VARIABLE NAME = %d",VAR_NAME); OutputDebugString(OutMsg); Here is the substituted function Code: void _OutputDebugString(LPCTSTR lpOutputString, ... ) { va_list argptr; va_start( argptr, lpOutputString ); TCHAR OutMsg[MAX_LENGTH]; TCHAR format[MAX_LENGTH]; for(int i=0,j=0;lpOutputString[i] != '\0';i++) { format[j++] = lpOutputString[i]; // If escape character if(lpOutputString[i] == '\\') { i++; continue; } // if not a substitutal character if(lpOutputString[i] != '%') continue; format[j++] = lpOutputString[++i]; format[j] = '\0'; switch(lpOutputString[i]) { // string case 's': { char* s = va_arg( argptr, char * ); sprintf(OutMsg,format,s); strcpy(format,OutMsg); j = strlen(format); strcat(format," "); break; } // character case 'c': { char c = (char) va_arg( argptr, int ); sprintf(OutMsg,format,c); strcpy(format,OutMsg); j = strlen(format); strcat(format," "); break; } // integer case 'd': { int d = va_arg( argptr, int ); sprintf(OutMsg,format,d); strcpy(format,OutMsg); j = strlen(format); strcat(format," "); break; } } } OutputDebugString(OutMsg); va_end( argptr ); } Download the cpp file and see how it works. I have taken care of escape character \, string %s, integers %d and characters %c but you can add the floating point numbers and many more.
VER NICE,YOU ARE A VERY CLEVER PERSON,I'M ALSO THANKING U FOR REPLYING TO MY ARTICLE 'FRIENDSHIP CALCULATOR & HANGMAN'.MY NAME IS TEJUS. I WAS VERY SAD BECAUSE NOONE DIDN'T REPLY TO ME TILL UR REPLY. I AM STUDYING IN 'VI'(6TH)'IN S.N.PUBLIC SCHOOL ,KOLLAM
A much more simple approach: Code: void _OutputDebugString(LPCTSTR lpOutputString, ... ) { TCHAR OutMsg[MAX_LENGTH]; va_list argptr; va_start(argptr, lpOutputString); wvsprintf(OutMsg, lpOutputString, argptr); OutputDebugString(OutMsg); va_end(argptr); }