ホーム › Devices.DeviceAndDriverInstallation › SetupOpenInfFileA
SetupOpenInfFileA
関数INFファイルを開いてハンドルを取得する(ANSI)。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
void* SetupOpenInfFileA(
LPCSTR FileName,
LPCSTR InfClass, // optional
INF_STYLE InfStyle,
DWORD* ErrorLine // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| FileName | LPCSTR | in |
| InfClass | LPCSTR | inoptional |
| InfStyle | INF_STYLE | in |
| ErrorLine | DWORD* | outoptional |
戻り値の型: void*
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
void* SetupOpenInfFileA(
LPCSTR FileName,
LPCSTR InfClass, // optional
INF_STYLE InfStyle,
DWORD* ErrorLine // optional
);[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr SetupOpenInfFileA(
[MarshalAs(UnmanagedType.LPStr)] string FileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string InfClass, // LPCSTR optional
uint InfStyle, // INF_STYLE
IntPtr ErrorLine // DWORD* optional, out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupOpenInfFileA(
<MarshalAs(UnmanagedType.LPStr)> FileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> InfClass As String, ' LPCSTR optional
InfStyle As UInteger, ' INF_STYLE
ErrorLine As IntPtr ' DWORD* optional, out
) As IntPtr
End Function' FileName : LPCSTR
' InfClass : LPCSTR optional
' InfStyle : INF_STYLE
' ErrorLine : DWORD* optional, out
Declare PtrSafe Function SetupOpenInfFileA Lib "setupapi" ( _
ByVal FileName As String, _
ByVal InfClass As String, _
ByVal InfStyle As Long, _
ByVal ErrorLine As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupOpenInfFileA = ctypes.windll.setupapi.SetupOpenInfFileA
SetupOpenInfFileA.restype = ctypes.c_void_p
SetupOpenInfFileA.argtypes = [
wintypes.LPCSTR, # FileName : LPCSTR
wintypes.LPCSTR, # InfClass : LPCSTR 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')
SetupOpenInfFileA = Fiddle::Function.new(
lib['SetupOpenInfFileA'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCSTR
Fiddle::TYPE_VOIDP, # InfClass : LPCSTR optional
-Fiddle::TYPE_INT, # InfStyle : INF_STYLE
Fiddle::TYPE_VOIDP, # ErrorLine : DWORD* optional, out
],
Fiddle::TYPE_VOIDP)#[link(name = "setupapi")]
extern "system" {
fn SetupOpenInfFileA(
FileName: *const u8, // LPCSTR
InfClass: *const u8, // LPCSTR 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.Ansi, SetLastError = true)]
public static extern IntPtr SetupOpenInfFileA([MarshalAs(UnmanagedType.LPStr)] string FileName, [MarshalAs(UnmanagedType.LPStr)] string InfClass, uint InfStyle, IntPtr ErrorLine);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupOpenInfFileA' -Namespace Win32 -PassThru
# $api::SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine)#uselib "SETUPAPI.dll"
#func global SetupOpenInfFileA "SetupOpenInfFileA" sptr, sptr, sptr, sptr
; SetupOpenInfFileA FileName, InfClass, InfStyle, varptr(ErrorLine) ; 戻り値は stat
; FileName : LPCSTR -> "sptr"
; InfClass : LPCSTR optional -> "sptr"
; InfStyle : INF_STYLE -> "sptr"
; ErrorLine : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileA "SetupOpenInfFileA" str, str, int, var ; res = SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine) ; FileName : LPCSTR -> "str" ; InfClass : LPCSTR optional -> "str" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileA "SetupOpenInfFileA" str, str, int, sptr ; res = SetupOpenInfFileA(FileName, InfClass, InfStyle, varptr(ErrorLine)) ; FileName : LPCSTR -> "str" ; InfClass : LPCSTR optional -> "str" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void* SetupOpenInfFileA(LPCSTR FileName, LPCSTR InfClass, INF_STYLE InfStyle, DWORD* ErrorLine) #uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileA "SetupOpenInfFileA" str, str, int, var ; res = SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine) ; FileName : LPCSTR -> "str" ; InfClass : LPCSTR optional -> "str" ; InfStyle : INF_STYLE -> "int" ; ErrorLine : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void* SetupOpenInfFileA(LPCSTR FileName, LPCSTR InfClass, INF_STYLE InfStyle, DWORD* ErrorLine) #uselib "SETUPAPI.dll" #cfunc global SetupOpenInfFileA "SetupOpenInfFileA" str, str, int, intptr ; res = SetupOpenInfFileA(FileName, InfClass, InfStyle, varptr(ErrorLine)) ; FileName : LPCSTR -> "str" ; InfClass : LPCSTR optional -> "str" ; 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")
procSetupOpenInfFileA = setupapi.NewProc("SetupOpenInfFileA")
)
// FileName (LPCSTR), InfClass (LPCSTR optional), InfStyle (INF_STYLE), ErrorLine (DWORD* optional, out)
r1, _, err := procSetupOpenInfFileA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(InfClass))),
uintptr(InfStyle),
uintptr(ErrorLine),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function SetupOpenInfFileA(
FileName: PAnsiChar; // LPCSTR
InfClass: PAnsiChar; // LPCSTR optional
InfStyle: DWORD; // INF_STYLE
ErrorLine: Pointer // DWORD* optional, out
): Pointer; stdcall;
external 'SETUPAPI.dll' name 'SetupOpenInfFileA';result := DllCall("SETUPAPI\SetupOpenInfFileA"
, "AStr", FileName ; LPCSTR
, "AStr", InfClass ; LPCSTR optional
, "UInt", InfStyle ; INF_STYLE
, "Ptr", ErrorLine ; DWORD* optional, out
, "Ptr") ; return: void*●SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine) = DLL("SETUPAPI.dll", "void* SetupOpenInfFileA(char*, char*, dword, void*)")
# 呼び出し: SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine)
# FileName : LPCSTR -> "char*"
# InfClass : LPCSTR optional -> "char*"
# InfStyle : INF_STYLE -> "dword"
# ErrorLine : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。