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

SetupQuerySourceListA

関数
現在のソースリストの内容を照会して取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupQuerySourceListA(
    DWORD Flags,
    LPCSTR** List,
    DWORD* Count
);

パラメーター

名前方向説明
FlagsDWORDin対象とするソースリストの種別を指定するフラグ。
ListLPCSTR**out取得したソースパス文字列(ANSI)配列へのポインタを受け取る出力。SetupFreeSourceListで解放する。
CountDWORD*out取得したソース数を受け取る出力ポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupQuerySourceListA(
    DWORD Flags,
    LPCSTR** List,
    DWORD* Count
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupQuerySourceListA(
    uint Flags,   // DWORD
    IntPtr List,   // LPCSTR** out
    out uint Count   // DWORD* out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupQuerySourceListA(
    Flags As UInteger,   ' DWORD
    List As IntPtr,   ' LPCSTR** out
    <Out> ByRef Count As UInteger   ' DWORD* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' Flags : DWORD
' List : LPCSTR** out
' Count : DWORD* out
Declare PtrSafe Function SetupQuerySourceListA Lib "setupapi" ( _
    ByVal Flags As Long, _
    ByVal List As LongPtr, _
    ByRef Count As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupQuerySourceListA = ctypes.windll.setupapi.SetupQuerySourceListA
SetupQuerySourceListA.restype = wintypes.BOOL
SetupQuerySourceListA.argtypes = [
    wintypes.DWORD,  # Flags : DWORD
    ctypes.c_void_p,  # List : LPCSTR** out
    ctypes.POINTER(wintypes.DWORD),  # Count : DWORD* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupQuerySourceListA = Fiddle::Function.new(
  lib['SetupQuerySourceListA'],
  [
    -Fiddle::TYPE_INT,  # Flags : DWORD
    Fiddle::TYPE_VOIDP,  # List : LPCSTR** out
    Fiddle::TYPE_VOIDP,  # Count : DWORD* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupQuerySourceListA(
        Flags: u32,  // DWORD
        List: *const *const *const u8,  // LPCSTR** out
        Count: *mut u32  // DWORD* 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 SetupQuerySourceListA(uint Flags, IntPtr List, out uint Count);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupQuerySourceListA' -Namespace Win32 -PassThru
# $api::SetupQuerySourceListA(Flags, List, Count)
#uselib "SETUPAPI.dll"
#func global SetupQuerySourceListA "SetupQuerySourceListA" sptr, sptr, sptr
; SetupQuerySourceListA Flags, varptr(List), varptr(Count)   ; 戻り値は stat
; Flags : DWORD -> "sptr"
; List : LPCSTR** out -> "sptr"
; Count : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupQuerySourceListA "SetupQuerySourceListA" int, var, var
; res = SetupQuerySourceListA(Flags, List, Count)
; Flags : DWORD -> "int"
; List : LPCSTR** out -> "var"
; Count : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupQuerySourceListA(DWORD Flags, LPCSTR** List, DWORD* Count)
#uselib "SETUPAPI.dll"
#cfunc global SetupQuerySourceListA "SetupQuerySourceListA" int, var, var
; res = SetupQuerySourceListA(Flags, List, Count)
; Flags : DWORD -> "int"
; List : LPCSTR** out -> "var"
; Count : DWORD* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupQuerySourceListA = setupapi.NewProc("SetupQuerySourceListA")
)

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

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

typedef SetupQuerySourceListANative = Int32 Function(Uint32, Pointer<Pointer<Utf8>>, Pointer<Uint32>);
typedef SetupQuerySourceListADart = int Function(int, Pointer<Pointer<Utf8>>, Pointer<Uint32>);
final SetupQuerySourceListA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupQuerySourceListANative, SetupQuerySourceListADart>('SetupQuerySourceListA');
// Flags : DWORD -> Uint32
// List : LPCSTR** out -> Pointer<Pointer<Utf8>>
// Count : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupQuerySourceListA(
  Flags: DWORD;   // DWORD
  List: PPAnsiChar;   // LPCSTR** out
  Count: Pointer   // DWORD* out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupQuerySourceListA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupQuerySourceListA"
  c_SetupQuerySourceListA :: Word32 -> Ptr CString -> Ptr Word32 -> IO CInt
-- Flags : DWORD -> Word32
-- List : LPCSTR** out -> Ptr CString
-- Count : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupquerysourcelista =
  foreign "SetupQuerySourceListA"
    (uint32_t @-> (ptr string) @-> (ptr uint32_t) @-> returning int32_t)
(* Flags : DWORD -> uint32_t *)
(* List : LPCSTR** out -> (ptr string) *)
(* Count : DWORD* 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 ("SetupQuerySourceListA" setup-query-source-list-a :convention :stdcall) :int32
  (flags :uint32)   ; DWORD
  (list :pointer)   ; LPCSTR** out
  (count :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupQuerySourceListA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupQuerySourceListA(DWORD Flags, LPVOID List, LPVOID Count)');
# my $ret = $SetupQuerySourceListA->Call($Flags, $List, $Count);
# Flags : DWORD -> DWORD
# List : LPCSTR** out -> LPVOID
# Count : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い