ホーム › 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 |
| InfClass | LPCWSTR | inoptional |
| InfStyle | INF_STYLE | in |
| ErrorLine | DWORD* | outoptional |
戻り値の型: 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 版の利用を推奨。