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

EnumDeviceDrivers

関数
システムにロードされたデバイスドライバを列挙する。
DLLPSAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

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

パラメーター

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

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL EnumDeviceDrivers(
    void** lpImageBase,
    DWORD cb,
    DWORD* lpcbNeeded
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("PSAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool EnumDeviceDrivers(
    IntPtr lpImageBase,   // void** out
    uint cb,   // DWORD
    out uint lpcbNeeded   // DWORD* out
);
<DllImport("PSAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function EnumDeviceDrivers(
    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 EnumDeviceDrivers Lib "psapi" ( _
    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

EnumDeviceDrivers = ctypes.windll.psapi.EnumDeviceDrivers
EnumDeviceDrivers.restype = wintypes.BOOL
EnumDeviceDrivers.argtypes = [
    ctypes.c_void_p,  # lpImageBase : void** out
    wintypes.DWORD,  # cb : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpcbNeeded : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	psapi = windows.NewLazySystemDLL("PSAPI.dll")
	procEnumDeviceDrivers = psapi.NewProc("EnumDeviceDrivers")
)

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