ホーム › Devices.DeviceAndDriverInstallation › SetupGetLineByIndexA
SetupGetLineByIndexA
関数INFセクション内の指定インデックスの行を取得する(ANSI)。
シグネチャ
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupGetLineByIndexA(
void* InfHandle,
LPCSTR Section,
DWORD Index,
INFCONTEXT* Context
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InfHandle | void* | in | 検索対象の開いているINFハンドル。 |
| Section | LPCSTR | in | 対象セクション名(ANSI)。 |
| Index | DWORD | in | セクション内で取得する行のインデックス(0起点)。 |
| Context | INFCONTEXT* | out | 見つかった行の位置情報を受け取るINFCONTEXT構造体へのポインタ。 |
戻り値の型: BOOL
各言語での呼び出し定義
// SETUPAPI.dll (ANSI / -A)
#include <windows.h>
BOOL SetupGetLineByIndexA(
void* InfHandle,
LPCSTR Section,
DWORD Index,
INFCONTEXT* Context
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetLineByIndexA(
IntPtr InfHandle, // void*
[MarshalAs(UnmanagedType.LPStr)] string Section, // LPCSTR
uint Index, // DWORD
IntPtr Context // INFCONTEXT* out
);<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetLineByIndexA(
InfHandle As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> Section As String, ' LPCSTR
Index As UInteger, ' DWORD
Context As IntPtr ' INFCONTEXT* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' InfHandle : void*
' Section : LPCSTR
' Index : DWORD
' Context : INFCONTEXT* out
Declare PtrSafe Function SetupGetLineByIndexA Lib "setupapi" ( _
ByVal InfHandle As LongPtr, _
ByVal Section As String, _
ByVal Index As Long, _
ByVal Context As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetupGetLineByIndexA = ctypes.windll.setupapi.SetupGetLineByIndexA
SetupGetLineByIndexA.restype = wintypes.BOOL
SetupGetLineByIndexA.argtypes = [
ctypes.POINTER(None), # InfHandle : void*
wintypes.LPCSTR, # Section : LPCSTR
wintypes.DWORD, # Index : DWORD
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')
SetupGetLineByIndexA = Fiddle::Function.new(
lib['SetupGetLineByIndexA'],
[
Fiddle::TYPE_VOIDP, # InfHandle : void*
Fiddle::TYPE_VOIDP, # Section : LPCSTR
-Fiddle::TYPE_INT, # Index : DWORD
Fiddle::TYPE_VOIDP, # Context : INFCONTEXT* out
],
Fiddle::TYPE_INT)#[link(name = "setupapi")]
extern "system" {
fn SetupGetLineByIndexA(
InfHandle: *mut (), // void*
Section: *const u8, // LPCSTR
Index: u32, // DWORD
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 SetupGetLineByIndexA(IntPtr InfHandle, [MarshalAs(UnmanagedType.LPStr)] string Section, uint Index, IntPtr Context);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetLineByIndexA' -Namespace Win32 -PassThru
# $api::SetupGetLineByIndexA(InfHandle, Section, Index, Context)#uselib "SETUPAPI.dll"
#func global SetupGetLineByIndexA "SetupGetLineByIndexA" sptr, sptr, sptr, sptr
; SetupGetLineByIndexA InfHandle, Section, Index, varptr(Context) ; 戻り値は stat
; InfHandle : void* -> "sptr"
; Section : LPCSTR -> "sptr"
; Index : DWORD -> "sptr"
; Context : INFCONTEXT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "SETUPAPI.dll" #cfunc global SetupGetLineByIndexA "SetupGetLineByIndexA" sptr, str, int, var ; res = SetupGetLineByIndexA(InfHandle, Section, Index, Context) ; InfHandle : void* -> "sptr" ; Section : LPCSTR -> "str" ; Index : DWORD -> "int" ; Context : INFCONTEXT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SETUPAPI.dll" #cfunc global SetupGetLineByIndexA "SetupGetLineByIndexA" sptr, str, int, sptr ; res = SetupGetLineByIndexA(InfHandle, Section, Index, varptr(Context)) ; InfHandle : void* -> "sptr" ; Section : LPCSTR -> "str" ; Index : DWORD -> "int" ; Context : INFCONTEXT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetupGetLineByIndexA(void* InfHandle, LPCSTR Section, DWORD Index, INFCONTEXT* Context) #uselib "SETUPAPI.dll" #cfunc global SetupGetLineByIndexA "SetupGetLineByIndexA" intptr, str, int, var ; res = SetupGetLineByIndexA(InfHandle, Section, Index, Context) ; InfHandle : void* -> "intptr" ; Section : LPCSTR -> "str" ; Index : DWORD -> "int" ; Context : INFCONTEXT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetupGetLineByIndexA(void* InfHandle, LPCSTR Section, DWORD Index, INFCONTEXT* Context) #uselib "SETUPAPI.dll" #cfunc global SetupGetLineByIndexA "SetupGetLineByIndexA" intptr, str, int, intptr ; res = SetupGetLineByIndexA(InfHandle, Section, Index, varptr(Context)) ; InfHandle : void* -> "intptr" ; Section : LPCSTR -> "str" ; Index : DWORD -> "int" ; Context : INFCONTEXT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
procSetupGetLineByIndexA = setupapi.NewProc("SetupGetLineByIndexA")
)
// InfHandle (void*), Section (LPCSTR), Index (DWORD), Context (INFCONTEXT* out)
r1, _, err := procSetupGetLineByIndexA.Call(
uintptr(InfHandle),
uintptr(unsafe.Pointer(windows.BytePtrFromString(Section))),
uintptr(Index),
uintptr(Context),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetupGetLineByIndexA(
InfHandle: Pointer; // void*
Section: PAnsiChar; // LPCSTR
Index: DWORD; // DWORD
Context: Pointer // INFCONTEXT* out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetLineByIndexA';result := DllCall("SETUPAPI\SetupGetLineByIndexA"
, "Ptr", InfHandle ; void*
, "AStr", Section ; LPCSTR
, "UInt", Index ; DWORD
, "Ptr", Context ; INFCONTEXT* out
, "Int") ; return: BOOL●SetupGetLineByIndexA(InfHandle, Section, Index, Context) = DLL("SETUPAPI.dll", "bool SetupGetLineByIndexA(void*, char*, dword, void*)")
# 呼び出し: SetupGetLineByIndexA(InfHandle, Section, Index, Context)
# InfHandle : void* -> "void*"
# Section : LPCSTR -> "char*"
# Index : DWORD -> "dword"
# Context : INFCONTEXT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "setupapi" fn SetupGetLineByIndexA(
InfHandle: ?*anyopaque, // void*
Section: [*c]const u8, // LPCSTR
Index: u32, // DWORD
Context: [*c]INFCONTEXT // INFCONTEXT* out
) callconv(std.os.windows.WINAPI) i32;proc SetupGetLineByIndexA(
InfHandle: pointer, # void*
Section: cstring, # LPCSTR
Index: uint32, # DWORD
Context: ptr INFCONTEXT # INFCONTEXT* out
): int32 {.importc: "SetupGetLineByIndexA", stdcall, dynlib: "SETUPAPI.dll".}pragma(lib, "setupapi");
extern(Windows)
int SetupGetLineByIndexA(
void* InfHandle, // void*
const(char)* Section, // LPCSTR
uint Index, // DWORD
INFCONTEXT* Context // INFCONTEXT* out
);ccall((:SetupGetLineByIndexA, "SETUPAPI.dll"), stdcall, Int32,
(Ptr{Cvoid}, Cstring, UInt32, Ptr{INFCONTEXT}),
InfHandle, Section, Index, Context)
# InfHandle : void* -> Ptr{Cvoid}
# Section : LPCSTR -> Cstring
# Index : DWORD -> UInt32
# Context : INFCONTEXT* out -> Ptr{INFCONTEXT}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupGetLineByIndexA(
void* InfHandle,
const char* Section,
uint32_t Index,
void* Context);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetLineByIndexA(InfHandle, Section, Index, Context)
-- InfHandle : void*
-- Section : LPCSTR
-- Index : DWORD
-- Context : INFCONTEXT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetLineByIndexA = lib.func('__stdcall', 'SetupGetLineByIndexA', 'int32_t', ['void *', 'str', 'uint32_t', 'void *']);
// SetupGetLineByIndexA(InfHandle, Section, Index, Context)
// InfHandle : void* -> 'void *'
// Section : LPCSTR -> 'str'
// Index : DWORD -> 'uint32_t'
// Context : INFCONTEXT* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SETUPAPI.dll", {
SetupGetLineByIndexA: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.SetupGetLineByIndexA(InfHandle, Section, Index, Context)
// InfHandle : void* -> "pointer"
// Section : LPCSTR -> "buffer"
// Index : DWORD -> "u32"
// Context : INFCONTEXT* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupGetLineByIndexA(
void* InfHandle,
const char* Section,
uint32_t Index,
void* Context);
C, "SETUPAPI.dll");
// $ffi->SetupGetLineByIndexA(InfHandle, Section, Index, Context);
// InfHandle : void*
// Section : LPCSTR
// Index : DWORD
// 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 SetupGetLineByIndexA(
Pointer InfHandle, // void*
String Section, // LPCSTR
int Index, // DWORD
Pointer Context // INFCONTEXT* out
);
}@[Link("setupapi")]
lib LibSETUPAPI
fun SetupGetLineByIndexA = SetupGetLineByIndexA(
InfHandle : Void*, # void*
Section : UInt8*, # LPCSTR
Index : UInt32, # DWORD
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 SetupGetLineByIndexANative = Int32 Function(Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Void>);
typedef SetupGetLineByIndexADart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Void>);
final SetupGetLineByIndexA = DynamicLibrary.open('SETUPAPI.dll')
.lookupFunction<SetupGetLineByIndexANative, SetupGetLineByIndexADart>('SetupGetLineByIndexA');
// InfHandle : void* -> Pointer<Void>
// Section : LPCSTR -> Pointer<Utf8>
// Index : DWORD -> Uint32
// Context : INFCONTEXT* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupGetLineByIndexA(
InfHandle: Pointer; // void*
Section: PAnsiChar; // LPCSTR
Index: DWORD; // DWORD
Context: Pointer // INFCONTEXT* out
): BOOL; stdcall;
external 'SETUPAPI.dll' name 'SetupGetLineByIndexA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupGetLineByIndexA"
c_SetupGetLineByIndexA :: Ptr () -> CString -> Word32 -> Ptr () -> IO CInt
-- InfHandle : void* -> Ptr ()
-- Section : LPCSTR -> CString
-- Index : DWORD -> Word32
-- Context : INFCONTEXT* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupgetlinebyindexa =
foreign "SetupGetLineByIndexA"
((ptr void) @-> string @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* Section : LPCSTR -> string *)
(* Index : DWORD -> uint32_t *)
(* 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 ("SetupGetLineByIndexA" setup-get-line-by-index-a :convention :stdcall) :int32
(inf-handle :pointer) ; void*
(section :string) ; LPCSTR
(index :uint32) ; DWORD
(context :pointer)) ; INFCONTEXT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupGetLineByIndexA = Win32::API::More->new('SETUPAPI',
'BOOL SetupGetLineByIndexA(LPVOID InfHandle, LPCSTR Section, DWORD Index, LPVOID Context)');
# my $ret = $SetupGetLineByIndexA->Call($InfHandle, $Section, $Index, $Context);
# InfHandle : void* -> LPVOID
# Section : LPCSTR -> LPCSTR
# Index : DWORD -> DWORD
# Context : INFCONTEXT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f SetupGetLineByIndexW (Unicode版) — INFセクション内の指定インデックスの行を取得する(Unicode)。
使用する型