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

GetNumberOfEventLogRecords

関数
イベントログのレコード総数を取得する。
DLLADVAPI32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL GetNumberOfEventLogRecords(
    HANDLE hEventLog,
    DWORD* NumberOfRecords
);

パラメーター

名前方向
hEventLogHANDLEin
NumberOfRecordsDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

GetNumberOfEventLogRecords = ctypes.windll.advapi32.GetNumberOfEventLogRecords
GetNumberOfEventLogRecords.restype = wintypes.BOOL
GetNumberOfEventLogRecords.argtypes = [
    wintypes.HANDLE,  # hEventLog : HANDLE
    ctypes.POINTER(wintypes.DWORD),  # NumberOfRecords : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('ADVAPI32.dll')
GetNumberOfEventLogRecords = Fiddle::Function.new(
  lib['GetNumberOfEventLogRecords'],
  [
    Fiddle::TYPE_VOIDP,  # hEventLog : HANDLE
    Fiddle::TYPE_VOIDP,  # NumberOfRecords : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "advapi32")]
extern "system" {
    fn GetNumberOfEventLogRecords(
        hEventLog: *mut core::ffi::c_void,  // HANDLE
        NumberOfRecords: *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 GetNumberOfEventLogRecords(IntPtr hEventLog, out uint NumberOfRecords);
"@
$api = Add-Type -MemberDefinition $sig -Name 'ADVAPI32_GetNumberOfEventLogRecords' -Namespace Win32 -PassThru
# $api::GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
#uselib "ADVAPI32.dll"
#func global GetNumberOfEventLogRecords "GetNumberOfEventLogRecords" sptr, sptr
; GetNumberOfEventLogRecords hEventLog, varptr(NumberOfRecords)   ; 戻り値は stat
; hEventLog : HANDLE -> "sptr"
; NumberOfRecords : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "ADVAPI32.dll"
#cfunc global GetNumberOfEventLogRecords "GetNumberOfEventLogRecords" sptr, var
; res = GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
; hEventLog : HANDLE -> "sptr"
; NumberOfRecords : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetNumberOfEventLogRecords(HANDLE hEventLog, DWORD* NumberOfRecords)
#uselib "ADVAPI32.dll"
#cfunc global GetNumberOfEventLogRecords "GetNumberOfEventLogRecords" intptr, var
; res = GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
; hEventLog : HANDLE -> "intptr"
; NumberOfRecords : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetNumberOfEventLogRecords = advapi32.NewProc("GetNumberOfEventLogRecords")
)

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