ホーム › 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 | 開くINFファイルの名前またはパス(ANSI)。 |
| InfClass | LPCSTR | inoptional | 想定するINFのクラス名(ANSI)。一致確認に使う。NULL可。 |
| InfStyle | INF_STYLE | in | 対象とするINFスタイル(旧形式/Win4形式)を示すフラグ。 |
| ErrorLine | DWORD* | outoptional | 解析エラーが起きた行番号を受け取る出力ポインタ。NULL可。 |
戻り値の型: 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)。const std = @import("std");
extern "setupapi" fn SetupOpenInfFileA(
FileName: [*c]const u8, // LPCSTR
InfClass: [*c]const u8, // LPCSTR optional
InfStyle: u32, // INF_STYLE
ErrorLine: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc SetupOpenInfFileA(
FileName: cstring, # LPCSTR
InfClass: cstring, # LPCSTR optional
InfStyle: uint32, # INF_STYLE
ErrorLine: ptr uint32 # DWORD* optional, out
): pointer {.importc: "SetupOpenInfFileA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
void* SetupOpenInfFileA(
const(char)* FileName, // LPCSTR
const(char)* InfClass, // LPCSTR optional
uint InfStyle, // INF_STYLE
uint* ErrorLine // DWORD* optional, out
);ccall((:SetupOpenInfFileA, "SETUPAPI.dll"), stdcall, Ptr{Cvoid},
(Cstring, Cstring, UInt32, Ptr{UInt32}),
FileName, InfClass, InfStyle, ErrorLine)
# FileName : LPCSTR -> Cstring
# InfClass : LPCSTR optional -> Cstring
# InfStyle : INF_STYLE -> UInt32
# ErrorLine : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* SetupOpenInfFileA(
const char* FileName,
const char* InfClass,
uint32_t InfStyle,
uint32_t* ErrorLine);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine)
-- FileName : LPCSTR
-- InfClass : LPCSTR optional
-- InfStyle : INF_STYLE
-- ErrorLine : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupOpenInfFileA = lib.func('__stdcall', 'SetupOpenInfFileA', 'void *', ['str', 'str', 'uint32_t', 'uint32_t *']);
// SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine)
// FileName : LPCSTR -> 'str'
// InfClass : LPCSTR optional -> 'str'
// InfStyle : INF_STYLE -> 'uint32_t'
// ErrorLine : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupOpenInfFileA: { parameters: ["buffer", "buffer", "u32", "pointer"], result: "pointer" },
});
// lib.symbols.SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine)
// FileName : LPCSTR -> "buffer"
// InfClass : LPCSTR optional -> "buffer"
// InfStyle : INF_STYLE -> "u32"
// ErrorLine : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* SetupOpenInfFileA(
const char* FileName,
const char* InfClass,
uint32_t InfStyle,
uint32_t* ErrorLine);
C, "SETUPAPI.dll");
// $ffi->SetupOpenInfFileA(FileName, InfClass, InfStyle, ErrorLine);
// FileName : LPCSTR
// InfClass : LPCSTR 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.ASCII_OPTIONS);
Pointer SetupOpenInfFileA(
String FileName, // LPCSTR
String InfClass, // LPCSTR optional
int InfStyle, // INF_STYLE
IntByReference ErrorLine // DWORD* optional, out
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupOpenInfFileA = SetupOpenInfFileA(
FileName : UInt8*, # LPCSTR
InfClass : UInt8*, # LPCSTR 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 SetupOpenInfFileANative = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupOpenInfFileADart = Pointer<Void> Function(Pointer<Utf8>, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupOpenInfFileA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupOpenInfFileANative, SetupOpenInfFileADart>('SetupOpenInfFileA');
// FileName : LPCSTR -> Pointer<Utf8>
// InfClass : LPCSTR optional -> Pointer<Utf8>
// InfStyle : INF_STYLE -> Uint32
// ErrorLine : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupOpenInfFileA"
c_SetupOpenInfFileA :: CString -> CString -> Word32 -> Ptr Word32 -> IO (Ptr ())
-- FileName : LPCSTR -> CString
-- InfClass : LPCSTR optional -> CString
-- InfStyle : INF_STYLE -> Word32
-- ErrorLine : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupopeninffilea =
foreign "SetupOpenInfFileA"
(string @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning (ptr void))
(* FileName : LPCSTR -> string *)
(* InfClass : LPCSTR optional -> string *)
(* 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 ("SetupOpenInfFileA" setup-open-inf-file-a :convention :stdcall) :pointer
(file-name :string) ; LPCSTR
(inf-class :string) ; LPCSTR 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 $SetupOpenInfFileA = Win32::API::More->new('SETUPAPI',
'LPVOID SetupOpenInfFileA(LPCSTR FileName, LPCSTR InfClass, DWORD InfStyle, LPVOID ErrorLine)');
# my $ret = $SetupOpenInfFileA->Call($FileName, $InfClass, $InfStyle, $ErrorLine);
# FileName : LPCSTR -> LPCSTR
# InfClass : LPCSTR optional -> LPCSTR
# InfStyle : INF_STYLE -> DWORD
# ErrorLine : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupOpenInfFileW (Unicode版) — INFファイルを開いてハンドルを取得する(Unicode)。
使用する型