Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupDiOpenDeviceInfoA

SetupDiOpenDeviceInfoA

関数
インスタンスIDで既存デバイスを開き情報セットに追加する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiOpenDeviceInfoA(
    HDEVINFO DeviceInfoSet,
    LPCSTR DeviceInstanceId,
    HWND hwndParent,   // optional
    DWORD OpenFlags,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);

パラメーター

名前方向
DeviceInfoSetHDEVINFOin
DeviceInstanceIdLPCSTRin
hwndParentHWNDinoptional
OpenFlagsDWORDin
DeviceInfoDataSP_DEVINFO_DATA*inoutoptional

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupDiOpenDeviceInfoA(
    HDEVINFO DeviceInfoSet,
    LPCSTR DeviceInstanceId,
    HWND hwndParent,   // optional
    DWORD OpenFlags,
    SP_DEVINFO_DATA* DeviceInfoData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiOpenDeviceInfoA(
    IntPtr DeviceInfoSet,   // HDEVINFO
    [MarshalAs(UnmanagedType.LPStr)] string DeviceInstanceId,   // LPCSTR
    IntPtr hwndParent,   // HWND optional
    uint OpenFlags,   // DWORD
    IntPtr DeviceInfoData   // SP_DEVINFO_DATA* optional, in/out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiOpenDeviceInfoA(
    DeviceInfoSet As IntPtr,   ' HDEVINFO
    <MarshalAs(UnmanagedType.LPStr)> DeviceInstanceId As String,   ' LPCSTR
    hwndParent As IntPtr,   ' HWND optional
    OpenFlags As UInteger,   ' DWORD
    DeviceInfoData As IntPtr   ' SP_DEVINFO_DATA* optional, in/out
) As Boolean
End Function
' DeviceInfoSet : HDEVINFO
' DeviceInstanceId : LPCSTR
' hwndParent : HWND optional
' OpenFlags : DWORD
' DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
Declare PtrSafe Function SetupDiOpenDeviceInfoA Lib "setupapi" ( _
    ByVal DeviceInfoSet As LongPtr, _
    ByVal DeviceInstanceId As String, _
    ByVal hwndParent As LongPtr, _
    ByVal OpenFlags As Long, _
    ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiOpenDeviceInfoA = ctypes.windll.setupapi.SetupDiOpenDeviceInfoA
SetupDiOpenDeviceInfoA.restype = wintypes.BOOL
SetupDiOpenDeviceInfoA.argtypes = [
    ctypes.c_ssize_t,  # DeviceInfoSet : HDEVINFO
    wintypes.LPCSTR,  # DeviceInstanceId : LPCSTR
    wintypes.HANDLE,  # hwndParent : HWND optional
    wintypes.DWORD,  # OpenFlags : DWORD
    ctypes.c_void_p,  # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiOpenDeviceInfoA = Fiddle::Function.new(
  lib['SetupDiOpenDeviceInfoA'],
  [
    Fiddle::TYPE_INTPTR_T,  # DeviceInfoSet : HDEVINFO
    Fiddle::TYPE_VOIDP,  # DeviceInstanceId : LPCSTR
    Fiddle::TYPE_VOIDP,  # hwndParent : HWND optional
    -Fiddle::TYPE_INT,  # OpenFlags : DWORD
    Fiddle::TYPE_VOIDP,  # DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiOpenDeviceInfoA(
        DeviceInfoSet: isize,  // HDEVINFO
        DeviceInstanceId: *const u8,  // LPCSTR
        hwndParent: *mut core::ffi::c_void,  // HWND optional
        OpenFlags: u32,  // DWORD
        DeviceInfoData: *mut SP_DEVINFO_DATA  // SP_DEVINFO_DATA* optional, in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupDiOpenDeviceInfoA(IntPtr DeviceInfoSet, [MarshalAs(UnmanagedType.LPStr)] string DeviceInstanceId, IntPtr hwndParent, uint OpenFlags, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiOpenDeviceInfoA' -Namespace Win32 -PassThru
# $api::SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
#uselib "SETUPAPI.dll"
#func global SetupDiOpenDeviceInfoA "SetupDiOpenDeviceInfoA" sptr, sptr, sptr, sptr, sptr
; SetupDiOpenDeviceInfoA DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, varptr(DeviceInfoData)   ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInstanceId : LPCSTR -> "sptr"
; hwndParent : HWND optional -> "sptr"
; OpenFlags : DWORD -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiOpenDeviceInfoA "SetupDiOpenDeviceInfoA" sptr, str, sptr, int, var
; res = SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInstanceId : LPCSTR -> "str"
; hwndParent : HWND optional -> "sptr"
; OpenFlags : DWORD -> "int"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiOpenDeviceInfoA(HDEVINFO DeviceInfoSet, LPCSTR DeviceInstanceId, HWND hwndParent, DWORD OpenFlags, SP_DEVINFO_DATA* DeviceInfoData)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiOpenDeviceInfoA "SetupDiOpenDeviceInfoA" intptr, str, intptr, int, var
; res = SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
; DeviceInfoSet : HDEVINFO -> "intptr"
; DeviceInstanceId : LPCSTR -> "str"
; hwndParent : HWND optional -> "intptr"
; OpenFlags : DWORD -> "int"
; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiOpenDeviceInfoA = setupapi.NewProc("SetupDiOpenDeviceInfoA")
)

// DeviceInfoSet (HDEVINFO), DeviceInstanceId (LPCSTR), hwndParent (HWND optional), OpenFlags (DWORD), DeviceInfoData (SP_DEVINFO_DATA* optional, in/out)
r1, _, err := procSetupDiOpenDeviceInfoA.Call(
	uintptr(DeviceInfoSet),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(DeviceInstanceId))),
	uintptr(hwndParent),
	uintptr(OpenFlags),
	uintptr(DeviceInfoData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiOpenDeviceInfoA(
  DeviceInfoSet: NativeInt;   // HDEVINFO
  DeviceInstanceId: PAnsiChar;   // LPCSTR
  hwndParent: THandle;   // HWND optional
  OpenFlags: DWORD;   // DWORD
  DeviceInfoData: Pointer   // SP_DEVINFO_DATA* optional, in/out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiOpenDeviceInfoA';
result := DllCall("SETUPAPI\SetupDiOpenDeviceInfoA"
    , "Ptr", DeviceInfoSet   ; HDEVINFO
    , "AStr", DeviceInstanceId   ; LPCSTR
    , "Ptr", hwndParent   ; HWND optional
    , "UInt", OpenFlags   ; DWORD
    , "Ptr", DeviceInfoData   ; SP_DEVINFO_DATA* optional, in/out
    , "Int")   ; return: BOOL
●SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiOpenDeviceInfoA(int, char*, void*, dword, void*)")
# 呼び出し: SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInstanceId : LPCSTR -> "char*"
# hwndParent : HWND optional -> "void*"
# OpenFlags : DWORD -> "dword"
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。