ホーム › System.EventLog › GetNumberOfEventLogRecords
GetNumberOfEventLogRecords
関数イベントログのレコード総数を取得する。
シグネチャ
// ADVAPI32.dll
#include <windows.h>
BOOL GetNumberOfEventLogRecords(
HANDLE hEventLog,
DWORD* NumberOfRecords
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hEventLog | HANDLE | in | オープンされたイベントログへのハンドル。このハンドルは OpenEventLog 関数または OpenBackupEventLog 関数によって返されます。 |
| NumberOfRecords | DWORD* | out | 指定したイベントログ内のレコード数を受け取る変数へのポインター。 |
戻り値の型: BOOL
公式ドキュメント
指定したイベントログ内のレコード数を取得します。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
イベントログ内の最も古いレコードは、必ずしもレコード番号 1 であるとは限りません。イベントログ内の最も古いレコード番号を判別するには、 GetOldestEventLogRecord 関数を使用します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "ADVAPI32.dll" #cfunc global GetNumberOfEventLogRecords "GetNumberOfEventLogRecords" sptr, sptr ; res = GetNumberOfEventLogRecords(hEventLog, varptr(NumberOfRecords)) ; hEventLog : HANDLE -> "sptr" ; NumberOfRecords : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL GetNumberOfEventLogRecords(HANDLE hEventLog, DWORD* NumberOfRecords) #uselib "ADVAPI32.dll" #cfunc global GetNumberOfEventLogRecords "GetNumberOfEventLogRecords" intptr, intptr ; res = GetNumberOfEventLogRecords(hEventLog, varptr(NumberOfRecords)) ; hEventLog : HANDLE -> "intptr" ; NumberOfRecords : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "advapi32" fn GetNumberOfEventLogRecords(
hEventLog: ?*anyopaque, // HANDLE
NumberOfRecords: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;proc GetNumberOfEventLogRecords(
hEventLog: pointer, # HANDLE
NumberOfRecords: ptr uint32 # DWORD* out
): int32 {.importc: "GetNumberOfEventLogRecords", stdcall, dynlib: "ADVAPI32.dll".}pragma(lib, "advapi32");
extern(Windows)
int GetNumberOfEventLogRecords(
void* hEventLog, // HANDLE
uint* NumberOfRecords // DWORD* out
);ccall((:GetNumberOfEventLogRecords, "ADVAPI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{UInt32}),
hEventLog, NumberOfRecords)
# hEventLog : HANDLE -> Ptr{Cvoid}
# NumberOfRecords : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetNumberOfEventLogRecords(
void* hEventLog,
uint32_t* NumberOfRecords);
]]
local advapi32 = ffi.load("advapi32")
-- advapi32.GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
-- hEventLog : HANDLE
-- NumberOfRecords : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('ADVAPI32.dll');
const GetNumberOfEventLogRecords = lib.func('__stdcall', 'GetNumberOfEventLogRecords', 'int32_t', ['void *', 'uint32_t *']);
// GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
// hEventLog : HANDLE -> 'void *'
// NumberOfRecords : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("ADVAPI32.dll", {
GetNumberOfEventLogRecords: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetNumberOfEventLogRecords(hEventLog, NumberOfRecords)
// hEventLog : HANDLE -> "pointer"
// NumberOfRecords : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetNumberOfEventLogRecords(
void* hEventLog,
uint32_t* NumberOfRecords);
C, "ADVAPI32.dll");
// $ffi->GetNumberOfEventLogRecords(hEventLog, NumberOfRecords);
// hEventLog : HANDLE
// NumberOfRecords : 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 GetNumberOfEventLogRecords(
Pointer hEventLog, // HANDLE
IntByReference NumberOfRecords // DWORD* out
);
}@[Link("advapi32")]
lib LibADVAPI32
fun GetNumberOfEventLogRecords = GetNumberOfEventLogRecords(
hEventLog : Void*, # HANDLE
NumberOfRecords : 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 GetNumberOfEventLogRecordsNative = Int32 Function(Pointer<Void>, Pointer<Uint32>);
typedef GetNumberOfEventLogRecordsDart = int Function(Pointer<Void>, Pointer<Uint32>);
final GetNumberOfEventLogRecords = DynamicLibrary.open('ADVAPI32.dll')
.lookupFunction<GetNumberOfEventLogRecordsNative, GetNumberOfEventLogRecordsDart>('GetNumberOfEventLogRecords');
// hEventLog : HANDLE -> Pointer<Void>
// NumberOfRecords : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetNumberOfEventLogRecords(
hEventLog: THandle; // HANDLE
NumberOfRecords: Pointer // DWORD* out
): BOOL; stdcall;
external 'ADVAPI32.dll' name 'GetNumberOfEventLogRecords';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetNumberOfEventLogRecords"
c_GetNumberOfEventLogRecords :: Ptr () -> Ptr Word32 -> IO CInt
-- hEventLog : HANDLE -> Ptr ()
-- NumberOfRecords : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getnumberofeventlogrecords =
foreign "GetNumberOfEventLogRecords"
((ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* hEventLog : HANDLE -> (ptr void) *)
(* NumberOfRecords : 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 ("GetNumberOfEventLogRecords" get-number-of-event-log-records :convention :stdcall) :int32
(h-event-log :pointer) ; HANDLE
(number-of-records :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetNumberOfEventLogRecords = Win32::API::More->new('ADVAPI32',
'BOOL GetNumberOfEventLogRecords(HANDLE hEventLog, LPVOID NumberOfRecords)');
# my $ret = $GetNumberOfEventLogRecords->Call($hEventLog, $NumberOfRecords);
# hEventLog : HANDLE -> HANDLE
# NumberOfRecords : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f GetOldestEventLogRecord — イベントログの最も古いレコード番号を取得する。
- f OpenBackupEventLogW — バックアップ済みイベントログを開く(Unicode版)。
- f OpenEventLogW — 指定したイベントログを開く(Unicode版)。