ホーム › Devices.DeviceAndDriverInstallation › SetupDiInstallDeviceInterfaces
SetupDiInstallDeviceInterfaces
関数デバイスのインターフェイスをインストールする。
シグネチャ
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiInstallDeviceInterfaces(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| DeviceInfoSet | HDEVINFO | in | インターフェイスをインストールする対象のデバイスを表すデバイス情報要素を含むデバイス情報セットへのポインター。デバイス情報セットには、ローカル システムの要素のみが含まれている必要があります。 |
| DeviceInfoData | SP_DEVINFO_DATA* | in | DeviceInfoSet 内のデバイス情報要素を指定する SP_DEVINFO_DATA 構造体へのポインター。 |
戻り値の型: BOOL
公式ドキュメント
SetupDiInstallDeviceInterfaces 関数は、DIF_INSTALLINTERFACES インストール要求に対する既定のハンドラーです。
戻り値
SetupDiInstallDeviceInterfaces は、関数がエラーなしで完了した場合に TRUE を返します。関数がエラーで完了した場合は FALSE が返され、失敗の原因を示すエラー コードは GetLastError を呼び出すことで取得できます。
解説(Remarks)
SetupDiInstallDeviceInterfaces は、デバイス INF ファイルの DDInstall.Interfaces セクションにある各 AddInterface エントリを処理し、SetupDiCreateDeviceInterface を呼び出して各インターフェイスを作成します。
SetupDiInstallDeviceInterfaces の呼び出し元は、Administrators グループのメンバーである必要があります。
メモ SetupDiInstallDeviceInterfaces を呼び出してよいのはクラス インストーラーのみであり、しかも SetupDiInstallDeviceInterfaces が既定のデバイス インターフェイス インストール操作を完了した後に、クラス インストーラーがデバイス インターフェイスのインストール操作を実行しなければならない場合に限られます。そのような場合、クラス インストーラーは DIF_INSTALLINTERFACES 要求を処理する際に SetupDiInstallDeviceInterfaces を直接呼び出す必要があります。既定のハンドラーの呼び出しの詳細については、「Calling Default DIF Code Handlers」を参照してください。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SETUPAPI.dll
#include <windows.h>
BOOL SetupDiInstallDeviceInterfaces(
HDEVINFO DeviceInfoSet,
SP_DEVINFO_DATA* DeviceInfoData
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetupDiInstallDeviceInterfaces(
IntPtr DeviceInfoSet, // HDEVINFO
IntPtr DeviceInfoData // SP_DEVINFO_DATA*
);<DllImport("SETUPAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupDiInstallDeviceInterfaces(
DeviceInfoSet As IntPtr, ' HDEVINFO
DeviceInfoData As IntPtr ' SP_DEVINFO_DATA*
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' DeviceInfoSet : HDEVINFO
' DeviceInfoData : SP_DEVINFO_DATA*
Declare PtrSafe Function SetupDiInstallDeviceInterfaces Lib "setupapi" ( _
ByVal DeviceInfoSet As LongPtr, _
ByVal DeviceInfoData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupDiInstallDeviceInterfaces = ctypes.windll.setupapi.SetupDiInstallDeviceInterfaces
SetupDiInstallDeviceInterfaces.restype = wintypes.BOOL
SetupDiInstallDeviceInterfaces.argtypes = [
ctypes.c_ssize_t, # DeviceInfoSet : HDEVINFO
ctypes.c_void_p, # DeviceInfoData : SP_DEVINFO_DATA*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupDiInstallDeviceInterfaces = Fiddle::Function.new(
lib['SetupDiInstallDeviceInterfaces'],
[
Fiddle::TYPE_INTPTR_T, # DeviceInfoSet : HDEVINFO
Fiddle::TYPE_VOIDP, # DeviceInfoData : SP_DEVINFO_DATA*
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupDiInstallDeviceInterfaces(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: *mut SP_DEVINFO_DATA // SP_DEVINFO_DATA*
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", SetLastError = true)]
public static extern bool SetupDiInstallDeviceInterfaces(IntPtr DeviceInfoSet, IntPtr DeviceInfoData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupDiInstallDeviceInterfaces' -Namespace Win32 -PassThru
# $api::SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData)#uselib "SETUPAPI.dll"
#func global SetupDiInstallDeviceInterfaces "SetupDiInstallDeviceInterfaces" sptr, sptr
; SetupDiInstallDeviceInterfaces DeviceInfoSet, varptr(DeviceInfoData) ; 戻り値は stat
; DeviceInfoSet : HDEVINFO -> "sptr"
; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupDiInstallDeviceInterfaces "SetupDiInstallDeviceInterfaces" sptr, var ; res = SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupDiInstallDeviceInterfaces "SetupDiInstallDeviceInterfaces" sptr, sptr ; res = SetupDiInstallDeviceInterfaces(DeviceInfoSet, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "sptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupDiInstallDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiInstallDeviceInterfaces "SetupDiInstallDeviceInterfaces" intptr, var ; res = SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupDiInstallDeviceInterfaces(HDEVINFO DeviceInfoSet, SP_DEVINFO_DATA* DeviceInfoData) #uselib "SETUPAPI.dll" #cfunc global SetupDiInstallDeviceInterfaces "SetupDiInstallDeviceInterfaces" intptr, intptr ; res = SetupDiInstallDeviceInterfaces(DeviceInfoSet, varptr(DeviceInfoData)) ; DeviceInfoSet : HDEVINFO -> "intptr" ; DeviceInfoData : SP_DEVINFO_DATA* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupDiInstallDeviceInterfaces = setupapi.NewProc("SetupDiInstallDeviceInterfaces")
)
// DeviceInfoSet (HDEVINFO), DeviceInfoData (SP_DEVINFO_DATA*)
r1, _, err := procSetupDiInstallDeviceInterfaces.Call(
uintptr(DeviceInfoSet),
uintptr(DeviceInfoData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupDiInstallDeviceInterfaces(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer // SP_DEVINFO_DATA*
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiInstallDeviceInterfaces';result := DllCall("SETUPAPI\SetupDiInstallDeviceInterfaces"
, "Ptr", DeviceInfoSet ; HDEVINFO
, "Ptr", DeviceInfoData ; SP_DEVINFO_DATA*
, "Int") ; return: BOOL●SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData) = DLL("SETUPAPI.dll", "bool SetupDiInstallDeviceInterfaces(int, void*)")
# 呼び出し: SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> "int"
# DeviceInfoData : SP_DEVINFO_DATA* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupDiInstallDeviceInterfaces(
DeviceInfoSet: isize, // HDEVINFO
DeviceInfoData: [*c]SP_DEVINFO_DATA // SP_DEVINFO_DATA*
) callconv(std.os.windows.WINAPI) i32;proc SetupDiInstallDeviceInterfaces(
DeviceInfoSet: int, # HDEVINFO
DeviceInfoData: ptr SP_DEVINFO_DATA # SP_DEVINFO_DATA*
): int32 {.importc: "SetupDiInstallDeviceInterfaces", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupDiInstallDeviceInterfaces(
ptrdiff_t DeviceInfoSet, // HDEVINFO
SP_DEVINFO_DATA* DeviceInfoData // SP_DEVINFO_DATA*
);ccall((:SetupDiInstallDeviceInterfaces, "SETUPAPI.dll"), stdcall, Int32,
(Int, Ptr{SP_DEVINFO_DATA}),
DeviceInfoSet, DeviceInfoData)
# DeviceInfoSet : HDEVINFO -> Int
# DeviceInfoData : SP_DEVINFO_DATA* -> Ptr{SP_DEVINFO_DATA}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupDiInstallDeviceInterfaces(
intptr_t DeviceInfoSet,
void* DeviceInfoData);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData)
-- DeviceInfoSet : HDEVINFO
-- DeviceInfoData : SP_DEVINFO_DATA*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupDiInstallDeviceInterfaces = lib.func('__stdcall', 'SetupDiInstallDeviceInterfaces', 'int32_t', ['intptr_t', 'void *']);
// SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData)
// DeviceInfoSet : HDEVINFO -> 'intptr_t'
// DeviceInfoData : SP_DEVINFO_DATA* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupDiInstallDeviceInterfaces: { parameters: ["isize", "pointer"], result: "i32" },
});
// lib.symbols.SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData)
// DeviceInfoSet : HDEVINFO -> "isize"
// DeviceInfoData : SP_DEVINFO_DATA* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupDiInstallDeviceInterfaces(
intptr_t DeviceInfoSet,
void* DeviceInfoData);
C, "SETUPAPI.dll");
// $ffi->SetupDiInstallDeviceInterfaces(DeviceInfoSet, DeviceInfoData);
// DeviceInfoSet : HDEVINFO
// DeviceInfoData : SP_DEVINFO_DATA*
// 構造体/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);
boolean SetupDiInstallDeviceInterfaces(
long DeviceInfoSet, // HDEVINFO
Pointer DeviceInfoData // SP_DEVINFO_DATA*
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupDiInstallDeviceInterfaces = SetupDiInstallDeviceInterfaces(
DeviceInfoSet : LibC::SSizeT, # HDEVINFO
DeviceInfoData : SP_DEVINFO_DATA* # SP_DEVINFO_DATA*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupDiInstallDeviceInterfacesNative = Int32 Function(IntPtr, Pointer<Void>);
typedef SetupDiInstallDeviceInterfacesDart = int Function(int, Pointer<Void>);
final SetupDiInstallDeviceInterfaces = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupDiInstallDeviceInterfacesNative, SetupDiInstallDeviceInterfacesDart>('SetupDiInstallDeviceInterfaces');
// DeviceInfoSet : HDEVINFO -> IntPtr
// DeviceInfoData : SP_DEVINFO_DATA* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupDiInstallDeviceInterfaces(
DeviceInfoSet: NativeInt; // HDEVINFO
DeviceInfoData: Pointer // SP_DEVINFO_DATA*
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupDiInstallDeviceInterfaces';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupDiInstallDeviceInterfaces"
c_SetupDiInstallDeviceInterfaces :: CIntPtr -> Ptr () -> IO CInt
-- DeviceInfoSet : HDEVINFO -> CIntPtr
-- DeviceInfoData : SP_DEVINFO_DATA* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupdiinstalldeviceinterfaces =
foreign "SetupDiInstallDeviceInterfaces"
(intptr_t @-> (ptr void) @-> returning int32_t)
(* DeviceInfoSet : HDEVINFO -> intptr_t *)
(* DeviceInfoData : SP_DEVINFO_DATA* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupDiInstallDeviceInterfaces" setup-di-install-device-interfaces :convention :stdcall) :int32
(device-info-set :int64) ; HDEVINFO
(device-info-data :pointer)) ; SP_DEVINFO_DATA*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupDiInstallDeviceInterfaces = Win32::API::More->new('SETUPAPI',
'BOOL SetupDiInstallDeviceInterfaces(LPARAM DeviceInfoSet, LPVOID DeviceInfoData)');
# my $ret = $SetupDiInstallDeviceInterfaces->Call($DeviceInfoSet, $DeviceInfoData);
# DeviceInfoSet : HDEVINFO -> LPARAM
# DeviceInfoData : SP_DEVINFO_DATA* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f SetupDiCreateDeviceInterfaceW — デバイスに新しいデバイスインターフェイスを作成する。
使用する型