想实现事件查看器的功能,但显示的描述内容有问题

hkg928515xj 2007-10-13 02:09:11
function GetEventIDText(EventID: DWORD; msgfile: string; pelr: PEVENTLOGRECORD): string;
var
hLib: THandle;
ret, flags, nSize,cchBuffer: DWORD;
ppc,pc, lpc: PChar;
i: Integer;
begin
result := '';
cchBuffer := 512;
flags := FORMAT_MESSAGE_FROM_HMODULE or
FORMAT_MESSAGE_ALLOCATE_BUFFER or
FORMAT_MESSAGE_ARGUMENT_ARRAY or
FORMAT_MESSAGE_IGNORE_INSERTS;
nSize := ExpandEnvironmentStrings(@msgfile[1], nil, 0) + 2;
GetMem(pc, nSize);
if Assigned(pc) then
try
ZeroMemory(pc, nSize);
ExpandEnvironmentStrings(@msgfile[1], pc, nSize);
for i := lstrlen(pc) - 1 downto 0 do
if pc[i] = ';' then
pc[i] := #0;
lpc := pc;
while lpc[0] <> #0 do
begin
hLib := LoadLibraryEx(lpc, 0, DONT_RESOLVE_DLL_REFERENCES);
inc(lpc, lstrlen(lpc) + 1);
if hLib <> 0 then
try
ret := FormatMessage(flags , Pointer(hLib), EventID, LANG_NEUTRAL, @ppc,cchBuffer, nil);
if ((ret = 0) and (GetLastError = ERROR_MR_MID_NOT_FOUND) and (lpc[0] <> #0)) then
Continue;
if ret<>0 then
Break;
finally
FreeLibrary(hLib);
end;
end;
if ret <> 0 then
SetString(result, ppc, lstrlen(ppc));
// Result:=StrPas(ppc) ;
if Assigned(ppc) then
LocalFree(THandle(ppc));
finally
Freemem(pc);
end;
// TODO: insert the replacement strings!
end;


我用这个还是获得事件描述内容,但是每次获得都是这样的:
%1 服务处于 %2 状态。
实际的错误是“IPSEC Services 服务处于 正在运行 状态。”

恳求各位老大帮忙
重谢!
...全文
77 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧