ホーム › Devices.DeviceAndDriverInstallation › SetupSetDirectoryIdExA
SetupSetDirectoryIdExA
関数INFのディレクトリ識別子にパスをフラグ付きで関連付ける(ANSI)。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupSetDirectoryIdExA(
void* InfHandle,
DWORD Id,
LPCSTR Directory, // optional
DWORD Flags,
DWORD Reserved1, // optional
void* Reserved2 // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfHandle | void* | in | 対象の開いているINFハンドル。 |
| Id | DWORD | in | 設定するディレクトリ識別子(DIRID)。0で全てのカスタムIDをクリアする。 |
| Directory | LPCSTR | inoptional | そのIDに割り当てるディレクトリパス(ANSI)。NULLで該当IDを削除する。 |
| Flags | DWORD | in | 動作を制御するフラグ。 |
| Reserved1 | DWORD | optional | 予約済み。0を指定する。 |
| Reserved2 | void* | optional | 予約済み。NULLを指定する。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "setupapi" fn SetupSetDirectoryIdExA(
InfHandle: ?*anyopaque, // void*
Id: u32, // DWORD
Directory: [*c]const u8, // LPCSTR optional
Flags: u32, // DWORD
Reserved1: u32, // DWORD optional
Reserved2: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;proc SetupSetDirectoryIdExA(
InfHandle: pointer, # void*
Id: uint32, # DWORD
Directory: cstring, # LPCSTR optional
Flags: uint32, # DWORD
Reserved1: uint32, # DWORD optional
Reserved2: pointer # void* optional
): int32 {.importc: "SetupSetDirectoryIdExA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupSetDirectoryIdExA(
void* InfHandle, // void*
uint Id, // DWORD
const(char)* Directory, // LPCSTR optional
uint Flags, // DWORD
uint Reserved1, // DWORD optional
void* Reserved2 // void* optional
);ccall((:SetupSetDirectoryIdExA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, Cstring, UInt32, UInt32, Ptr{Cvoid}),
InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
# InfHandle : void* -> Ptr{Cvoid}
# Id : DWORD -> UInt32
# Directory : LPCSTR optional -> Cstring
# Flags : DWORD -> UInt32
# Reserved1 : DWORD optional -> UInt32
# Reserved2 : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupSetDirectoryIdExA(
void* InfHandle,
uint32_t Id,
const char* Directory,
uint32_t Flags,
uint32_t Reserved1,
void* Reserved2);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
-- InfHandle : void*
-- Id : DWORD
-- Directory : LPCSTR optional
-- Flags : DWORD
-- Reserved1 : DWORD optional
-- Reserved2 : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupSetDirectoryIdExA = lib.func('__stdcall', 'SetupSetDirectoryIdExA', 'int32_t', ['void *', 'uint32_t', 'str', 'uint32_t', 'uint32_t', 'void *']);
// SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
// InfHandle : void* -> 'void *'
// Id : DWORD -> 'uint32_t'
// Directory : LPCSTR optional -> 'str'
// Flags : DWORD -> 'uint32_t'
// Reserved1 : DWORD optional -> 'uint32_t'
// Reserved2 : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupSetDirectoryIdExA: { parameters: ["pointer", "u32", "buffer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2)
// InfHandle : void* -> "pointer"
// Id : DWORD -> "u32"
// Directory : LPCSTR optional -> "buffer"
// Flags : DWORD -> "u32"
// Reserved1 : DWORD optional -> "u32"
// Reserved2 : void* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupSetDirectoryIdExA(
void* InfHandle,
uint32_t Id,
const char* Directory,
uint32_t Flags,
uint32_t Reserved1,
void* Reserved2);
C, "SETUPAPI.dll");
// $ffi->SetupSetDirectoryIdExA(InfHandle, Id, Directory, Flags, Reserved1, Reserved2);
// InfHandle : void*
// Id : DWORD
// Directory : LPCSTR 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.ASCII_OPTIONS);
boolean SetupSetDirectoryIdExA(
Pointer InfHandle, // void*
int Id, // DWORD
String Directory, // LPCSTR optional
int Flags, // DWORD
int Reserved1, // DWORD optional
Pointer Reserved2 // void* optional
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupSetDirectoryIdExA = SetupSetDirectoryIdExA(
InfHandle : Void*, # void*
Id : UInt32, # DWORD
Directory : UInt8*, # LPCSTR 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 SetupSetDirectoryIdExANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Uint32, Uint32, Pointer<Void>);
typedef SetupSetDirectoryIdExADart = int Function(Pointer<Void>, int, Pointer<Utf8>, int, int, Pointer<Void>);
final SetupSetDirectoryIdExA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupSetDirectoryIdExANative, SetupSetDirectoryIdExADart>('SetupSetDirectoryIdExA');
// InfHandle : void* -> Pointer<Void>
// Id : DWORD -> Uint32
// Directory : LPCSTR optional -> Pointer<Utf8>
// Flags : DWORD -> Uint32
// Reserved1 : DWORD optional -> Uint32
// Reserved2 : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupSetDirectoryIdExA"
c_SetupSetDirectoryIdExA :: Ptr () -> Word32 -> CString -> Word32 -> Word32 -> Ptr () -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Id : DWORD -> Word32
-- Directory : LPCSTR optional -> CString
-- Flags : DWORD -> Word32
-- Reserved1 : DWORD optional -> Word32
-- Reserved2 : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupsetdirectoryidexa =
foreign "SetupSetDirectoryIdExA"
((ptr void) @-> uint32_t @-> string @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Id : DWORD -> uint32_t *)
(* Directory : LPCSTR optional -> string *)
(* 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 ("SetupSetDirectoryIdExA" setup-set-directory-id-ex-a :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(id :uint32) ; DWORD
(directory :string) ; LPCSTR 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 $SetupSetDirectoryIdExA = Win32::API::More->new('SETUPAPI',
'BOOL SetupSetDirectoryIdExA(LPVOID InfHandle, DWORD Id, LPCSTR Directory, DWORD Flags, DWORD Reserved1, LPVOID Reserved2)');
# my $ret = $SetupSetDirectoryIdExA->Call($InfHandle, $Id, $Directory, $Flags, $Reserved1, $Reserved2);
# InfHandle : void* -> LPVOID
# Id : DWORD -> DWORD
# Directory : LPCSTR optional -> LPCSTR
# Flags : DWORD -> DWORD
# Reserved1 : DWORD optional -> DWORD
# Reserved2 : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupSetDirectoryIdExW (Unicode版) — INFのディレクトリ識別子にパスをフラグ付きで関連付ける(Unicode)。
類似 API
- f SetupSetDirectoryIdA — INFのディレクトリ識別子に実際のパスを関連付ける(ANSI)。