2012年12月4日星期二

ReportEvent.Cpp


/*
日志,怎能不会?
特别是系统的,这些基本的功能。
有时它还是特有用的。
所以有此文。

参考:
http://msdn.microsoft.com/en-us/library/aa363680(v=vs.85).aspx等相关的内容。
http://www.aogosoft.com/downpage.asp?mode=viewtext&id=220
*/

#include <windows.h>

int main()
{
    HANDLE hEventLog = RegisterEventSource(NULL, L"来源");
    if (NULL == hEventLog) {
        return 1;
    }

    CONST LPWSTR pBadCommand = L"data";//这里不准用汉字,是不会显示汉字的,是以字节显示的字母的。以双0字节结尾。
    DWORD dwEventDataSize = ((DWORD)wcslen(pBadCommand) + 1) * sizeof(WCHAR);
    if (!ReportEvent(hEventLog,
        EVENTLOG_INFORMATION_TYPE, //类型(级别)是信息。
        (WORD)0x00000003L, //分类或者任务类别。
        (DWORD)0xC0020100L, //低16位是事件或者事件ID,
        NULL,//A pointer to the current user's security identifier. This parameter can be NULL if the security identifier is not required
        0, //The number of insert strings in the array pointed to by the lpStrings parameter. A value of zero indicates that no strings are present.
        dwEventDataSize, //数据的长度。
        NULL, //另一种情况使用,是数组用的,与上上个参数配合使用,有大小的限制。
        pBadCommand))//数据的内容。
    {
        return 1;
    }

    if (hEventLog) {
        DeregisterEventSource(hEventLog);
    }
}

没有评论:

发表评论