使用 EvtSetChannelConfigProperty() 函数时出现访问冲突错误

Access violation error while using EvtSetChannelConfigProperty() function

本文关键字:访问冲突 错误 函数 EvtSetChannelConfigProperty 使用      更新时间:2023-10-16

>我正在尝试使用EvtSetChannelConfigProperty()功能。我在运行程序时收到访问冲突。

我在管理员模式下运行Visual Studio。它仍然显示访问冲突。

我添加了<winevt.h>头文件:

PEVT_VARIANT value;
UINT64 val = 30000000;
value = PEVT_VARIANT(val);
EVT_HANDLE hlog = EvtOpenChannelConfig(NULL,L"Application",0);
BOOL check = EvtSetChannelConfigProperty(hlog,EvtChannelLoggingConfigMaxSize, 0, value);

为什么我收到一条错误消息,指出读取位置时存在访问冲突?

错误:

'Windows_API.exe' (Win32): Loaded 
'C:UsersAdministratorsourcereposWindows_APIx64DebugWindows_API.exe'. 
Symbols loaded.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32ntdll.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32kernel32.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32KernelBase.dll'. 
Cannot find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32apphelp.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32advapi32.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32msvcrt.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32sechost.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32rpcrt4.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32msvcp140d.dll'. 
Cannot find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32ucrtbased.dll'. 
Cannot find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32vcruntime140d.dll'. 
Cannot find or open the PDB file.
'Windows_API.exe' (Win32): Unloaded 'C:WindowsSystem32vcruntime140d.dll'
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32vcruntime140d.dll'. 
Cannot find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32wevtapi.dll'. Cannot 
find or open the PDB file.
'Windows_API.exe' (Win32): Loaded 'C:WindowsSystem32bcrypt.dll'. Cannot 
find or open the PDB file.
Exception thrown at 0x00007FFBB52C6749 (wevtapi.dll) in Windows_API.exe: 
0xC0000005: Access violation reading location 0x0000000001C9C38C.
The program '[7672] Windows_API.exe' has exited with code 0 (0x0).

value是一个未初始化的指针器,无处可去。因此,当EvtSetChannelConfigProperty尝试取消引用该指针时,程序会崩溃。

你可能想要这样的东西:

EVT_VARIANT value;
value.Count = 0;
value.Type = EvtVarTypeUInt64;
value.UInt64Val = 3000000;
EVT_HANDLE hlog = EvtOpenChannelConfig(NULL, L"Application", 0);
BOOL check = EvtSetChannelConfigProperty(hlog, EvtChannelLoggingConfigMaxSize, 0, &value);

顺便说一句,您无需为此处于管理员模式。