標籤:
1、格式化字串(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 ,適用於服務應用,適用於在事件檢視器中查看相關log
1 #ifdef _DEBUG 2 3 HANDLE hEventSource = NULL; 4 LPCWSTR lpszStrings[2] = { NULL, NULL }; 5 6 hEventSource = RegisterEventSourceW(NULL, L"DeviceMonitorService"); 7 if (hEventSource) 8 { 9 lpszStrings[0] = L"Source";//來源10 lpszStrings[1] = pszMessage;11 12 ReportEventW(hEventSource, // Event log handle13 wType, // Event type14 0, // Event category15 0, // Event identifier16 NULL, // No security identifier17 2, // Size of lpszStrings array18 0, // No binary data19 lpszStrings, // Array of strings20 NULL // No binary data21 );22 23 DeregisterEventSource(hEventSource);24 }25 #else26 #endif // DEBUG
3、OutputDebugStringA,適用於win32應用程式(非控制台程式)
void logoutput(const char * lpszFormat, ...){ //#ifdef _DEBUG va_list argList; va_start(argList, lpszFormat); char chInput[512] = { 0 }; vsprintf_s(chInput, lpszFormat, argList); va_end(argList); OutputDebugStringA(chInput); OutputDebugStringA("\n"); //#endif}
4、字串操作(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 each character in a string.使用安全字元: #include Strsafe.h StringCchCopy
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
|
來源於http://msdn.microsoft.com/en-us/library/windows/desktop/ms647465(v=vs.85).aspx
windows log 列印語句