WEB开发网
开发学院软件开发C++ VC6.0环境下C++编写Windows日志文件法 阅读

VC6.0环境下C++编写Windows日志文件法

 2010-10-20 14:04:57 来源:WEB开发网   
核心提示:#include "windows.h"#define SVC_ERROR ((DWORD)0xC0020001L)void WriteReportEvent(LPTSTR szName,LPTSTR szFunction) { HANDLE hEventSource; LPCT

#include "windows.h"
#define SVC_ERROR    ((DWORD)0xC0020001L)

void WriteReportEvent(LPTSTR szName,LPTSTR szFunction) 
{ 
    HANDLE hEventSource;
    LPCTSTR lpszStrings[2];
    unsigned int len = sizeof(szFunction);
    char *Buffer = new char[len];
    
    hEventSource = RegisterEventSource(NULL, szName);
    
    if( NULL != hEventSource )
    {
        //StringCchPrintf(Buffer, 80, TEXT("%s failed with %d"), szFunction, GetLastError());
        strcpy(Buffer,szFunction);
        lpszStrings[0] = szName;
        lpszStrings[1] = Buffer;
        //详细请参考MSDN
        ReportEvent(hEventSource,        // event log handle
            EVENTLOG_ERROR_TYPE, // event type
            0,                   // event category
            SVC_ERROR,           // event identifier
            NULL,                // no security identifier
            2,                   // size of lpszStrings array
            0,                   // no binary data
            lpszStrings,         // array of strings
            NULL);               // no binary data    
        DeregisterEventSource(hEventSource);
    }
}

编辑-爽爽推荐VC6.0环境下C++编写Windows服务程序法

http://tech.cncms.com/develop/cjj/111575.html

Tags:VC6.0 环境 C++ Windows 日志

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接