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
SectionLPCSTRin
KeyLPCSTRinoptional
ContextINFCONTEXT*out

戻り値の型: 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 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)。