windows log 列印語句

來源:互聯網
上載者:User

標籤:

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 列印語句

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.