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

GetOldestEventLogRecord

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

シグネチャ

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

BOOL GetOldestEventLogRecord(
    HANDLE hEventLog,
    DWORD* OldestRecord
);

パラメーター

名前方向
hEventLogHANDLEin
OldestRecordDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	advapi32 = windows.NewLazySystemDLL("ADVAPI32.dll")
	procGetOldestEventLogRecord = advapi32.NewProc("GetOldestEventLogRecord")
)

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