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

SetupDiGetHwProfileListExW

関数
リモート対応でハードウェアプロファイル一覧を取得する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiGetHwProfileListExW(
    DWORD* HwProfileList,
    DWORD HwProfileListSize,
    DWORD* RequiredSize,
    DWORD* CurrentlyActiveIndex,   // optional
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);

パラメーター

名前方向
HwProfileListDWORD*out
HwProfileListSizeDWORDin
RequiredSizeDWORD*out
CurrentlyActiveIndexDWORD*outoptional
MachineNameLPCWSTRinoptional
Reservedvoid*optional

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupDiGetHwProfileListExW(
    DWORD* HwProfileList,
    DWORD HwProfileListSize,
    DWORD* RequiredSize,
    DWORD* CurrentlyActiveIndex,   // optional
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetHwProfileListExW(
    out uint HwProfileList,   // DWORD* out
    uint HwProfileListSize,   // DWORD
    out uint RequiredSize,   // DWORD* out
    IntPtr CurrentlyActiveIndex,   // DWORD* optional, out
    [MarshalAs(UnmanagedType.LPWStr)] string MachineName,   // LPCWSTR optional
    IntPtr Reserved   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetHwProfileListExW(
    <Out> ByRef HwProfileList As UInteger,   ' DWORD* out
    HwProfileListSize As UInteger,   ' DWORD
    <Out> ByRef RequiredSize As UInteger,   ' DWORD* out
    CurrentlyActiveIndex As IntPtr,   ' DWORD* optional, out
    <MarshalAs(UnmanagedType.LPWStr)> MachineName As String,   ' LPCWSTR optional
    Reserved As IntPtr   ' void* optional
) As Boolean
End Function
' HwProfileList : DWORD* out
' HwProfileListSize : DWORD
' RequiredSize : DWORD* out
' CurrentlyActiveIndex : DWORD* optional, out
' MachineName : LPCWSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiGetHwProfileListExW Lib "setupapi" ( _
    ByRef HwProfileList As Long, _
    ByVal HwProfileListSize As Long, _
    ByRef RequiredSize As Long, _
    ByVal CurrentlyActiveIndex As LongPtr, _
    ByVal MachineName As LongPtr, _
    ByVal Reserved As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiGetHwProfileListExW = ctypes.windll.setupapi.SetupDiGetHwProfileListExW
SetupDiGetHwProfileListExW.restype = wintypes.BOOL
SetupDiGetHwProfileListExW.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # HwProfileList : DWORD* out
    wintypes.DWORD,  # HwProfileListSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RequiredSize : DWORD* out
    ctypes.POINTER(wintypes.DWORD),  # CurrentlyActiveIndex : DWORD* optional, out
    wintypes.LPCWSTR,  # MachineName : LPCWSTR optional
    ctypes.POINTER(None),  # Reserved : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiGetHwProfileListExW = Fiddle::Function.new(
  lib['SetupDiGetHwProfileListExW'],
  [
    Fiddle::TYPE_VOIDP,  # HwProfileList : DWORD* out
    -Fiddle::TYPE_INT,  # HwProfileListSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # CurrentlyActiveIndex : DWORD* optional, out
    Fiddle::TYPE_VOIDP,  # MachineName : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiGetHwProfileListExW(
        HwProfileList: *mut u32,  // DWORD* out
        HwProfileListSize: u32,  // DWORD
        RequiredSize: *mut u32,  // DWORD* out
        CurrentlyActiveIndex: *mut u32,  // DWORD* optional, out
        MachineName: *const u16,  // LPCWSTR optional
        Reserved: *mut ()  // void* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiGetHwProfileListExW(out uint HwProfileList, uint HwProfileListSize, out uint RequiredSize, IntPtr CurrentlyActiveIndex, [MarshalAs(UnmanagedType.LPWStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetHwProfileListExW' -Namespace Win32 -PassThru
# $api::SetupDiGetHwProfileListExW(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiGetHwProfileListExW "SetupDiGetHwProfileListExW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiGetHwProfileListExW varptr(HwProfileList), HwProfileListSize, varptr(RequiredSize), varptr(CurrentlyActiveIndex), MachineName, Reserved   ; 戻り値は stat
; HwProfileList : DWORD* out -> "wptr"
; HwProfileListSize : DWORD -> "wptr"
; RequiredSize : DWORD* out -> "wptr"
; CurrentlyActiveIndex : DWORD* optional, out -> "wptr"
; MachineName : LPCWSTR optional -> "wptr"
; Reserved : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileListExW "SetupDiGetHwProfileListExW" var, int, var, var, wstr, sptr
; res = SetupDiGetHwProfileListExW(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
; HwProfileList : DWORD* out -> "var"
; HwProfileListSize : DWORD -> "int"
; RequiredSize : DWORD* out -> "var"
; CurrentlyActiveIndex : DWORD* optional, out -> "var"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetHwProfileListExW(DWORD* HwProfileList, DWORD HwProfileListSize, DWORD* RequiredSize, DWORD* CurrentlyActiveIndex, LPCWSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileListExW "SetupDiGetHwProfileListExW" var, int, var, var, wstr, intptr
; res = SetupDiGetHwProfileListExW(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
; HwProfileList : DWORD* out -> "var"
; HwProfileListSize : DWORD -> "int"
; RequiredSize : DWORD* out -> "var"
; CurrentlyActiveIndex : DWORD* optional, out -> "var"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetHwProfileListExW = setupapi.NewProc("SetupDiGetHwProfileListExW")
)

// HwProfileList (DWORD* out), HwProfileListSize (DWORD), RequiredSize (DWORD* out), CurrentlyActiveIndex (DWORD* optional, out), MachineName (LPCWSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiGetHwProfileListExW.Call(
	uintptr(HwProfileList),
	uintptr(HwProfileListSize),
	uintptr(RequiredSize),
	uintptr(CurrentlyActiveIndex),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MachineName))),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetHwProfileListExW(
  HwProfileList: Pointer;   // DWORD* out
  HwProfileListSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* out
  CurrentlyActiveIndex: Pointer;   // DWORD* optional, out
  MachineName: PWideChar;   // LPCWSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetHwProfileListExW';
result := DllCall("SETUPAPI\SetupDiGetHwProfileListExW"
    , "Ptr", HwProfileList   ; DWORD* out
    , "UInt", HwProfileListSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* out
    , "Ptr", CurrentlyActiveIndex   ; DWORD* optional, out
    , "WStr", MachineName   ; LPCWSTR optional
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiGetHwProfileListExW(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiGetHwProfileListExW(void*, dword, void*, void*, char*, void*)")
# 呼び出し: SetupDiGetHwProfileListExW(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
# HwProfileList : DWORD* out -> "void*"
# HwProfileListSize : DWORD -> "dword"
# RequiredSize : DWORD* out -> "void*"
# CurrentlyActiveIndex : DWORD* optional, out -> "void*"
# MachineName : LPCWSTR optional -> "char*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。