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

SetupFindFirstLineA

関数
INFの指定セクション内で最初の行を検索する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupFindFirstLineA(
    void* InfHandle,
    LPCSTR Section,
    LPCSTR Key,   // optional
    INFCONTEXT* Context
);

パラメーター

名前方向説明
InfHandlevoid*in検索対象の開いているINFハンドル。
SectionLPCSTRin検索するセクション名(ANSI)。
KeyLPCSTRinoptionalセクション内で一致を探すキー名(ANSI)。NULLでセクション先頭行を取得する。
ContextINFCONTEXT*out見つかった行の位置情報を受け取るINFCONTEXT構造体へのポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupFindFirstLineA(
    void* InfHandle,
    LPCSTR Section,
    LPCSTR Key,   // optional
    INFCONTEXT* Context
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupFindFirstLineA(
    IntPtr InfHandle,   // void*
    [MarshalAs(UnmanagedType.LPStr)] string Section,   // LPCSTR
    [MarshalAs(UnmanagedType.LPStr)] string Key,   // LPCSTR optional
    IntPtr Context   // INFCONTEXT* out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupFindFirstLineA(
    InfHandle As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPStr)> Section As String,   ' LPCSTR
    <MarshalAs(UnmanagedType.LPStr)> Key As String,   ' LPCSTR optional
    Context As IntPtr   ' INFCONTEXT* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' InfHandle : void*
' Section : LPCSTR
' Key : LPCSTR optional
' Context : INFCONTEXT* out
Declare PtrSafe Function SetupFindFirstLineA Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal Section As String, _
    ByVal Key As String, _
    ByVal Context As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupFindFirstLineA = ctypes.windll.setupapi.SetupFindFirstLineA
SetupFindFirstLineA.restype = wintypes.BOOL
SetupFindFirstLineA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    wintypes.LPCSTR,  # Section : LPCSTR
    wintypes.LPCSTR,  # Key : LPCSTR optional
    ctypes.c_void_p,  # Context : INFCONTEXT* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupFindFirstLineA = setupapi.NewProc("SetupFindFirstLineA")
)

// InfHandle (void*), Section (LPCSTR), Key (LPCSTR optional), Context (INFCONTEXT* out)
r1, _, err := procSetupFindFirstLineA.Call(
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(Section))),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(Key))),
	uintptr(Context),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupFindFirstLineA(
  InfHandle: Pointer;   // void*
  Section: PAnsiChar;   // LPCSTR
  Key: PAnsiChar;   // LPCSTR optional
  Context: Pointer   // INFCONTEXT* out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupFindFirstLineA';
result := DllCall("SETUPAPI\SetupFindFirstLineA"
    , "Ptr", InfHandle   ; void*
    , "AStr", Section   ; LPCSTR
    , "AStr", Key   ; LPCSTR optional
    , "Ptr", Context   ; INFCONTEXT* out
    , "Int")   ; return: BOOL
●SetupFindFirstLineA(InfHandle, Section, Key, Context) = DLL("SETUPAPI.dll", "bool SetupFindFirstLineA(void*, char*, char*, void*)")
# 呼び出し: SetupFindFirstLineA(InfHandle, Section, Key, Context)
# InfHandle : void* -> "void*"
# Section : LPCSTR -> "char*"
# Key : LPCSTR optional -> "char*"
# Context : INFCONTEXT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef SetupFindFirstLineANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>);
typedef SetupFindFirstLineADart = int Function(Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Void>);
final SetupFindFirstLineA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupFindFirstLineANative, SetupFindFirstLineADart>('SetupFindFirstLineA');
// InfHandle : void* -> Pointer<Void>
// Section : LPCSTR -> Pointer<Utf8>
// Key : LPCSTR optional -> Pointer<Utf8>
// Context : INFCONTEXT* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupFindFirstLineA(
  InfHandle: Pointer;   // void*
  Section: PAnsiChar;   // LPCSTR
  Key: PAnsiChar;   // LPCSTR optional
  Context: Pointer   // INFCONTEXT* out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupFindFirstLineA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupFindFirstLineA"
  c_SetupFindFirstLineA :: Ptr () -> CString -> CString -> Ptr () -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Section : LPCSTR -> CString
-- Key : LPCSTR optional -> CString
-- Context : INFCONTEXT* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupfindfirstlinea =
  foreign "SetupFindFirstLineA"
    ((ptr void) @-> string @-> string @-> (ptr void) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Section : LPCSTR -> string *)
(* Key : LPCSTR optional -> string *)
(* Context : INFCONTEXT* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupFindFirstLineA" setup-find-first-line-a :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (section :string)   ; LPCSTR
  (key :string)   ; LPCSTR optional
  (context :pointer))   ; INFCONTEXT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupFindFirstLineA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupFindFirstLineA(LPVOID InfHandle, LPCSTR Section, LPCSTR Key, LPVOID Context)');
# my $ret = $SetupFindFirstLineA->Call($InfHandle, $Section, $Key, $Context);
# InfHandle : void* -> LPVOID
# Section : LPCSTR -> LPCSTR
# Key : LPCSTR optional -> LPCSTR
# Context : INFCONTEXT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
使用する型