Win32 API 日本語リファレンス
ホームSystem.EventLog › GetEventLogInformation

GetEventLogInformation

関数
イベントログに関する情報を取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// ADVAPI32.dll
#include <windows.h>

BOOL GetEventLogInformation(
    HANDLE hEventLog,
    DWORD dwInfoLevel,
    void* lpBuffer,
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded
);

パラメーター

名前方向
hEventLogHANDLEin
dwInfoLevelDWORDin
lpBuffervoid*out
cbBufSizeDWORDin
pcbBytesNeededDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

// ADVAPI32.dll
#include <windows.h>

BOOL GetEventLogInformation(
    HANDLE hEventLog,
    DWORD dwInfoLevel,
    void* lpBuffer,
    DWORD cbBufSize,
    DWORD* pcbBytesNeeded
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetEventLogInformation(
    IntPtr hEventLog,   // HANDLE
    uint dwInfoLevel,   // DWORD
    IntPtr lpBuffer,   // void* out
    uint cbBufSize,   // DWORD
    out uint pcbBytesNeeded   // DWORD* out
);
<DllImport("ADVAPI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetEventLogInformation(
    hEventLog As IntPtr,   ' HANDLE
    dwInfoLevel As UInteger,   ' DWORD
    lpBuffer As IntPtr,   ' void* out
    cbBufSize As UInteger,   ' DWORD
    <Out> ByRef pcbBytesNeeded As UInteger   ' DWORD* out
) As Boolean
End Function
' hEventLog : HANDLE
' dwInfoLevel : DWORD
' lpBuffer : void* out
' cbBufSize : DWORD
' pcbBytesNeeded : DWORD* out
Declare PtrSafe Function GetEventLogInformation Lib "advapi32" ( _
    ByVal hEventLog As LongPtr, _
    ByVal dwInfoLevel As Long, _
    ByVal lpBuffer As LongPtr, _
    ByVal cbBufSize As Long, _
    ByRef pcbBytesNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetEventLogInformation = ctypes.windll.advapi32.GetEventLogInformation
GetEventLogInformation.restype = wintypes.BOOL
GetEventLogInformation.argtypes = [
    wintypes.HANDLE,  # hEventLog : HANDLE
    wintypes.DWORD,  # dwInfoLevel : DWORD
    ctypes.POINTER(None),  # lpBuffer : void* out
    wintypes.DWORD,  # cbBufSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # pcbBytesNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
GetEventLogInformation = Fiddle::Function.new(
  lib['GetEventLogInformation'],
  [
    Fiddle::TYPE_VOIDP,  # hEventLog : HANDLE
    -Fiddle::TYPE_INT,  # dwInfoLevel : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuffer : void* out
    -Fiddle::TYPE_INT,  # cbBufSize : DWORD
    Fiddle::TYPE_VOIDP,  # pcbBytesNeeded : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn GetEventLogInformation(
        hEventLog: *mut core::ffi::c_void,  // HANDLE
        dwInfoLevel: u32,  // DWORD
        lpBuffer: *mut (),  // void* out
        cbBufSize: u32,  // DWORD
        pcbBytesNeeded: *mut u32  // DWORD* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("ADVAPI32.dll", SetLastError = true)]
public static extern bool GetEventLogInformation(IntPtr hEventLog, uint dwInfoLevel, IntPtr lpBuffer, uint cbBufSize, out uint pcbBytesNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetEventLogInformation' -Namespace Win32 -PassThru
# $api::GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#func global GetEventLogInformation "GetEventLogInformation" sptr, sptr, sptr, sptr, sptr
; GetEventLogInformation hEventLog, dwInfoLevel, lpBuffer, cbBufSize, varptr(pcbBytesNeeded)   ; 戻り値は stat
; hEventLog : HANDLE -> "sptr"
; dwInfoLevel : DWORD -> "sptr"
; lpBuffer : void* out -> "sptr"
; cbBufSize : DWORD -> "sptr"
; pcbBytesNeeded : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global GetEventLogInformation "GetEventLogInformation" sptr, int, sptr, int, var
; res = GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
; hEventLog : HANDLE -> "sptr"
; dwInfoLevel : DWORD -> "int"
; lpBuffer : void* out -> "sptr"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetEventLogInformation(HANDLE hEventLog, DWORD dwInfoLevel, void* lpBuffer, DWORD cbBufSize, DWORD* pcbBytesNeeded)
#uselib "ADVAPI32.dll"
#cfunc global GetEventLogInformation "GetEventLogInformation" intptr, int, intptr, int, var
; res = GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
; hEventLog : HANDLE -> "intptr"
; dwInfoLevel : DWORD -> "int"
; lpBuffer : void* out -> "intptr"
; cbBufSize : DWORD -> "int"
; pcbBytesNeeded : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetEventLogInformation = advapi32.NewProc("GetEventLogInformation")
)

// hEventLog (HANDLE), dwInfoLevel (DWORD), lpBuffer (void* out), cbBufSize (DWORD), pcbBytesNeeded (DWORD* out)
r1, _, err := procGetEventLogInformation.Call(
	uintptr(hEventLog),
	uintptr(dwInfoLevel),
	uintptr(lpBuffer),
	uintptr(cbBufSize),
	uintptr(pcbBytesNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetEventLogInformation(
  hEventLog: THandle;   // HANDLE
  dwInfoLevel: DWORD;   // DWORD
  lpBuffer: Pointer;   // void* out
  cbBufSize: DWORD;   // DWORD
  pcbBytesNeeded: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'ADVAPI32.dll' name 'GetEventLogInformation';
result := DllCall("ADVAPI32\GetEventLogInformation"
    , "Ptr", hEventLog   ; HANDLE
    , "UInt", dwInfoLevel   ; DWORD
    , "Ptr", lpBuffer   ; void* out
    , "UInt", cbBufSize   ; DWORD
    , "Ptr", pcbBytesNeeded   ; DWORD* out
    , "Int")   ; return: BOOL
●GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded) = DLL("ADVAPI32.dll", "bool GetEventLogInformation(void*, dword, void*, dword, void*)")
# 呼び出し: GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
# hEventLog : HANDLE -> "void*"
# dwInfoLevel : DWORD -> "dword"
# lpBuffer : void* out -> "void*"
# cbBufSize : DWORD -> "dword"
# pcbBytesNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。