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

SetupEnumInfSectionsW

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

シグネチャ

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupEnumInfSectionsW(
    void* InfHandle,
    DWORD Index,
    LPWSTR Buffer,   // optional
    DWORD Size,
    DWORD* SizeNeeded   // optional
);

パラメーター

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

戻り値の型: BOOL

各言語での呼び出し定義

// SETUPAPI.dll  (Unicode / -W)
#include <windows.h>

BOOL SetupEnumInfSectionsW(
    void* InfHandle,
    DWORD Index,
    LPWSTR Buffer,   // optional
    DWORD Size,
    DWORD* SizeNeeded   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupEnumInfSectionsW(
    IntPtr InfHandle,   // void*
    uint Index,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buffer,   // LPWSTR optional, out
    uint Size,   // DWORD
    IntPtr SizeNeeded   // DWORD* optional, out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupEnumInfSectionsW(
    InfHandle As IntPtr,   ' void*
    Index As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> Buffer As System.Text.StringBuilder,   ' LPWSTR optional, out
    Size As UInteger,   ' DWORD
    SizeNeeded As IntPtr   ' DWORD* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' InfHandle : void*
' Index : DWORD
' Buffer : LPWSTR optional, out
' Size : DWORD
' SizeNeeded : DWORD* optional, out
Declare PtrSafe Function SetupEnumInfSectionsW Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal Index As Long, _
    ByVal Buffer As LongPtr, _
    ByVal Size As Long, _
    ByVal SizeNeeded As LongPtr) As Long
' 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

SetupEnumInfSectionsW = ctypes.windll.setupapi.SetupEnumInfSectionsW
SetupEnumInfSectionsW.restype = wintypes.BOOL
SetupEnumInfSectionsW.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.DWORD,  # Index : DWORD
    wintypes.LPWSTR,  # Buffer : LPWSTR 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')
SetupEnumInfSectionsW = Fiddle::Function.new(
  lib['SetupEnumInfSectionsW'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    -Fiddle::TYPE_INT,  # Index : DWORD
    Fiddle::TYPE_VOIDP,  # Buffer : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # Size : DWORD
    Fiddle::TYPE_VOIDP,  # SizeNeeded : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupEnumInfSectionsW(
        InfHandle: *mut (),  // void*
        Index: u32,  // DWORD
        Buffer: *mut u16,  // LPWSTR 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.Unicode, SetLastError = true)]
public static extern bool SetupEnumInfSectionsW(IntPtr InfHandle, uint Index, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder Buffer, uint Size, IntPtr SizeNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupEnumInfSectionsW' -Namespace Win32 -PassThru
# $api::SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
#uselib "SETUPAPI.dll"
#func global SetupEnumInfSectionsW "SetupEnumInfSectionsW" wptr, wptr, wptr, wptr, wptr
; SetupEnumInfSectionsW InfHandle, Index, varptr(Buffer), Size, varptr(SizeNeeded)   ; 戻り値は stat
; InfHandle : void* -> "wptr"
; Index : DWORD -> "wptr"
; Buffer : LPWSTR optional, out -> "wptr"
; Size : DWORD -> "wptr"
; SizeNeeded : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupEnumInfSectionsW "SetupEnumInfSectionsW" sptr, int, var, int, var
; res = SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
; InfHandle : void* -> "sptr"
; Index : DWORD -> "int"
; Buffer : LPWSTR optional, out -> "var"
; Size : DWORD -> "int"
; SizeNeeded : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupEnumInfSectionsW(void* InfHandle, DWORD Index, LPWSTR Buffer, DWORD Size, DWORD* SizeNeeded)
#uselib "SETUPAPI.dll"
#cfunc global SetupEnumInfSectionsW "SetupEnumInfSectionsW" intptr, int, var, int, var
; res = SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
; InfHandle : void* -> "intptr"
; Index : DWORD -> "int"
; Buffer : LPWSTR 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")
	procSetupEnumInfSectionsW = setupapi.NewProc("SetupEnumInfSectionsW")
)

// InfHandle (void*), Index (DWORD), Buffer (LPWSTR optional, out), Size (DWORD), SizeNeeded (DWORD* optional, out)
r1, _, err := procSetupEnumInfSectionsW.Call(
	uintptr(InfHandle),
	uintptr(Index),
	uintptr(Buffer),
	uintptr(Size),
	uintptr(SizeNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupEnumInfSectionsW(
  InfHandle: Pointer;   // void*
  Index: DWORD;   // DWORD
  Buffer: PWideChar;   // LPWSTR optional, out
  Size: DWORD;   // DWORD
  SizeNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupEnumInfSectionsW';
result := DllCall("SETUPAPI\SetupEnumInfSectionsW"
    , "Ptr", InfHandle   ; void*
    , "UInt", Index   ; DWORD
    , "Ptr", Buffer   ; LPWSTR optional, out
    , "UInt", Size   ; DWORD
    , "Ptr", SizeNeeded   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded) = DLL("SETUPAPI.dll", "bool SetupEnumInfSectionsW(void*, dword, char*, dword, void*)")
# 呼び出し: SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
# InfHandle : void* -> "void*"
# Index : DWORD -> "dword"
# Buffer : LPWSTR optional, out -> "char*"
# Size : DWORD -> "dword"
# SizeNeeded : 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 SetupEnumInfSectionsW(
    InfHandle: ?*anyopaque, // void*
    Index: u32, // DWORD
    Buffer: [*c]u16, // LPWSTR optional, out
    Size: u32, // DWORD
    SizeNeeded: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupEnumInfSectionsW(
    InfHandle: pointer,  # void*
    Index: uint32,  # DWORD
    Buffer: ptr uint16,  # LPWSTR optional, out
    Size: uint32,  # DWORD
    SizeNeeded: ptr uint32  # DWORD* optional, out
): int32 {.importc: "SetupEnumInfSectionsW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupEnumInfSectionsW(
    void* InfHandle,   // void*
    uint Index,   // DWORD
    wchar* Buffer,   // LPWSTR optional, out
    uint Size,   // DWORD
    uint* SizeNeeded   // DWORD* optional, out
);
ccall((:SetupEnumInfSectionsW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Ptr{UInt16}, UInt32, Ptr{UInt32}),
      InfHandle, Index, Buffer, Size, SizeNeeded)
# InfHandle : void* -> Ptr{Cvoid}
# Index : DWORD -> UInt32
# Buffer : LPWSTR optional, out -> Ptr{UInt16}
# Size : DWORD -> UInt32
# SizeNeeded : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupEnumInfSectionsW(
    void* InfHandle,
    uint32_t Index,
    uint16_t* Buffer,
    uint32_t Size,
    uint32_t* SizeNeeded);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
-- InfHandle : void*
-- Index : DWORD
-- Buffer : LPWSTR optional, out
-- Size : DWORD
-- SizeNeeded : 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 SetupEnumInfSectionsW = lib.func('__stdcall', 'SetupEnumInfSectionsW', 'int32_t', ['void *', 'uint32_t', 'uint16_t *', 'uint32_t', 'uint32_t *']);
// SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
// InfHandle : void* -> 'void *'
// Index : DWORD -> 'uint32_t'
// Buffer : LPWSTR optional, out -> 'uint16_t *'
// Size : DWORD -> 'uint32_t'
// SizeNeeded : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupEnumInfSectionsW: { parameters: ["pointer", "u32", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded)
// InfHandle : void* -> "pointer"
// Index : DWORD -> "u32"
// Buffer : LPWSTR optional, out -> "buffer"
// Size : DWORD -> "u32"
// SizeNeeded : DWORD* optional, out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupEnumInfSectionsW(
    void* InfHandle,
    uint32_t Index,
    uint16_t* Buffer,
    uint32_t Size,
    uint32_t* SizeNeeded);
C, "SETUPAPI.dll");
// $ffi->SetupEnumInfSectionsW(InfHandle, Index, Buffer, Size, SizeNeeded);
// InfHandle : void*
// Index : DWORD
// Buffer : LPWSTR 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.UNICODE_OPTIONS);
    boolean SetupEnumInfSectionsW(
        Pointer InfHandle,   // void*
        int Index,   // DWORD
        char[] Buffer,   // LPWSTR optional, out
        int Size,   // DWORD
        IntByReference SizeNeeded   // DWORD* optional, out
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupEnumInfSectionsW = SetupEnumInfSectionsW(
    InfHandle : Void*,   # void*
    Index : UInt32,   # DWORD
    Buffer : UInt16*,   # LPWSTR 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 SetupEnumInfSectionsWNative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf16>, Uint32, Pointer<Uint32>);
typedef SetupEnumInfSectionsWDart = int Function(Pointer<Void>, int, Pointer<Utf16>, int, Pointer<Uint32>);
final SetupEnumInfSectionsW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupEnumInfSectionsWNative, SetupEnumInfSectionsWDart>('SetupEnumInfSectionsW');
// InfHandle : void* -> Pointer<Void>
// Index : DWORD -> Uint32
// Buffer : LPWSTR optional, out -> Pointer<Utf16>
// Size : DWORD -> Uint32
// SizeNeeded : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupEnumInfSectionsW(
  InfHandle: Pointer;   // void*
  Index: DWORD;   // DWORD
  Buffer: PWideChar;   // LPWSTR optional, out
  Size: DWORD;   // DWORD
  SizeNeeded: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupEnumInfSectionsW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let setupenuminfsectionsw =
  foreign "SetupEnumInfSectionsW"
    ((ptr void) @-> uint32_t @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Index : DWORD -> uint32_t *)
(* Buffer : LPWSTR optional, out -> (ptr uint16_t) *)
(* 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 ("SetupEnumInfSectionsW" setup-enum-inf-sections-w :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (index :uint32)   ; DWORD
  (buffer :pointer)   ; LPWSTR 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 $SetupEnumInfSectionsW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupEnumInfSectionsW(LPVOID InfHandle, DWORD Index, LPWSTR Buffer, DWORD Size, LPVOID SizeNeeded)');
# my $ret = $SetupEnumInfSectionsW->Call($InfHandle, $Index, $Buffer, $Size, $SizeNeeded);
# InfHandle : void* -> LPVOID
# Index : DWORD -> DWORD
# Buffer : LPWSTR optional, out -> LPWSTR
# Size : DWORD -> DWORD
# SizeNeeded : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い