首页 > 代码库 > windows log 打印语句
windows log 打印语句
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 |
|
strcmp | lstrcmp | (no equivalent function) |
strcpy | lstrcpy |
|
strlen | lstrlen |
|
来源于http://msdn.microsoft.com/en-us/library/windows/desktop/ms647465(v=vs.85).aspx
windows log 打印语句
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。