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

K32EnumDeviceDrivers

関数
システムにロードされたデバイスドライバを列挙する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

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

BOOL K32EnumDeviceDrivers(
    void** lpImageBase,
    DWORD cb,
    DWORD* lpcbNeeded
);

パラメーター

名前方向
lpImageBasevoid**out
cbDWORDin
lpcbNeededDWORD*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

K32EnumDeviceDrivers = ctypes.windll.kernel32.K32EnumDeviceDrivers
K32EnumDeviceDrivers.restype = wintypes.BOOL
K32EnumDeviceDrivers.argtypes = [
    ctypes.c_void_p,  # lpImageBase : void** out
    wintypes.DWORD,  # cb : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpcbNeeded : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procK32EnumDeviceDrivers = kernel32.NewProc("K32EnumDeviceDrivers")
)

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