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

SetupSetDirectoryIdA

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

シグネチャ

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

BOOL SetupSetDirectoryIdA(
    void* InfHandle,
    DWORD Id,
    LPCSTR Directory   // optional
);

パラメーター

名前方向説明
InfHandlevoid*in対象の開いているINFハンドル。
IdDWORDin設定するディレクトリ識別子(DIRID)。0で全てのカスタムIDをクリアする。
DirectoryLPCSTRinoptionalそのIDに割り当てるディレクトリパス(ANSI)。NULLで該当IDを削除する。

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupSetDirectoryIdA = setupapi.NewProc("SetupSetDirectoryIdA")
)

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

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

typedef SetupSetDirectoryIdANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>);
typedef SetupSetDirectoryIdADart = int Function(Pointer<Void>, int, Pointer<Utf8>);
final SetupSetDirectoryIdA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupSetDirectoryIdANative, SetupSetDirectoryIdADart>('SetupSetDirectoryIdA');
// InfHandle : void* -> Pointer<Void>
// Id : DWORD -> Uint32
// Directory : LPCSTR optional -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupSetDirectoryIdA(
  InfHandle: Pointer;   // void*
  Id: DWORD;   // DWORD
  Directory: PAnsiChar   // LPCSTR optional
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupSetDirectoryIdA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupSetDirectoryIdA"
  c_SetupSetDirectoryIdA :: Ptr () -> Word32 -> CString -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Id : DWORD -> Word32
-- Directory : LPCSTR optional -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupsetdirectoryida =
  foreign "SetupSetDirectoryIdA"
    ((ptr void) @-> uint32_t @-> string @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Id : DWORD -> uint32_t *)
(* Directory : LPCSTR optional -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupSetDirectoryIdA" setup-set-directory-id-a :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (id :uint32)   ; DWORD
  (directory :string))   ; LPCSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupSetDirectoryIdA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupSetDirectoryIdA(LPVOID InfHandle, DWORD Id, LPCSTR Directory)');
# my $ret = $SetupSetDirectoryIdA->Call($InfHandle, $Id, $Directory);
# InfHandle : void* -> LPVOID
# Id : DWORD -> DWORD
# Directory : LPCSTR optional -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
類似 API