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

SetupSetDirectoryIdExA

関数
INFのディレクトリ識別子にパスをフラグ付きで関連付ける(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupSetDirectoryIdExA(
    void* InfHandle,
    DWORD Id,
    LPCSTR Directory,   // optional
    DWORD Flags,
    DWORD Reserved1,   // optional
    void* Reserved2   // optional
);

パラメーター

名前方向
InfHandlevoid*in
IdDWORDin
DirectoryLPCSTRinoptional
FlagsDWORDin
Reserved1DWORDoptional
Reserved2void*optional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupSetDirectoryIdExA(
    void* InfHandle,
    DWORD Id,
    LPCSTR Directory,   // optional
    DWORD Flags,
    DWORD Reserved1,   // optional
    void* Reserved2   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupSetDirectoryIdExA(
    IntPtr InfHandle,   // void*
    uint Id,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string Directory,   // LPCSTR optional
    uint Flags,   // DWORD
    uint Reserved1,   // DWORD optional
    IntPtr Reserved2   // void* optional
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupSetDirectoryIdExA(
    InfHandle As IntPtr,   ' void*
    Id As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> Directory As String,   ' LPCSTR optional
    Flags As UInteger,   ' DWORD
    Reserved1 As UInteger,   ' DWORD optional
    Reserved2 As IntPtr   ' void* optional
) As Boolean
End Function
' InfHandle : void*
' Id : DWORD
' Directory : LPCSTR optional
' Flags : DWORD
' Reserved1 : DWORD optional
' Reserved2 : void* optional
Declare PtrSafe Function SetupSetDirectoryIdExA Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal Id As Long, _
    ByVal Directory As String, _
    ByVal Flags As Long, _
    ByVal Reserved1 As Long, _
    ByVal Reserved2 As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupSetDirectoryIdExA = ctypes.windll.setupapi.SetupSetDirectoryIdExA
SetupSetDirectoryIdExA.restype = wintypes.BOOL
SetupSetDirectoryIdExA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.DWORD,  # Id : DWORD
    wintypes.LPCSTR,  # Directory : LPCSTR optional
    wintypes.DWORD,  # Flags : DWORD
    wintypes.DWORD,  # Reserved1 : DWORD optional
    ctypes.POINTER(None),  # Reserved2 : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupSetDirectoryIdExA = Fiddle::Function.new(
  lib['SetupSetDirectoryIdExA'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    -Fiddle::TYPE_INT,  # Id : DWORD
    Fiddle::TYPE_VOIDP,  # Directory : LPCSTR optional
    -Fiddle::TYPE_INT,  # Flags : DWORD
    -Fiddle::TYPE_INT,  # Reserved1 : DWORD optional
    Fiddle::TYPE_VOIDP,  # Reserved2 : void* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupSetDirectoryIdExA(
        InfHandle: *mut (),  // void*
        Id: u32,  // DWORD
        Directory: *const u8,  // LPCSTR optional
        Flags: u32,  // DWORD
        Reserved1: u32,  // DWORD optional
        Reserved2: *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 SetupSetDirectoryIdExA(IntPtr InfHandle, uint Id, [MarshalAs(UnmanagedType.LPStr)] string Directory, uint Flags, uint Reserved1, IntPtr Reserved2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupSetDirectoryIdExA' -Namespace Win32 -PassThru
# $api::SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
#uselib "SETUPAPI.dll"
#func global SetupSetDirectoryIdExA "SetupSetDirectoryIdExA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupSetDirectoryIdExA InfHandle, Id, Directory, Flags, Reserved1, Reserved2   ; 戻り値は stat
; InfHandle : void* -> "sptr"
; Id : DWORD -> "sptr"
; Directory : LPCSTR optional -> "sptr"
; Flags : DWORD -> "sptr"
; Reserved1 : DWORD optional -> "sptr"
; Reserved2 : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SETUPAPI.dll"
#cfunc global SetupSetDirectoryIdExA "SetupSetDirectoryIdExA" sptr, int, str, int, int, sptr
; res = SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
; InfHandle : void* -> "sptr"
; Id : DWORD -> "int"
; Directory : LPCSTR optional -> "str"
; Flags : DWORD -> "int"
; Reserved1 : DWORD optional -> "int"
; Reserved2 : void* optional -> "sptr"
; BOOL SetupSetDirectoryIdExA(void* InfHandle, DWORD Id, LPCSTR Directory, DWORD Flags, DWORD Reserved1, void* Reserved2)
#uselib "SETUPAPI.dll"
#cfunc global SetupSetDirectoryIdExA "SetupSetDirectoryIdExA" intptr, int, str, int, int, intptr
; res = SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
; InfHandle : void* -> "intptr"
; Id : DWORD -> "int"
; Directory : LPCSTR optional -> "str"
; Flags : DWORD -> "int"
; Reserved1 : DWORD optional -> "int"
; Reserved2 : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupSetDirectoryIdExA = setupapi.NewProc("SetupSetDirectoryIdExA")
)

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