ホーム › Devices.DeviceAndDriverInstallation › SetupDiOpenDeviceInfoA
SetupDiOpenDeviceInfoA
関数インスタンスIDで既存デバイスを開き情報セットに追加する。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupDiOpenDeviceInfoA(
HDEVINFO DeviceInfoSet,
LPCSTR DeviceInstanceId,
HWND hwndParent, // optional
DWORD OpenFlags,
SP_DEVINFO_DATA* DeviceInfoData // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | デバイス要素を追加する対象のデバイス情報セット。 |
| DeviceInstanceId | LPCSTR | in | 開く既存デバイスのインスタンスID(ANSI)。 |
| hwndParent | HWND | inoptional | UI表示時の親ウィンドウハンドル。NULL可。 |
| OpenFlags | DWORD | in | DIOD_*系のオープン動作を制御するフラグ。 |
| DeviceInfoData | SP_DEVINFO_DATA* | inoutoptional | 開いた要素情報を受け取るSP_DEVINFO_DATAへのポインタ(出力)。NULL可。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiOpenDeviceInfoA "SetupDiOpenDeviceInfoA" sptr, str, sptr, int, sptr ; res = SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInstanceId : LPCSTR -> "str" ; hwndParent : HWND optional -> "sptr" ; OpenFlags : DWORD -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr ; res = SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInstanceId : LPCSTR -> "str" ; hwndParent : HWND optional -> "intptr" ; OpenFlags : DWORD -> "int" ; DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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)。const std = @import("std");
extern "setupapi" fn SetupDiOpenDeviceInfoA(
DeviceInfoSet: isize, // HDEVINFO
DeviceInstanceId: [*c]const u8, // LPCSTR
hwndParent: ?*anyopaque, // HWND optional
OpenFlags: u32, // DWORD
DeviceInfoData: [*c]SP_DEVINFO_DATA // SP_DEVINFO_DATA* optional, in/out
) callconv(std.os.windows.WINAPI) i32;proc SetupDiOpenDeviceInfoA(
DeviceInfoSet: int, # HDEVINFO
DeviceInstanceId: cstring, # LPCSTR
hwndParent: pointer, # HWND optional
OpenFlags: uint32, # DWORD
DeviceInfoData: ptr SP_DEVINFO_DATA # SP_DEVINFO_DATA* optional, in/out
): int32 {.importc: "SetupDiOpenDeviceInfoA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiOpenDeviceInfoA(
ptrdiff_t DeviceInfoSet, // HDEVINFO
const(char)* DeviceInstanceId, // LPCSTR
void* hwndParent, // HWND optional
uint OpenFlags, // DWORD
SP_DEVINFO_DATA* DeviceInfoData // SP_DEVINFO_DATA* optional, in/out
);ccall((:SetupDiOpenDeviceInfoA, "SETUPAPI.dll"), stdcall, Int32,
(Int, Cstring, Ptr{Cvoid}, UInt32, Ptr{SP_DEVINFO_DATA}),
DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInstanceId : LPCSTR -> Cstring
# hwndParent : HWND optional -> Ptr{Cvoid}
# OpenFlags : DWORD -> UInt32
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Ptr{SP_DEVINFO_DATA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiOpenDeviceInfoA(
intptr_t DeviceInfoSet,
const char* DeviceInstanceId,
void* hwndParent,
uint32_t OpenFlags,
void* DeviceInfoData);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
-- DeviceInfoSet : HDEVINFO
-- DeviceInstanceId : LPCSTR
-- hwndParent : HWND optional
-- OpenFlags : DWORD
-- DeviceInfoData : SP_DEVINFO_DATA* optional, in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiOpenDeviceInfoA = lib.func('__stdcall', 'SetupDiOpenDeviceInfoA', 'int32_t', ['intptr_t', 'str', 'void *', 'uint32_t', 'void *']);
// SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInstanceId : LPCSTR -> 'str'
// hwndParent : HWND optional -> 'void *'
// OpenFlags : DWORD -> 'uint32_t'
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiOpenDeviceInfoA: { parameters: ["isize", "buffer", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInstanceId : LPCSTR -> "buffer"
// hwndParent : HWND optional -> "pointer"
// OpenFlags : DWORD -> "u32"
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiOpenDeviceInfoA(
intptr_t DeviceInfoSet,
const char* DeviceInstanceId,
void* hwndParent,
uint32_t OpenFlags,
void* DeviceInfoData);
C, "SETUPAPI.dll");
// $ffi->SetupDiOpenDeviceInfoA(DeviceInfoSet, DeviceInstanceId, hwndParent, OpenFlags, DeviceInfoData);
// DeviceInfoSet : HDEVINFO
// DeviceInstanceId : LPCSTR
// hwndParent : HWND optional
// OpenFlags : DWORD
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/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 Setupapi extends StdCallLibrary {
Setupapi INSTANCE = Native.load("setupapi", Setupapi.class, W32APIOptions.ASCII_OPTIONS);
boolean SetupDiOpenDeviceInfoA(
long DeviceInfoSet, // HDEVINFO
String DeviceInstanceId, // LPCSTR
Pointer hwndParent, // HWND optional
int OpenFlags, // DWORD
Pointer DeviceInfoData // SP_DEVINFO_DATA* optional, in/out
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiOpenDeviceInfoA = SetupDiOpenDeviceInfoA(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInstanceId : UInt8*, # LPCSTR
hwndParent : Void*, # HWND optional
OpenFlags : UInt32, # DWORD
DeviceInfoData : SP_DEVINFO_DATA* # SP_DEVINFO_DATA* optional, in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiOpenDeviceInfoANative = Int32 Function(IntPtr, Pointer<Utf8>, Pointer<Void>, Uint32, Pointer<Void>);
typedef SetupDiOpenDeviceInfoADart = int Function(int, Pointer<Utf8>, Pointer<Void>, int, Pointer<Void>);
final SetupDiOpenDeviceInfoA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiOpenDeviceInfoANative, SetupDiOpenDeviceInfoADart>('SetupDiOpenDeviceInfoA');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInstanceId : LPCSTR -> Pointer<Utf8>
// hwndParent : HWND optional -> Pointer<Void>
// OpenFlags : DWORD -> Uint32
// DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiOpenDeviceInfoA"
c_SetupDiOpenDeviceInfoA :: CIntPtr -> CString -> Ptr () -> Word32 -> Ptr () -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInstanceId : LPCSTR -> CString
-- hwndParent : HWND optional -> Ptr ()
-- OpenFlags : DWORD -> Word32
-- DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdiopendeviceinfoa =
foreign "SetupDiOpenDeviceInfoA"
(intptr_t @-> string @-> (ptr void) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInstanceId : LPCSTR -> string *)
(* hwndParent : HWND optional -> (ptr void) *)
(* OpenFlags : DWORD -> uint32_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiOpenDeviceInfoA" setup-di-open-device-info-a :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-instance-id :string) ; LPCSTR
(hwnd-parent :pointer) ; HWND optional
(open-flags :uint32) ; DWORD
(device-info-data :pointer)) ; SP_DEVINFO_DATA* optional, in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiOpenDeviceInfoA = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiOpenDeviceInfoA(LPARAM DeviceInfoSet, LPCSTR DeviceInstanceId, HANDLE hwndParent, DWORD OpenFlags, LPVOID DeviceInfoData)');
# my $ret = $SetupDiOpenDeviceInfoA->Call($DeviceInfoSet, $DeviceInstanceId, $hwndParent, $OpenFlags, $DeviceInfoData);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInstanceId : LPCSTR -> LPCSTR
# hwndParent : HWND optional -> HANDLE
# OpenFlags : DWORD -> DWORD
# DeviceInfoData : SP_DEVINFO_DATA* optional, in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupDiOpenDeviceInfoW (Unicode版) — インスタンスIDで既存デバイスを開き情報セットに追加する。
使用する型