Win32 API 日本語リファレンス
ホームDevices.DeviceAndDriverInstallation › SetupEnumInfSectionsA

SetupEnumInfSectionsA

関数
INFファイル内のセクションを順に列挙する。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupEnumInfSectionsA(
    void* InfHandle,
    DWORD Index,
    LPSTR Buffer,   // optional
    DWORD Size,
    DWORD* SizeNeeded   // optional
);

パラメーター

名前方向説明
InfHandlevoid*inセクションを列挙する対象INFファイルのハンドル。
IndexDWORDin0始まりのセクション列挙インデックス。エラーが返るまで増分する。
BufferLPSTRoutoptional列挙されたセクション名を受け取るバッファ(ANSI)。NULL可でサイズ照会。
SizeDWORDinBufferバッファの文字数。
SizeNeededDWORD*outoptionalセクション名に必要な文字数を受け取るポインタ。不足判定に使う。

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (ANSI / -A)
#include <windows.h>

BOOL SetupEnumInfSectionsA(
    void* InfHandle,
    DWORD Index,
    LPSTR Buffer,   // optional
    DWORD Size,
    DWORD* SizeNeeded   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupEnumInfSectionsA(
    IntPtr InfHandle,   // void*
    uint Index,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Buffer,   // LPSTR optional, out
    uint Size,   // DWORD
    IntPtr SizeNeeded   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupEnumInfSectionsA(
    InfHandle As IntPtr,   ' void*
    Index As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> Buffer As System.Text.StringBuilder,   ' LPSTR optional, out
    Size As UInteger,   ' DWORD
    SizeNeeded As IntPtr   ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' InfHandle : void*
' Index : DWORD
' Buffer : LPSTR optional, out
' Size : DWORD
' SizeNeeded : DWORD* optional, out
Declare PtrSafe Function SetupEnumInfSectionsA Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal Index As Long, _
    ByVal Buffer As String, _
    ByVal Size As Long, _
    ByVal SizeNeeded As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupEnumInfSectionsA = ctypes.windll.setupapi.SetupEnumInfSectionsA
SetupEnumInfSectionsA.restype = wintypes.BOOL
SetupEnumInfSectionsA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.DWORD,  # Index : DWORD
    wintypes.LPSTR,  # Buffer : LPSTR optional, out
    wintypes.DWORD,  # Size : DWORD
    ctypes.POINTER(wintypes.DWORD),  # SizeNeeded : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupEnumInfSectionsA = Fiddle::Function.new(
  lib['SetupEnumInfSectionsA'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    -Fiddle::TYPE_INT,  # Index : DWORD
    Fiddle::TYPE_VOIDP,  # Buffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # Size : DWORD
    Fiddle::TYPE_VOIDP,  # SizeNeeded : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupEnumInfSectionsA(
        InfHandle: *mut (),  // void*
        Index: u32,  // DWORD
        Buffer: *mut u8,  // LPSTR optional, out
        Size: u32,  // DWORD
        SizeNeeded: *mut u32  // DWORD* optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool SetupEnumInfSectionsA(IntPtr InfHandle, uint Index, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder Buffer, uint Size, IntPtr SizeNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupEnumInfSectionsA' -Namespace Win32 -PassThru
# $api::SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
#uselib "SETUPAPI.dll"
#func global SetupEnumInfSectionsA "SetupEnumInfSectionsA" sptr, sptr, sptr, sptr, sptr
; SetupEnumInfSectionsA InfHandle, Index, varptr(Buffer), Size, varptr(SizeNeeded)   ; 戻り値は stat
; InfHandle : void* -> "sptr"
; Index : DWORD -> "sptr"
; Buffer : LPSTR optional, out -> "sptr"
; Size : DWORD -> "sptr"
; SizeNeeded : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupEnumInfSectionsA "SetupEnumInfSectionsA" sptr, int, var, int, var
; res = SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
; InfHandle : void* -> "sptr"
; Index : DWORD -> "int"
; Buffer : LPSTR optional, out -> "var"
; Size : DWORD -> "int"
; SizeNeeded : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupEnumInfSectionsA(void* InfHandle, DWORD Index, LPSTR Buffer, DWORD Size, DWORD* SizeNeeded)
#uselib "SETUPAPI.dll"
#cfunc global SetupEnumInfSectionsA "SetupEnumInfSectionsA" intptr, int, var, int, var
; res = SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
; InfHandle : void* -> "intptr"
; Index : DWORD -> "int"
; Buffer : LPSTR optional, out -> "var"
; Size : DWORD -> "int"
; SizeNeeded : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupEnumInfSectionsA = setupapi.NewProc("SetupEnumInfSectionsA")
)

// InfHandle (void*), Index (DWORD), Buffer (LPSTR optional, out), Size (DWORD), SizeNeeded (DWORD* optional, out)
r1, _, err := procSetupEnumInfSectionsA.Call(
	uintptr(InfHandle),
	uintptr(Index),
	uintptr(Buffer),
	uintptr(Size),
	uintptr(SizeNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupEnumInfSectionsA(
  InfHandle: Pointer;   // void*
  Index: DWORD;   // DWORD
  Buffer: PAnsiChar;   // LPSTR optional, out
  Size: DWORD;   // DWORD
  SizeNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupEnumInfSectionsA';
result := DllCall("SETUPAPI\SetupEnumInfSectionsA"
    , "Ptr", InfHandle   ; void*
    , "UInt", Index   ; DWORD
    , "Ptr", Buffer   ; LPSTR optional, out
    , "UInt", Size   ; DWORD
    , "Ptr", SizeNeeded   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded) = DLL("SETUPAPI.dll", "bool SetupEnumInfSectionsA(void*, dword, char*, dword, void*)")
# 呼び出し: SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
# InfHandle : void* -> "void*"
# Index : DWORD -> "dword"
# Buffer : LPSTR optional, out -> "char*"
# Size : DWORD -> "dword"
# SizeNeeded : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupEnumInfSectionsA(
    InfHandle: ?*anyopaque, // void*
    Index: u32, // DWORD
    Buffer: [*c]u8, // LPSTR optional, out
    Size: u32, // DWORD
    SizeNeeded: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc SetupEnumInfSectionsA(
    InfHandle: pointer,  # void*
    Index: uint32,  # DWORD
    Buffer: ptr char,  # LPSTR optional, out
    Size: uint32,  # DWORD
    SizeNeeded: ptr uint32  # DWORD* optional, out
): int32 {.importc: "SetupEnumInfSectionsA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupEnumInfSectionsA(
    void* InfHandle,   // void*
    uint Index,   // DWORD
    char* Buffer,   // LPSTR optional, out
    uint Size,   // DWORD
    uint* SizeNeeded   // DWORD* optional, out
);
ccall((:SetupEnumInfSectionsA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
      InfHandle, Index, Buffer, Size, SizeNeeded)
# InfHandle : void* -> Ptr{Cvoid}
# Index : DWORD -> UInt32
# Buffer : LPSTR optional, out -> Ptr{UInt8}
# Size : DWORD -> UInt32
# SizeNeeded : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupEnumInfSectionsA(
    void* InfHandle,
    uint32_t Index,
    char* Buffer,
    uint32_t Size,
    uint32_t* SizeNeeded);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
-- InfHandle : void*
-- Index : DWORD
-- Buffer : LPSTR optional, out
-- Size : DWORD
-- SizeNeeded : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupEnumInfSectionsA = lib.func('__stdcall', 'SetupEnumInfSectionsA', 'int32_t', ['void *', 'uint32_t', 'char *', 'uint32_t', 'uint32_t *']);
// SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
// InfHandle : void* -> 'void *'
// Index : DWORD -> 'uint32_t'
// Buffer : LPSTR optional, out -> 'char *'
// Size : DWORD -> 'uint32_t'
// SizeNeeded : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupEnumInfSectionsA: { parameters: ["pointer", "u32", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded)
// InfHandle : void* -> "pointer"
// Index : DWORD -> "u32"
// Buffer : LPSTR optional, out -> "buffer"
// Size : DWORD -> "u32"
// SizeNeeded : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupEnumInfSectionsA(
    void* InfHandle,
    uint32_t Index,
    char* Buffer,
    uint32_t Size,
    uint32_t* SizeNeeded);
C, "SETUPAPI.dll");
// $ffi->SetupEnumInfSectionsA(InfHandle, Index, Buffer, Size, SizeNeeded);
// InfHandle : void*
// Index : DWORD
// Buffer : LPSTR optional, out
// Size : DWORD
// SizeNeeded : 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);
    boolean SetupEnumInfSectionsA(
        Pointer InfHandle,   // void*
        int Index,   // DWORD
        byte[] Buffer,   // LPSTR optional, out
        int Size,   // DWORD
        IntByReference SizeNeeded   // DWORD* optional, out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupEnumInfSectionsA = SetupEnumInfSectionsA(
    InfHandle : Void*,   # void*
    Index : UInt32,   # DWORD
    Buffer : UInt8*,   # LPSTR optional, out
    Size : UInt32,   # DWORD
    SizeNeeded : UInt32*   # DWORD* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupEnumInfSectionsANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Uint32, Pointer<Uint32>);
typedef SetupEnumInfSectionsADart = int Function(Pointer<Void>, int, Pointer<Utf8>, int, Pointer<Uint32>);
final SetupEnumInfSectionsA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupEnumInfSectionsANative, SetupEnumInfSectionsADart>('SetupEnumInfSectionsA');
// InfHandle : void* -> Pointer<Void>
// Index : DWORD -> Uint32
// Buffer : LPSTR optional, out -> Pointer<Utf8>
// Size : DWORD -> Uint32
// SizeNeeded : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupEnumInfSectionsA(
  InfHandle: Pointer;   // void*
  Index: DWORD;   // DWORD
  Buffer: PAnsiChar;   // LPSTR optional, out
  Size: DWORD;   // DWORD
  SizeNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupEnumInfSectionsA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupEnumInfSectionsA"
  c_SetupEnumInfSectionsA :: Ptr () -> Word32 -> CString -> Word32 -> Ptr Word32 -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Index : DWORD -> Word32
-- Buffer : LPSTR optional, out -> CString
-- Size : DWORD -> Word32
-- SizeNeeded : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupenuminfsectionsa =
  foreign "SetupEnumInfSectionsA"
    ((ptr void) @-> uint32_t @-> string @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Index : DWORD -> uint32_t *)
(* Buffer : LPSTR optional, out -> string *)
(* Size : DWORD -> uint32_t *)
(* SizeNeeded : 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 ("SetupEnumInfSectionsA" setup-enum-inf-sections-a :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (index :uint32)   ; DWORD
  (buffer :pointer)   ; LPSTR optional, out
  (size :uint32)   ; DWORD
  (size-needed :pointer))   ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupEnumInfSectionsA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupEnumInfSectionsA(LPVOID InfHandle, DWORD Index, LPSTR Buffer, DWORD Size, LPVOID SizeNeeded)');
# my $ret = $SetupEnumInfSectionsA->Call($InfHandle, $Index, $Buffer, $Size, $SizeNeeded);
# InfHandle : void* -> LPVOID
# Index : DWORD -> DWORD
# Buffer : LPSTR optional, out -> LPSTR
# Size : DWORD -> DWORD
# SizeNeeded : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い