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ハードウェアプロファイルID配列を受け取るバッファ。
HwProfileListSizeDWORDinHwProfileList配列が保持できる要素数。
RequiredSizeDWORD*out実際に必要な要素数を受け取るポインタ。サイズ照会に使う。
CurrentlyActiveIndexDWORD*outoptional現在アクティブなプロファイルの配列内インデックスを受け取るポインタ。
MachineNameLPCSTRinoptional対象リモートコンピュータ名(ANSI)。NULL指定でローカルマシンを対象とする。
Reservedvoid*optional予約済み。NULLを指定する。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "setupapi" fn SetupDiGetHwProfileListExA(
    HwProfileList: [*c]u32, // DWORD* out
    HwProfileListSize: u32, // DWORD
    RequiredSize: [*c]u32, // DWORD* out
    CurrentlyActiveIndex: [*c]u32, // DWORD* optional, out
    MachineName: [*c]const u8, // LPCSTR optional
    Reserved: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
proc SetupDiGetHwProfileListExA(
    HwProfileList: ptr uint32,  # DWORD* out
    HwProfileListSize: uint32,  # DWORD
    RequiredSize: ptr uint32,  # DWORD* out
    CurrentlyActiveIndex: ptr uint32,  # DWORD* optional, out
    MachineName: cstring,  # LPCSTR optional
    Reserved: pointer  # void* optional
): int32 {.importc: "SetupDiGetHwProfileListExA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupDiGetHwProfileListExA(
    uint* HwProfileList,   // DWORD* out
    uint HwProfileListSize,   // DWORD
    uint* RequiredSize,   // DWORD* out
    uint* CurrentlyActiveIndex,   // DWORD* optional, out
    const(char)* MachineName,   // LPCSTR optional
    void* Reserved   // void* optional
);
ccall((:SetupDiGetHwProfileListExA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{UInt32}, UInt32, Ptr{UInt32}, Ptr{UInt32}, Cstring, Ptr{Cvoid}),
      HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
# HwProfileList : DWORD* out -> Ptr{UInt32}
# HwProfileListSize : DWORD -> UInt32
# RequiredSize : DWORD* out -> Ptr{UInt32}
# CurrentlyActiveIndex : DWORD* optional, out -> Ptr{UInt32}
# MachineName : LPCSTR optional -> Cstring
# Reserved : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiGetHwProfileListExA(
    uint32_t* HwProfileList,
    uint32_t HwProfileListSize,
    uint32_t* RequiredSize,
    uint32_t* CurrentlyActiveIndex,
    const char* MachineName,
    void* Reserved);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
-- HwProfileList : DWORD* out
-- HwProfileListSize : DWORD
-- RequiredSize : DWORD* out
-- CurrentlyActiveIndex : DWORD* optional, out
-- MachineName : LPCSTR optional
-- Reserved : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiGetHwProfileListExA = lib.func('__stdcall', 'SetupDiGetHwProfileListExA', 'int32_t', ['uint32_t *', 'uint32_t', 'uint32_t *', 'uint32_t *', 'str', 'void *']);
// SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
// HwProfileList : DWORD* out -> 'uint32_t *'
// HwProfileListSize : DWORD -> 'uint32_t'
// RequiredSize : DWORD* out -> 'uint32_t *'
// CurrentlyActiveIndex : DWORD* optional, out -> 'uint32_t *'
// MachineName : LPCSTR optional -> 'str'
// Reserved : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupDiGetHwProfileListExA: { parameters: ["pointer", "u32", "pointer", "pointer", "buffer", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved)
// HwProfileList : DWORD* out -> "pointer"
// HwProfileListSize : DWORD -> "u32"
// RequiredSize : DWORD* out -> "pointer"
// CurrentlyActiveIndex : DWORD* optional, out -> "pointer"
// MachineName : LPCSTR optional -> "buffer"
// Reserved : void* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiGetHwProfileListExA(
    uint32_t* HwProfileList,
    uint32_t HwProfileListSize,
    uint32_t* RequiredSize,
    uint32_t* CurrentlyActiveIndex,
    const char* MachineName,
    void* Reserved);
C, "SETUPAPI.dll");
// $ffi->SetupDiGetHwProfileListExA(HwProfileList, HwProfileListSize, RequiredSize, CurrentlyActiveIndex, MachineName, Reserved);
// HwProfileList : DWORD* out
// HwProfileListSize : DWORD
// RequiredSize : DWORD* out
// CurrentlyActiveIndex : DWORD* optional, out
// MachineName : LPCSTR optional
// Reserved : void* optional
// 構造体/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 SetupDiGetHwProfileListExA(
        IntByReference HwProfileList,   // DWORD* out
        int HwProfileListSize,   // DWORD
        IntByReference RequiredSize,   // DWORD* out
        IntByReference CurrentlyActiveIndex,   // DWORD* optional, out
        String MachineName,   // LPCSTR optional
        Pointer Reserved   // void* optional
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupDiGetHwProfileListExA = SetupDiGetHwProfileListExA(
    HwProfileList : UInt32*,   # DWORD* out
    HwProfileListSize : UInt32,   # DWORD
    RequiredSize : UInt32*,   # DWORD* out
    CurrentlyActiveIndex : UInt32*,   # DWORD* optional, out
    MachineName : UInt8*,   # LPCSTR optional
    Reserved : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupDiGetHwProfileListExANative = Int32 Function(Pointer<Uint32>, Uint32, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf8>, Pointer<Void>);
typedef SetupDiGetHwProfileListExADart = int Function(Pointer<Uint32>, int, Pointer<Uint32>, Pointer<Uint32>, Pointer<Utf8>, Pointer<Void>);
final SetupDiGetHwProfileListExA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupDiGetHwProfileListExANative, SetupDiGetHwProfileListExADart>('SetupDiGetHwProfileListExA');
// HwProfileList : DWORD* out -> Pointer<Uint32>
// HwProfileListSize : DWORD -> Uint32
// RequiredSize : DWORD* out -> Pointer<Uint32>
// CurrentlyActiveIndex : DWORD* optional, out -> Pointer<Uint32>
// MachineName : LPCSTR optional -> Pointer<Utf8>
// Reserved : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupDiGetHwProfileListExA"
  c_SetupDiGetHwProfileListExA :: Ptr Word32 -> Word32 -> Ptr Word32 -> Ptr Word32 -> CString -> Ptr () -> IO CInt
-- HwProfileList : DWORD* out -> Ptr Word32
-- HwProfileListSize : DWORD -> Word32
-- RequiredSize : DWORD* out -> Ptr Word32
-- CurrentlyActiveIndex : DWORD* optional, out -> Ptr Word32
-- MachineName : LPCSTR optional -> CString
-- Reserved : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupdigethwprofilelistexa =
  foreign "SetupDiGetHwProfileListExA"
    ((ptr uint32_t) @-> uint32_t @-> (ptr uint32_t) @-> (ptr uint32_t) @-> string @-> (ptr void) @-> returning int32_t)
(* HwProfileList : DWORD* out -> (ptr uint32_t) *)
(* HwProfileListSize : DWORD -> uint32_t *)
(* RequiredSize : DWORD* out -> (ptr uint32_t) *)
(* CurrentlyActiveIndex : DWORD* optional, out -> (ptr uint32_t) *)
(* MachineName : LPCSTR optional -> string *)
(* Reserved : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupDiGetHwProfileListExA" setup-di-get-hw-profile-list-ex-a :convention :stdcall) :int32
  (hw-profile-list :pointer)   ; DWORD* out
  (hw-profile-list-size :uint32)   ; DWORD
  (required-size :pointer)   ; DWORD* out
  (currently-active-index :pointer)   ; DWORD* optional, out
  (machine-name :string)   ; LPCSTR optional
  (reserved :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupDiGetHwProfileListExA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupDiGetHwProfileListExA(LPVOID HwProfileList, DWORD HwProfileListSize, LPVOID RequiredSize, LPVOID CurrentlyActiveIndex, LPCSTR MachineName, LPVOID Reserved)');
# my $ret = $SetupDiGetHwProfileListExA->Call($HwProfileList, $HwProfileListSize, $RequiredSize, $CurrentlyActiveIndex, $MachineName, $Reserved);
# HwProfileList : DWORD* out -> LPVOID
# HwProfileListSize : DWORD -> DWORD
# RequiredSize : DWORD* out -> LPVOID
# CurrentlyActiveIndex : DWORD* optional, out -> LPVOID
# MachineName : LPCSTR optional -> LPCSTR
# Reserved : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
類似 API