如何读写WINDOWS2000的日志
2006-07-19 11:37:24 来源:WEB开发网核心提示: 用mc.exe(vc自带)编译一个*.mc文件,生成*.h,*.rc,*.bin,再用他们生成一个资源dll(用vc生成一个空win32dll框架,把他们加进来编译),放system目录下.下面是一个mc文件的样板:;//begin==;#ifndef __CMCARD_H__;#defi
用mc.exe(vc自带)编译一个*.mc文件,生成*.h,*.rc,*.bin,再用他们生成一个资源dll(用vc生成一个空
win32dll框架,把他们加进来编译),放system目录下.
下面是一个mc文件的样板:
;//begin==============================================================
;#ifndef __CMCARD_H__
;#define __CMCARD_H__
LanguageNames=(Chinese=2052:MSG0052)
SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
Warning=0x2:STATUS_SEVERITY_WARNING
Error=0x3:STATUS_SEVERITY_ERROR
)
MessageId=1000 Severity=Success SymbolicName=CM_CARD_STATUS_OK
Language=Chinese
CMCard的状态良好.
.
MessageId=1001 Severity=Success SymbolicName=CM_CARD_STATUS_BED
Language=Chinese
CMCard出错了,原因可能是%1.
.
;#endif //__CMCARD_H__
;//end================================================================
说明:默认的语言是英语,此时"LanguageNames="那句可以省略;
%1表示从ReportEvent传来的参数;
注意注释时";"与";//"的不同用法.mc编译器会忽略";"后面的字符,但会把他们写到*.h文件里.
三.写日志的方法.
//vc
BOOL syslog(DWORD dwID,char*str,WORD wType)//参数:事件id;事件附加信息;事件类型
{
HANDLE hd=RegisterEventSource(NULL,"CMCard");//指定/打开事件源
char* buff[1];
buff[0]=str;
int i;
if(hd){
i=ReportEvent(hd,wType,0,dwID,NULL,1,0,(LPCTSTR*)buff,NULL);//写日志
DeregisterEventSource(hd);//关闭事件源
if(i)return TRUE;
}
return FALSE;
}
''vb
Private Declare Function ReportEvent Lib "advapi32" Alias "ReportEventA" (ByVal hEventLog As Long, _
ByVal wType As Long, ByVal wCategory As Long, ByVal dwEventID As Long, ByVal lpUserSid As Long, _
ByVal wNumStrings As Long, ByVal dwDataSize As Long, lpStrings As Any, lpRawData As Any) As Long
''注意这个声明,与api text viewer的是不同的.注意As Any的妙用.
Function sysLog(byval lngID as long,byval strMsg As String,byval lngType as long) As Boolean
Dim hd As Long
Dim ret As Integer
hd = RegisterEventSource("", "CMCard")
If hd <> 0 Then
ret = ReportEvent(hd, lngType, 0, lngID, 0&, 1, 0, strMsg, 0)
DeregisterEventSource hd
End If
If ret <> 0 Then
sysLog = True
Else: sysLog = False
End If
End Function
四 .读日志的例子.
更多精彩
赞助商链接