ホーム › Devices.DeviceAndDriverInstallation › SetupSetDirectoryIdExW
SetupSetDirectoryIdExW
関数INFのディレクトリ識別子にパスをフラグ付きで関連付ける(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupSetDirectoryIdExW(
void* InfHandle,
DWORD Id,
LPCWSTR Directory, // optional
DWORD Flags,
DWORD Reserved1, // optional
void* Reserved2 // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfHandle | void* | in | 対象の開いているINFハンドル。 |
| Id | DWORD | in | 設定するディレクトリ識別子(DIRID)。0で全てのカスタムIDをクリアする。 |
| Directory | LPCWSTR | inoptional | そのIDに割り当てるディレクトリパス(Unicode)。NULLで該当IDを削除する。 |
| Flags | DWORD | in | 動作を制御するフラグ。 |
| Reserved1 | DWORD | optional | 予約済み。0を指定する。 |
| Reserved2 | void* | optional | 予約済み。NULLを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
BOOL SetupSetDirectoryIdExW(
void* InfHandle,
DWORD Id,
LPCWSTR Directory, // optional
DWORD Flags,
DWORD Reserved1, // optional
void* Reserved2 // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupSetDirectoryIdExW(
IntPtr InfHandle, // void*
uint Id, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string Directory, // LPCWSTR optional
uint Flags, // DWORD
uint Reserved1, // DWORD optional
IntPtr Reserved2 // void* optional
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupSetDirectoryIdExW(
InfHandle As IntPtr, ' void*
Id As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> Directory As String, ' LPCWSTR optional
Flags As UInteger, ' DWORD
Reserved1 As UInteger, ' DWORD optional
Reserved2 As IntPtr ' void* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' InfHandle : void*
' Id : DWORD
' Directory : LPCWSTR optional
' Flags : DWORD
' Reserved1 : DWORD optional
' Reserved2 : void* optional
Declare PtrSafe Function SetupSetDirectoryIdExW Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal Id As Long, _
ByVal Directory As LongPtr, _
ByVal Flags As Long, _
ByVal Reserved1 As Long, _
ByVal Reserved2 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
SetupSetDirectoryIdExW = ctypes.windll.setupapi.SetupSetDirectoryIdExW
SetupSetDirectoryIdExW.restype = wintypes.BOOL
SetupSetDirectoryIdExW.argtypes = [
ctypes.POINTER(None), # InfHandle : void*
wintypes.DWORD, # Id : DWORD
wintypes.LPCWSTR, # Directory : LPCWSTR 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')
SetupSetDirectoryIdExW = Fiddle::Function.new(
lib['SetupSetDirectoryIdExW'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void*
-Fiddle::TYPE_INT, # Id : DWORD
Fiddle::TYPE_VOIDP, # Directory : LPCWSTR optional
-Fiddle::TYPE_INT, # Flags : DWORD
-Fiddle::TYPE_INT, # Reserved1 : DWORD optional
Fiddle::TYPE_VOIDP, # Reserved2 : void* optional
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupSetDirectoryIdExW(
InfHandle: *mut (), // void*
Id: u32, // DWORD
Directory: *const u16, // LPCWSTR 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.Unicode, SetLastError = true)]
public static extern bool SetupSetDirectoryIdExW(IntPtr InfHandle, uint Id, [MarshalAs(UnmanagedType.LPWStr)] string Directory, uint Flags, uint Reserved1, IntPtr Reserved2);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupSetDirectoryIdExW' -Namespace Win32 -PassThru
# $api::SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)#uselib "SETUPAPI.dll"
#func global SetupSetDirectoryIdExW "SetupSetDirectoryIdExW" wptr, wptr, wptr, wptr, wptr, wptr
; SetupSetDirectoryIdExW InfHandle, Id, Directory, Flags, Reserved1, Reserved2 ; 戻り値は stat
; InfHandle : void* -> "wptr"
; Id : DWORD -> "wptr"
; Directory : LPCWSTR optional -> "wptr"
; Flags : DWORD -> "wptr"
; Reserved1 : DWORD optional -> "wptr"
; Reserved2 : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SETUPAPI.dll"
#cfunc global SetupSetDirectoryIdExW "SetupSetDirectoryIdExW" sptr, int, wstr, int, int, sptr
; res = SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
; InfHandle : void* -> "sptr"
; Id : DWORD -> "int"
; Directory : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; Reserved1 : DWORD optional -> "int"
; Reserved2 : void* optional -> "sptr"; BOOL SetupSetDirectoryIdExW(void* InfHandle, DWORD Id, LPCWSTR Directory, DWORD Flags, DWORD Reserved1, void* Reserved2)
#uselib "SETUPAPI.dll"
#cfunc global SetupSetDirectoryIdExW "SetupSetDirectoryIdExW" intptr, int, wstr, int, int, intptr
; res = SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
; InfHandle : void* -> "intptr"
; Id : DWORD -> "int"
; Directory : LPCWSTR optional -> "wstr"
; Flags : DWORD -> "int"
; Reserved1 : DWORD optional -> "int"
; Reserved2 : void* optional -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupSetDirectoryIdExW = setupapi.NewProc("SetupSetDirectoryIdExW")
)
// InfHandle (void*), Id (DWORD), Directory (LPCWSTR optional), Flags (DWORD), Reserved1 (DWORD optional), Reserved2 (void* optional)
r1, _, err := procSetupSetDirectoryIdExW.Call(
uintptr(InfHandle),
uintptr(Id),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Directory))),
uintptr(Flags),
uintptr(Reserved1),
uintptr(Reserved2),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupSetDirectoryIdExW(
InfHandle: Pointer; // void*
Id: DWORD; // DWORD
Directory: PWideChar; // LPCWSTR optional
Flags: DWORD; // DWORD
Reserved1: DWORD; // DWORD optional
Reserved2: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupSetDirectoryIdExW';result := DllCall("SETUPAPI\SetupSetDirectoryIdExW"
, "Ptr", InfHandle ; void*
, "UInt", Id ; DWORD
, "WStr", Directory ; LPCWSTR optional
, "UInt", Flags ; DWORD
, "UInt", Reserved1 ; DWORD optional
, "Ptr", Reserved2 ; void* optional
, "Int") ; return: BOOL●SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2) = DLL("SETUPAPI.dll", "bool SetupSetDirectoryIdExW(void*, dword, char*, dword, dword, void*)")
# 呼び出し: SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
# InfHandle : void* -> "void*"
# Id : DWORD -> "dword"
# Directory : LPCWSTR optional -> "char*"
# Flags : DWORD -> "dword"
# Reserved1 : DWORD optional -> "dword"
# Reserved2 : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupSetDirectoryIdExW(
InfHandle: ?*anyopaque, // void*
Id: u32, // DWORD
Directory: [*c]const u16, // LPCWSTR optional
Flags: u32, // DWORD
Reserved1: u32, // DWORD optional
Reserved2: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupSetDirectoryIdExW(
InfHandle: pointer, # void*
Id: uint32, # DWORD
Directory: WideCString, # LPCWSTR optional
Flags: uint32, # DWORD
Reserved1: uint32, # DWORD optional
Reserved2: pointer # void* optional
): int32 {.importc: "SetupSetDirectoryIdExW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
int SetupSetDirectoryIdExW(
void* InfHandle, // void*
uint Id, // DWORD
const(wchar)* Directory, // LPCWSTR optional
uint Flags, // DWORD
uint Reserved1, // DWORD optional
void* Reserved2 // void* optional
);ccall((:SetupSetDirectoryIdExW, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Cwstring, UInt32, UInt32, Ptr{Cvoid}),
InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
# InfHandle : void* -> Ptr{Cvoid}
# Id : DWORD -> UInt32
# Directory : LPCWSTR optional -> Cwstring
# Flags : DWORD -> UInt32
# Reserved1 : DWORD optional -> UInt32
# Reserved2 : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupSetDirectoryIdExW(
void* InfHandle,
uint32_t Id,
const uint16_t* Directory,
uint32_t Flags,
uint32_t Reserved1,
void* Reserved2);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
-- InfHandle : void*
-- Id : DWORD
-- Directory : LPCWSTR optional
-- Flags : DWORD
-- Reserved1 : DWORD optional
-- Reserved2 : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupSetDirectoryIdExW = lib.func('__stdcall', 'SetupSetDirectoryIdExW', 'int32_t', ['void *', 'uint32_t', 'str16', 'uint32_t', 'uint32_t', 'void *']);
// SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
// InfHandle : void* -> 'void *'
// Id : DWORD -> 'uint32_t'
// Directory : LPCWSTR optional -> 'str16'
// Flags : DWORD -> 'uint32_t'
// Reserved1 : DWORD optional -> 'uint32_t'
// Reserved2 : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupSetDirectoryIdExW: { parameters: ["pointer", "u32", "buffer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
// InfHandle : void* -> "pointer"
// Id : DWORD -> "u32"
// Directory : LPCWSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// Reserved1 : DWORD optional -> "u32"
// Reserved2 : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupSetDirectoryIdExW(
void* InfHandle,
uint32_t Id,
const uint16_t* Directory,
uint32_t Flags,
uint32_t Reserved1,
void* Reserved2);
C, "SETUPAPI.dll");
// $ffi->SetupSetDirectoryIdExW(InfHandle, Id, Directory, Flags, Reserved1, Reserved2);
// InfHandle : void*
// Id : DWORD
// Directory : LPCWSTR optional
// Flags : DWORD
// Reserved1 : DWORD optional
// Reserved2 : 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.UNICODE_OPTIONS);
boolean SetupSetDirectoryIdExW(
Pointer InfHandle, // void*
int Id, // DWORD
WString Directory, // LPCWSTR optional
int Flags, // DWORD
int Reserved1, // DWORD optional
Pointer Reserved2 // void* optional
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupSetDirectoryIdExW = SetupSetDirectoryIdExW(
InfHandle : Void*, # void*
Id : UInt32, # DWORD
Directory : UInt16*, # LPCWSTR optional
Flags : UInt32, # DWORD
Reserved1 : UInt32, # DWORD optional
Reserved2 : 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 SetupSetDirectoryIdExWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf16>, Uint32, Uint32, Pointer<Void>);
typedef SetupSetDirectoryIdExWDart = int Function(Pointer<Void>, int, Pointer<Utf16>, int, int, Pointer<Void>);
final SetupSetDirectoryIdExW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupSetDirectoryIdExWNative, SetupSetDirectoryIdExWDart>('SetupSetDirectoryIdExW');
// InfHandle : void* -> Pointer<Void>
// Id : DWORD -> Uint32
// Directory : LPCWSTR optional -> Pointer<Utf16>
// Flags : DWORD -> Uint32
// Reserved1 : DWORD optional -> Uint32
// Reserved2 : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupSetDirectoryIdExW(
InfHandle: Pointer; // void*
Id: DWORD; // DWORD
Directory: PWideChar; // LPCWSTR optional
Flags: DWORD; // DWORD
Reserved1: DWORD; // DWORD optional
Reserved2: Pointer // void* optional
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupSetDirectoryIdExW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupSetDirectoryIdExW"
c_SetupSetDirectoryIdExW :: Ptr () -> Word32 -> CWString -> Word32 -> Word32 -> Ptr () -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Id : DWORD -> Word32
-- Directory : LPCWSTR optional -> CWString
-- Flags : DWORD -> Word32
-- Reserved1 : DWORD optional -> Word32
-- Reserved2 : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupsetdirectoryidexw =
foreign "SetupSetDirectoryIdExW"
((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Id : DWORD -> uint32_t *)
(* Directory : LPCWSTR optional -> (ptr uint16_t) *)
(* Flags : DWORD -> uint32_t *)
(* Reserved1 : DWORD optional -> uint32_t *)
(* Reserved2 : 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 ("SetupSetDirectoryIdExW" setup-set-directory-id-ex-w :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(id :uint32) ; DWORD
(directory (:string :encoding :utf-16le)) ; LPCWSTR optional
(flags :uint32) ; DWORD
(reserved1 :uint32) ; DWORD optional
(reserved2 :pointer)) ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupSetDirectoryIdExW = Win32::API::More->new('SETUPAPI',
'BOOL SetupSetDirectoryIdExW(LPVOID InfHandle, DWORD Id, LPCWSTR Directory, DWORD Flags, DWORD Reserved1, LPVOID Reserved2)');
# my $ret = $SetupSetDirectoryIdExW->Call($InfHandle, $Id, $Directory, $Flags, $Reserved1, $Reserved2);
# InfHandle : void* -> LPVOID
# Id : DWORD -> DWORD
# Directory : LPCWSTR optional -> LPCWSTR
# Flags : DWORD -> DWORD
# Reserved1 : DWORD optional -> DWORD
# Reserved2 : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupSetDirectoryIdExA (ANSI版) — INFのディレクトリ識別子にパスをフラグ付きで関連付ける(ANSI)。
類似 API
- f SetupSetDirectoryIdW — INFのディレクトリ識別子に実際のパスを関連付ける(Unicode)。