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イベントログへのハンドル。 OpenEventLog 関数または RegisterEventSource 関数がこのハンドルを返します。
dwInfoLevelDWORDin

返すイベントログ情報のレベル。

このパラメーターには次の値を指定できます。

意味
EVENTLOG_FULL_INFO
指定されたログが満杯かどうかを示します。lpBuffer パラメーターには EVENTLOG_FULL_INFORMATION 構造体が格納されます。
lpBuffervoid*outイベントログ情報を受け取る、アプリケーションが割り当てたバッファー。このデータの形式は dwInfoLevel パラメーターの値によって異なります。
cbBufSizeDWORDinlpBuffer バッファーのサイズ(バイト単位)。
pcbBytesNeededDWORD*out関数の成否にかかわらず、要求された情報に必要なバッファーサイズがこのパラメーターに設定されます。関数が ERROR_INSUFFICIENT_BUFFER で失敗した場合は、この値を使用して正しいサイズのバッファーを割り当ててください。

戻り値の型: BOOL

公式ドキュメント

指定されたイベントログに関する情報を取得します。

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "advapi32" fn GetEventLogInformation(
    hEventLog: ?*anyopaque, // HANDLE
    dwInfoLevel: u32, // DWORD
    lpBuffer: ?*anyopaque, // void* out
    cbBufSize: u32, // DWORD
    pcbBytesNeeded: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;
proc GetEventLogInformation(
    hEventLog: pointer,  # HANDLE
    dwInfoLevel: uint32,  # DWORD
    lpBuffer: pointer,  # void* out
    cbBufSize: uint32,  # DWORD
    pcbBytesNeeded: ptr uint32  # DWORD* out
): int32 {.importc: "GetEventLogInformation", stdcall, dynlib: "ADVAPI32.dll".}
pragma(lib, "advapi32");
extern(Windows)
int GetEventLogInformation(
    void* hEventLog,   // HANDLE
    uint dwInfoLevel,   // DWORD
    void* lpBuffer,   // void* out
    uint cbBufSize,   // DWORD
    uint* pcbBytesNeeded   // DWORD* out
);
ccall((:GetEventLogInformation, "ADVAPI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
      hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
# hEventLog : HANDLE -> Ptr{Cvoid}
# dwInfoLevel : DWORD -> UInt32
# lpBuffer : void* out -> Ptr{Cvoid}
# cbBufSize : DWORD -> UInt32
# pcbBytesNeeded : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetEventLogInformation(
    void* hEventLog,
    uint32_t dwInfoLevel,
    void* lpBuffer,
    uint32_t cbBufSize,
    uint32_t* pcbBytesNeeded);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
-- hEventLog : HANDLE
-- dwInfoLevel : DWORD
-- lpBuffer : void* out
-- cbBufSize : DWORD
-- pcbBytesNeeded : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetEventLogInformation = lib.func('__stdcall', 'GetEventLogInformation', 'int32_t', ['void *', 'uint32_t', 'void *', 'uint32_t', 'uint32_t *']);
// GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
// hEventLog : HANDLE -> 'void *'
// dwInfoLevel : DWORD -> 'uint32_t'
// lpBuffer : void* out -> 'void *'
// cbBufSize : DWORD -> 'uint32_t'
// pcbBytesNeeded : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("ADVAPI32.dll", {
  GetEventLogInformation: { parameters: ["pointer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
// hEventLog : HANDLE -> "pointer"
// dwInfoLevel : DWORD -> "u32"
// lpBuffer : void* out -> "pointer"
// cbBufSize : DWORD -> "u32"
// pcbBytesNeeded : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetEventLogInformation(
    void* hEventLog,
    uint32_t dwInfoLevel,
    void* lpBuffer,
    uint32_t cbBufSize,
    uint32_t* pcbBytesNeeded);
C, "ADVAPI32.dll");
// $ffi->GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
// hEventLog : HANDLE
// dwInfoLevel : DWORD
// lpBuffer : void* out
// cbBufSize : DWORD
// pcbBytesNeeded : DWORD* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Advapi32 extends StdCallLibrary {
    Advapi32 INSTANCE = Native.load("advapi32", Advapi32.class);
    boolean GetEventLogInformation(
        Pointer hEventLog,   // HANDLE
        int dwInfoLevel,   // DWORD
        Pointer lpBuffer,   // void* out
        int cbBufSize,   // DWORD
        IntByReference pcbBytesNeeded   // DWORD* out
    );
}
@[Link("advapi32")]
lib LibADVAPI32
  fun GetEventLogInformation = GetEventLogInformation(
    hEventLog : Void*,   # HANDLE
    dwInfoLevel : UInt32,   # DWORD
    lpBuffer : Void*,   # void* out
    cbBufSize : UInt32,   # DWORD
    pcbBytesNeeded : UInt32*   # DWORD* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetEventLogInformationNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef GetEventLogInformationDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Uint32>);
final GetEventLogInformation = DynamicLibrary.open('ADVAPI32.dll')
    .lookupFunction<GetEventLogInformationNative, GetEventLogInformationDart>('GetEventLogInformation');
// hEventLog : HANDLE -> Pointer<Void>
// dwInfoLevel : DWORD -> Uint32
// lpBuffer : void* out -> Pointer<Void>
// cbBufSize : DWORD -> Uint32
// pcbBytesNeeded : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetEventLogInformation"
  c_GetEventLogInformation :: Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO CInt
-- hEventLog : HANDLE -> Ptr ()
-- dwInfoLevel : DWORD -> Word32
-- lpBuffer : void* out -> Ptr ()
-- cbBufSize : DWORD -> Word32
-- pcbBytesNeeded : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let geteventloginformation =
  foreign "GetEventLogInformation"
    ((ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hEventLog : HANDLE -> (ptr void) *)
(* dwInfoLevel : DWORD -> uint32_t *)
(* lpBuffer : void* out -> (ptr void) *)
(* cbBufSize : DWORD -> uint32_t *)
(* pcbBytesNeeded : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library advapi32 (t "ADVAPI32.dll"))
(cffi:use-foreign-library advapi32)

(cffi:defcfun ("GetEventLogInformation" get-event-log-information :convention :stdcall) :int32
  (h-event-log :pointer)   ; HANDLE
  (dw-info-level :uint32)   ; DWORD
  (lp-buffer :pointer)   ; void* out
  (cb-buf-size :uint32)   ; DWORD
  (pcb-bytes-needed :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetEventLogInformation = Win32::API::More->new('ADVAPI32',
    'BOOL GetEventLogInformation(HANDLE hEventLog, DWORD dwInfoLevel, LPVOID lpBuffer, DWORD cbBufSize, LPVOID pcbBytesNeeded)');
# my $ret = $GetEventLogInformation->Call($hEventLog, $dwInfoLevel, $lpBuffer, $cbBufSize, $pcbBytesNeeded);
# hEventLog : HANDLE -> HANDLE
# dwInfoLevel : DWORD -> DWORD
# lpBuffer : void* out -> LPVOID
# cbBufSize : DWORD -> DWORD
# pcbBytesNeeded : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目