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:
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 handle 13 wType, // Event type 14 0, // Event category 15 0, // Event identifier 16 NULL, // No security identifier 17 2, // Size of lpszStrings array 18 0, // No binary data 19 lpszStrings, // Array of strings 20 NULL // No binary data 21 ); 22 23 DeregisterEventSource(hEventSource); 24 } 25 #else 26 #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 | |
strcmp | lstrcmp | (no equivalent function) |
strcpy | lstrcpy | |
strlen | lstrlen |
来源于http://msdn.microsoft.com/en-us/library/windows/desktop/ms647465(v=vs.85).aspx
时间: 2024-10-12 15:16:56