ホーム › Devices.DeviceAndDriverInstallation › SetupOpenInfFileW
SetupOpenInfFileW
関数INFファイルを開いてハンドルを取得する(Unicode)。
シグネチャ
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
void* SetupOpenInfFileW(
LPCWSTR FileName,
LPCWSTR InfClass, // optional
INF_STYLE InfStyle,
DWORD* ErrorLine // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCWSTR | in | 開くINFファイルの名前またはパス(Unicode)。 |
| InfClass | LPCWSTR | inoptional | 想定するINFのクラス名(Unicode)。一致確認に使う。NULL可。 |
| InfStyle | INF_STYLE | in | 対象とするINFスタイル(旧形式/Win4形式)を示すフラグ。 |
| ErrorLine | DWORD* | outoptional | 解析エラーが起きた行番号を受け取る出力ポインタ。NULL可。 |
戻り値の型: void*
各言語での呼び出し定義
// SETUPAPI.dll (Unicode / -W)
#include <windows.h>
void* SetupOpenInfFileW(
LPCWSTR FileName,
LPCWSTR InfClass, // optional
INF_STYLE InfStyle,
DWORD* ErrorLine // optional
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupOpenInfFileW(
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string InfClass, // LPCWSTR optional
uint InfStyle, // INF_STYLE
IntPtr ErrorLine // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupOpenInfFileW(
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> InfClass As String, ' LPCWSTR optional
InfStyle As UInteger, ' INF_STYLE
ErrorLine As IntPtr ' DWORD* optional, out
) As IntPtr
End Function' FileName : LPCWSTR
' InfClass : LPCWSTR optional
' InfStyle : INF_STYLE
' ErrorLine : DWORD* optional, out
Declare PtrSafe Function SetupOpenInfFileW Lib "setupapi" ( _
ByVal FileName As LongPtr, _
ByVal InfClass As LongPtr, _
ByVal InfStyle As Long, _
ByVal ErrorLine As LongPtr) As LongPtr
' 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
SetupOpenInfFileW = ctypes.windll.setupapi.SetupOpenInfFileW
SetupOpenInfFileW.restype = ctypes.c_void_p
SetupOpenInfFileW.argtypes = [
wintypes.LPCWSTR, # FileName : LPCWSTR
wintypes.LPCWSTR, # InfClass : LPCWSTR optional
wintypes.DWORD, # InfStyle : INF_STYLE
ctypes.POINTER(wintypes.DWORD), # ErrorLine : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SETUPAPI.dll')
SetupOpenInfFileW = Fiddle::Function.new(
lib['SetupOpenInfFileW'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR
Fiddle::TYPE_VOIDP, # InfClass : LPCWSTR optional
-Fiddle::TYPE_INT, # InfStyle : INF_STYLE
Fiddle::TYPE_VOIDP, # ErrorLine : DWORD* optional, out
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "setupapi")]
extern "system" {
fn SetupOpenInfFileW(
FileName: *const u16, // LPCWSTR
InfClass: *const u16, // LPCWSTR optional
InfStyle: u32, // INF_STYLE
ErrorLine: *mut u32 // DWORD* optional, out
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SetupOpenInfFileW([MarshalAs(UnmanagedType.LPWStr)] string FileName, [MarshalAs(UnmanagedType.LPWStr)] string InfClass, uint InfStyle, IntPtr ErrorLine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupOpenInfFileW' -Namespace Win32 -PassThru
# $api::SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine)#uselib "SETUPAPI.dll"
#func global SetupOpenInfFileW "SetupOpenInfFileW" wptr, wptr, wptr, wptr
; SetupOpenInfFileW FileName, InfClass, InfStyle, varptr(ErrorLine) ; 戻り値は stat
; FileName : LPCWSTR -> "wptr"
; InfClass : LPCWSTR optional -> "wptr"
; InfStyle : INF_STYLE -> "wptr"
; ErrorLine : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileW "SetupOpenInfFileW" wstr, wstr, int, var ; res = SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine) ; FileName : LPCWSTR -> "wstr" ; InfClass : LPCWSTR optional -> "wstr" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileW "SetupOpenInfFileW" wstr, wstr, int, sptr ; res = SetupOpenInfFileW(FileName, InfClass, InfStyle, varptr(ErrorLine)) ; FileName : LPCWSTR -> "wstr" ; InfClass : LPCWSTR optional -> "wstr" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void* SetupOpenInfFileW(LPCWSTR FileName, LPCWSTR InfClass, INF_STYLE InfStyle, DWORD* ErrorLine) #uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileW "SetupOpenInfFileW" wstr, wstr, int, var ; res = SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine) ; FileName : LPCWSTR -> "wstr" ; InfClass : LPCWSTR optional -> "wstr" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void* SetupOpenInfFileW(LPCWSTR FileName, LPCWSTR InfClass, INF_STYLE InfStyle, DWORD* ErrorLine) #uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileW "SetupOpenInfFileW" wstr, wstr, int, intptr ; res = SetupOpenInfFileW(FileName, InfClass, InfStyle, varptr(ErrorLine)) ; FileName : LPCWSTR -> "wstr" ; InfClass : LPCWSTR optional -> "wstr" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupOpenInfFileW = setupapi.NewProc("SetupOpenInfFileW")
)
// FileName (LPCWSTR), InfClass (LPCWSTR optional), InfStyle (INF_STYLE), ErrorLine (DWORD* optional, out)
r1, _, err := procSetupOpenInfFileW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(InfClass))),
uintptr(InfStyle),
uintptr(ErrorLine),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function SetupOpenInfFileW(
FileName: PWideChar; // LPCWSTR
InfClass: PWideChar; // LPCWSTR optional
InfStyle: DWORD; // INF_STYLE
ErrorLine: Pointer // DWORD* optional, out
): Pointer; stdcall;
external 'SETUPAPI.dll' name 'SetupOpenInfFileW';result := DllCall("SETUPAPI\SetupOpenInfFileW"
, "WStr", FileName ; LPCWSTR
, "WStr", InfClass ; LPCWSTR optional
, "UInt", InfStyle ; INF_STYLE
, "Ptr", ErrorLine ; DWORD* optional, out
, "Ptr") ; return: void*●SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine) = DLL("SETUPAPI.dll", "void* SetupOpenInfFileW(char*, char*, dword, void*)")
# 呼び出し: SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine)
# FileName : LPCWSTR -> "char*"
# InfClass : LPCWSTR optional -> "char*"
# InfStyle : INF_STYLE -> "dword"
# ErrorLine : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "setupapi" fn SetupOpenInfFileW(
FileName: [*c]const u16, // LPCWSTR
InfClass: [*c]const u16, // LPCWSTR optional
InfStyle: u32, // INF_STYLE
ErrorLine: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc SetupOpenInfFileW(
FileName: WideCString, # LPCWSTR
InfClass: WideCString, # LPCWSTR optional
InfStyle: uint32, # INF_STYLE
ErrorLine: ptr uint32 # DWORD* optional, out
): pointer {.importc: "SetupOpenInfFileW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "setupapi");
extern(Windows)
void* SetupOpenInfFileW(
const(wchar)* FileName, // LPCWSTR
const(wchar)* InfClass, // LPCWSTR optional
uint InfStyle, // INF_STYLE
uint* ErrorLine // DWORD* optional, out
);ccall((:SetupOpenInfFileW, "SETUPAPI.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Cwstring, UInt32, Ptr{UInt32}),
FileName, InfClass, InfStyle, ErrorLine)
# FileName : LPCWSTR -> Cwstring
# InfClass : LPCWSTR optional -> Cwstring
# InfStyle : INF_STYLE -> UInt32
# ErrorLine : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void* SetupOpenInfFileW(
const uint16_t* FileName,
const uint16_t* InfClass,
uint32_t InfStyle,
uint32_t* ErrorLine);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine)
-- FileName : LPCWSTR
-- InfClass : LPCWSTR optional
-- InfStyle : INF_STYLE
-- ErrorLine : DWORD* optional, out
-- 構造体/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 SetupOpenInfFileW = lib.func('__stdcall', 'SetupOpenInfFileW', 'void *', ['str16', 'str16', 'uint32_t', 'uint32_t *']);
// SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine)
// FileName : LPCWSTR -> 'str16'
// InfClass : LPCWSTR optional -> 'str16'
// InfStyle : INF_STYLE -> 'uint32_t'
// ErrorLine : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupOpenInfFileW: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "pointer" },
});
// lib.symbols.SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine)
// FileName : LPCWSTR -> "buffer"
// InfClass : LPCWSTR optional -> "buffer"
// InfStyle : INF_STYLE -> "u32"
// ErrorLine : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* SetupOpenInfFileW(
const uint16_t* FileName,
const uint16_t* InfClass,
uint32_t InfStyle,
uint32_t* ErrorLine);
C, "SETUPAPI.dll");
// $ffi->SetupOpenInfFileW(FileName, InfClass, InfStyle, ErrorLine);
// FileName : LPCWSTR
// InfClass : LPCWSTR optional
// InfStyle : INF_STYLE
// ErrorLine : DWORD* optional, out
// 構造体/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);
Pointer SetupOpenInfFileW(
WString FileName, // LPCWSTR
WString InfClass, // LPCWSTR optional
int InfStyle, // INF_STYLE
IntByReference ErrorLine // DWORD* optional, out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("setupapi")]
lib LibSETUPAPI
fun SetupOpenInfFileW = SetupOpenInfFileW(
FileName : UInt16*, # LPCWSTR
InfClass : UInt16*, # LPCWSTR optional
InfStyle : UInt32, # INF_STYLE
ErrorLine : UInt32* # DWORD* optional, out
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupOpenInfFileWNative = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, Uint32, Pointer<Uint32>);
typedef SetupOpenInfFileWDart = Pointer<Void> Function(Pointer<Utf16>, Pointer<Utf16>, int, Pointer<Uint32>);
final SetupOpenInfFileW = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupOpenInfFileWNative, SetupOpenInfFileWDart>('SetupOpenInfFileW');
// FileName : LPCWSTR -> Pointer<Utf16>
// InfClass : LPCWSTR optional -> Pointer<Utf16>
// InfStyle : INF_STYLE -> Uint32
// ErrorLine : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupOpenInfFileW(
FileName: PWideChar; // LPCWSTR
InfClass: PWideChar; // LPCWSTR optional
InfStyle: DWORD; // INF_STYLE
ErrorLine: Pointer // DWORD* optional, out
): Pointer; stdcall;
external 'SETUPAPI.dll' name 'SetupOpenInfFileW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupOpenInfFileW"
c_SetupOpenInfFileW :: CWString -> CWString -> Word32 -> Ptr Word32 -> IO (Ptr ())
-- FileName : LPCWSTR -> CWString
-- InfClass : LPCWSTR optional -> CWString
-- InfStyle : INF_STYLE -> Word32
-- ErrorLine : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupopeninffilew =
foreign "SetupOpenInfFileW"
((ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> returning (ptr void))
(* FileName : LPCWSTR -> (ptr uint16_t) *)
(* InfClass : LPCWSTR optional -> (ptr uint16_t) *)
(* InfStyle : INF_STYLE -> uint32_t *)
(* ErrorLine : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)
(cffi:defcfun ("SetupOpenInfFileW" setup-open-inf-file-w :convention :stdcall) :pointer
(file-name (:string :encoding :utf-16le)) ; LPCWSTR
(inf-class (:string :encoding :utf-16le)) ; LPCWSTR optional
(inf-style :uint32) ; INF_STYLE
(error-line :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupOpenInfFileW = Win32::API::More->new('SETUPAPI',
'LPVOID SetupOpenInfFileW(LPCWSTR FileName, LPCWSTR InfClass, DWORD InfStyle, LPVOID ErrorLine)');
# my $ret = $SetupOpenInfFileW->Call($FileName, $InfClass, $InfStyle, $ErrorLine);
# FileName : LPCWSTR -> LPCWSTR
# InfClass : LPCWSTR optional -> LPCWSTR
# InfStyle : INF_STYLE -> DWORD
# ErrorLine : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f SetupOpenInfFileA (ANSI版) — INFファイルを開いてハンドルを取得する(ANSI)。
使用する型