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

SetupDiGetHwProfileFriendlyNameExW

関数
指定マシンのハードウェアプロファイル名を取得する。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL SetupDiGetHwProfileFriendlyNameExW(
    DWORD HwProfile,
    LPWSTR FriendlyName,
    DWORD FriendlyNameSize,
    DWORD* RequiredSize,   // optional
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);

パラメーター

名前方向
HwProfileDWORDin
FriendlyNameLPWSTRout
FriendlyNameSizeDWORDin
RequiredSizeDWORD*outoptional
MachineNameLPCWSTRinoptional
Reservedvoid*optional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupDiGetHwProfileFriendlyNameExW(
    DWORD HwProfile,
    LPWSTR FriendlyName,
    DWORD FriendlyNameSize,
    DWORD* RequiredSize,   // optional
    LPCWSTR MachineName,   // optional
    void* Reserved   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiGetHwProfileFriendlyNameExW(
    uint HwProfile,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FriendlyName,   // LPWSTR out
    uint FriendlyNameSize,   // DWORD
    IntPtr RequiredSize,   // 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 SetupDiGetHwProfileFriendlyNameExW(
    HwProfile As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> FriendlyName As System.Text.StringBuilder,   ' LPWSTR out
    FriendlyNameSize As UInteger,   ' DWORD
    RequiredSize As IntPtr,   ' DWORD* optional, out
    <MarshalAs(UnmanagedType.LPWStr)> MachineName As String,   ' LPCWSTR optional
    Reserved As IntPtr   ' void* optional
) As Boolean
End Function
' HwProfile : DWORD
' FriendlyName : LPWSTR out
' FriendlyNameSize : DWORD
' RequiredSize : DWORD* optional, out
' MachineName : LPCWSTR optional
' Reserved : void* optional
Declare PtrSafe Function SetupDiGetHwProfileFriendlyNameExW Lib "setupapi" ( _
    ByVal HwProfile As Long, _
    ByVal FriendlyName As LongPtr, _
    ByVal FriendlyNameSize As Long, _
    ByVal RequiredSize 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

SetupDiGetHwProfileFriendlyNameExW = ctypes.windll.setupapi.SetupDiGetHwProfileFriendlyNameExW
SetupDiGetHwProfileFriendlyNameExW.restype = wintypes.BOOL
SetupDiGetHwProfileFriendlyNameExW.argtypes = [
    wintypes.DWORD,  # HwProfile : DWORD
    wintypes.LPWSTR,  # FriendlyName : LPWSTR out
    wintypes.DWORD,  # FriendlyNameSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # RequiredSize : 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')
SetupDiGetHwProfileFriendlyNameExW = Fiddle::Function.new(
  lib['SetupDiGetHwProfileFriendlyNameExW'],
  [
    -Fiddle::TYPE_INT,  # HwProfile : DWORD
    Fiddle::TYPE_VOIDP,  # FriendlyName : LPWSTR out
    -Fiddle::TYPE_INT,  # FriendlyNameSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : 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 SetupDiGetHwProfileFriendlyNameExW(
        HwProfile: u32,  // DWORD
        FriendlyName: *mut u16,  // LPWSTR out
        FriendlyNameSize: u32,  // DWORD
        RequiredSize: *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 SetupDiGetHwProfileFriendlyNameExW(uint HwProfile, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder FriendlyName, uint FriendlyNameSize, IntPtr RequiredSize, [MarshalAs(UnmanagedType.LPWStr)] string MachineName, IntPtr Reserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiGetHwProfileFriendlyNameExW' -Namespace Win32 -PassThru
# $api::SetupDiGetHwProfileFriendlyNameExW(HwProfile, FriendlyName, FriendlyNameSize, RequiredSize, MachineName, Reserved)
#uselib "SETUPAPI.dll"
#func global SetupDiGetHwProfileFriendlyNameExW "SetupDiGetHwProfileFriendlyNameExW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupDiGetHwProfileFriendlyNameExW HwProfile, varptr(FriendlyName), FriendlyNameSize, varptr(RequiredSize), MachineName, Reserved   ; 戻り値は stat
; HwProfile : DWORD -> "wptr"
; FriendlyName : LPWSTR out -> "wptr"
; FriendlyNameSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; MachineName : LPCWSTR optional -> "wptr"
; Reserved : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileFriendlyNameExW "SetupDiGetHwProfileFriendlyNameExW" int, var, int, var, wstr, sptr
; res = SetupDiGetHwProfileFriendlyNameExW(HwProfile, FriendlyName, FriendlyNameSize, RequiredSize, MachineName, Reserved)
; HwProfile : DWORD -> "int"
; FriendlyName : LPWSTR out -> "var"
; FriendlyNameSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; MachineName : LPCWSTR optional -> "wstr"
; Reserved : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupDiGetHwProfileFriendlyNameExW(DWORD HwProfile, LPWSTR FriendlyName, DWORD FriendlyNameSize, DWORD* RequiredSize, LPCWSTR MachineName, void* Reserved)
#uselib "SETUPAPI.dll"
#cfunc global SetupDiGetHwProfileFriendlyNameExW "SetupDiGetHwProfileFriendlyNameExW" int, var, int, var, wstr, intptr
; res = SetupDiGetHwProfileFriendlyNameExW(HwProfile, FriendlyName, FriendlyNameSize, RequiredSize, MachineName, Reserved)
; HwProfile : DWORD -> "int"
; FriendlyName : LPWSTR out -> "var"
; FriendlyNameSize : DWORD -> "int"
; RequiredSize : 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")
	procSetupDiGetHwProfileFriendlyNameExW = setupapi.NewProc("SetupDiGetHwProfileFriendlyNameExW")
)

// HwProfile (DWORD), FriendlyName (LPWSTR out), FriendlyNameSize (DWORD), RequiredSize (DWORD* optional, out), MachineName (LPCWSTR optional), Reserved (void* optional)
r1, _, err := procSetupDiGetHwProfileFriendlyNameExW.Call(
	uintptr(HwProfile),
	uintptr(FriendlyName),
	uintptr(FriendlyNameSize),
	uintptr(RequiredSize),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(MachineName))),
	uintptr(Reserved),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupDiGetHwProfileFriendlyNameExW(
  HwProfile: DWORD;   // DWORD
  FriendlyName: PWideChar;   // LPWSTR out
  FriendlyNameSize: DWORD;   // DWORD
  RequiredSize: Pointer;   // DWORD* optional, out
  MachineName: PWideChar;   // LPCWSTR optional
  Reserved: Pointer   // void* optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupDiGetHwProfileFriendlyNameExW';
result := DllCall("SETUPAPI\SetupDiGetHwProfileFriendlyNameExW"
    , "UInt", HwProfile   ; DWORD
    , "Ptr", FriendlyName   ; LPWSTR out
    , "UInt", FriendlyNameSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "WStr", MachineName   ; LPCWSTR optional
    , "Ptr", Reserved   ; void* optional
    , "Int")   ; return: BOOL
●SetupDiGetHwProfileFriendlyNameExW(HwProfile, FriendlyName, FriendlyNameSize, RequiredSize, MachineName, Reserved) = DLL("SETUPAPI.dll", "bool SetupDiGetHwProfileFriendlyNameExW(dword, char*, dword, void*, char*, void*)")
# 呼び出し: SetupDiGetHwProfileFriendlyNameExW(HwProfile, FriendlyName, FriendlyNameSize, RequiredSize, MachineName, Reserved)
# HwProfile : DWORD -> "dword"
# FriendlyName : LPWSTR out -> "char*"
# FriendlyNameSize : DWORD -> "dword"
# RequiredSize : 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 版の利用を推奨。