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

SetupDiGetHwProfileListExA

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

シグネチャ

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

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

パラメーター

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

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiGetHwProfileListExA(
    DWORD* HwProfileList,
    DWORD HwProfileListSize,
    DWORD* RequiredSize,
    DWORD* CurrentlyActiveIndex,   // optional
    LPCSTR MachineName,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetHwProfileListExA(
    out uint HwProfileList,   // DWORD* out
    uint HwProfileListSize,   // DWORD
    out uint RequiredSize,   // DWORD* out
    IntPtr CurrentlyActiveIndex,   // DWORD* optional, out
    [MarshalAs(UnmanagedType.LPStr)] string MachineName,   // LPCSTR optional
    IntPtr Reserved   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiGetHwProfileListExA(
    <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.LPStr)> MachineName As String,   ' LPCSTR optional
    Reserved As IntPtr   ' void* optional
) As Boolean
End Function
' HwProfileList : DWORD* out
' HwProfileListSize : DWORD
' RequiredSize : DWORD* out
' CurrentlyActiveIndex : DWORD* optional, out
' MachineName : LPCSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiGetHwProfileListExA Lib "setupapi" ( _
    ByRef HwProfileList As Long, _
    ByVal HwProfileListSize As Long, _
    ByRef RequiredSize As Long, _
    ByVal CurrentlyActiveIndex As LongPtr, _
    ByVal MachineName As String, _
    ByVal Reserved As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupDiGetHwProfileListExA = ctypes.windll.setupapi.SetupDiGetHwProfileListExA
SetupDiGetHwProfileListExA.restype = wintypes.BOOL
SetupDiGetHwProfileListExA.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.LPCSTR,  # MachineName : LPCSTR 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')
SetupDiGetHwProfileListExA = Fiddle::Function.new(
  lib['SetupDiGetHwProfileListExA'],
  [
    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 : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # Reserved : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupDiGetHwProfileListExA(
        HwProfileList: *mut u32,  // DWORD* out
        HwProfileListSize: u32,  // DWORD
        RequiredSize: *mut u32,  // DWORD* out
        CurrentlyActiveIndex: *mut u32,  // DWORD* optional, out
        MachineName: *const u8,  // LPCSTR 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.Ansi, SetLastError = true)]
public static extern bool SetupDiGetHwProfileListExA(out uint HwProfileList, uint HwProfileListSize, out uint RequiredSize, IntPtr CurrentlyActiveIndex, [MarshalAs(UnmanagedType.LPStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetHwProfileListExA' -Namespace Win32 -PassThru
# $api::SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiGetHwProfileListExA "SetupDiGetHwProfileListExA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupDiGetHwProfileListExA varptr(HwProfileList), HwProfileListSize, varptr(RequiredSize), varptr(CurrentlyActiveIndex), MachineName, Reserved   ; 戻り値は stat
; HwProfileList : DWORD* out -> "sptr"
; HwProfileListSize : DWORD -> "sptr"
; RequiredSize : DWORD* out -> "sptr"
; CurrentlyActiveIndex : DWORD* optional, out -> "sptr"
; MachineName : LPCSTR optional -> "sptr"
; Reserved : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileListExA "SetupDiGetHwProfileListExA" var, int, var, var, str, sptr
; res = SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
; HwProfileList : DWORD* out -> "var"
; HwProfileListSize : DWORD -> "int"
; RequiredSize : DWORD* out -> "var"
; CurrentlyActiveIndex : DWORD* optional, out -> "var"
; MachineName : LPCSTR optional -> "str"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetHwProfileListExA(DWORD* HwProfileList, DWORD HwProfileListSize, DWORD* RequiredSize, DWORD* CurrentlyActiveIndex, LPCSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileListExA "SetupDiGetHwProfileListExA" var, int, var, var, str, intptr
; res = SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
; HwProfileList : DWORD* out -> "var"
; HwProfileListSize : DWORD -> "int"
; RequiredSize : DWORD* out -> "var"
; CurrentlyActiveIndex : DWORD* optional, out -> "var"
; MachineName : LPCSTR optional -> "str"
; Reserved : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupDiGetHwProfileListExA = setupapi.NewProc("SetupDiGetHwProfileListExA")
)

// HwProfileList (DWORD* out), HwProfileListSize (DWORD), RequiredSize (DWORD* out), CurrentlyActiveIndex (DWORD* optional, out), MachineName (LPCSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiGetHwProfileListExA.Call(
	uintptr(HwProfileList),
	uintptr(HwProfileListSize),
	uintptr(RequiredSize),
	uintptr(CurrentlyActiveIndex),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(MachineName))),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetHwProfileListExA(
  HwProfileList: Pointer;   // DWORD* out
  HwProfileListSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* out
  CurrentlyActiveIndex: Pointer;   // DWORD* optional, out
  MachineName: PAnsiChar;   // LPCSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetHwProfileListExA';
result := DllCall("SETUPAPI\SetupDiGetHwProfileListExA"
    , "Ptr", HwProfileList   ; DWORD* out
    , "UInt", HwProfileListSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* out
    , "Ptr", CurrentlyActiveIndex   ; DWORD* optional, out
    , "AStr", MachineName   ; LPCSTR optional
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiGetHwProfileListExA(void*, dword, void*, void*, char*, void*)")
# 呼び出し: SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
# HwProfileList : DWORD* out -> "void*"
# HwProfileListSize : DWORD -> "dword"
# RequiredSize : DWORD* out -> "void*"
# CurrentlyActiveIndex : DWORD* optional, out -> "void*"
# MachineName : LPCSTR optional -> "char*"
# Reserved : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。