1. Formatted string (writes formatted data to the specified string)
wchar_t szmessage[260];
Pwstr pszfunction = L "Hello world!" ”;
DWORD dwerror = GetLastError ();
STRINGCCHPRINTFW (Szmessage, ARRAYSIZE (szmessage), L "%s failed W/err 0x%08lx", Pszfunction, dwerror);
stringcchprintf is a replacement for the following functions:
- sprintf, swprintf, _stprintf
- wsprintf
- wnsprintf
- _snprintf, _snwprintf, _sntprintf
2, Reporteventw , for service applications, for viewing related logs in Event Viewer
1 #ifdef _DEBUG2 3HANDLE Heventsource =NULL;4LPCWSTR lpszstrings[2] ={null, null};5 6Heventsource = Registereventsourcew (NULL, L"Devicemonitorservice");7 if(Heventsource)8 {9lpszstrings[0] = L"Source";//SourceTenlpszstrings[1] =Pszmessage; One AREPORTEVENTW (Heventsource,//Event Log Handle -Wtype,//Event Type - 0,//Event category the 0,//Event identifier -Null//No Security Identifier - 2,//Size of lpszstrings array - 0,//No binary Data +Lpszstrings,//Array of Strings -Null//No binary Data + ); A at Deregistereventsource (heventsource); - } - #else - #endif //DEBUG
3, Outputdebugstringa, for Win32 applications (non-console program)
void logoutput (constChar * lpszformat, ...) { //#ifdef _DEBUG va_list argList; Va_start (ArgList, Lpszformat); Char chinput[0 }; vsprintf_s (Chinput, Lpszformat, argList); Va_end (argList); Outputdebugstringa (chinput); Outputdebugstringa ("\ n") ; // #endif}
4. String manipulation (Strsafe function)
the string functions give applications the means to copy, compare, sort, format, and convert character strings as well As the means to determine the character type of all character in a string.Use safe characters:#include Strsafe.hStringCchCopy
CRT String Function |
Windows String Function |
Strsafe Function |
Strcat |
Lstrcat |
-
StringCchCat
-
Stringcchcatex
-
Stringcbcat
-
Stringcbcatex
|
strcmp |
lstrcmp |
(No equivalent function) |
strcpy |
lstrcpy |
-
StringCchCopy
-
Stringcchcopyex
-
Stringcbcopy
-
Stringcbcopyex
|
Strlen |
Lstrlen |
-
Stringcchlength
-
Stringcblength
|
From http://msdn.microsoft.com/en-us/library/windows/desktop/ms647465 (v=vs.85). aspx
Windows log Print statement