Windows log Print statement

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.