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

SetupGetLineTextW

関数
INFの指定行またはキーのテキストを取得する(Unicode)。
DLLSETUPAPI.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupGetLineTextW(
    INFCONTEXT* Context,   // optional
    void* InfHandle,   // optional
    LPCWSTR Section,   // optional
    LPCWSTR Key,   // optional
    LPWSTR ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);

パラメーター

名前方向
ContextINFCONTEXT*inoptional
InfHandlevoid*inoptional
SectionLPCWSTRinoptional
KeyLPCWSTRinoptional
ReturnBufferLPWSTRoutoptional
ReturnBufferSizeDWORDin
RequiredSizeDWORD*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupGetLineTextW = Fiddle::Function.new(
  lib['SetupGetLineTextW'],
  [
    Fiddle::TYPE_VOIDP,  # Context : INFCONTEXT* optional
    Fiddle::TYPE_VOIDP,  # InfHandle : void* optional
    Fiddle::TYPE_VOIDP,  # Section : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # Key : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # ReturnBuffer : LPWSTR optional, out
    -Fiddle::TYPE_INT,  # ReturnBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "setupapi")]
extern "system" {
    fn SetupGetLineTextW(
        Context: *mut INFCONTEXT,  // INFCONTEXT* optional
        InfHandle: *mut (),  // void* optional
        Section: *const u16,  // LPCWSTR optional
        Key: *const u16,  // LPCWSTR optional
        ReturnBuffer: *mut u16,  // LPWSTR optional, out
        ReturnBufferSize: u32,  // DWORD
        RequiredSize: *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 SetupGetLineTextW(IntPtr Context, IntPtr InfHandle, [MarshalAs(UnmanagedType.LPWStr)] string Section, [MarshalAs(UnmanagedType.LPWStr)] string Key, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetLineTextW' -Namespace Win32 -PassThru
# $api::SetupGetLineTextW(Context, InfHandle, Section, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupGetLineTextW "SetupGetLineTextW" wptr, wptr, wptr, wptr, wptr, wptr, wptr
; SetupGetLineTextW varptr(Context), InfHandle, Section, Key, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)   ; 戻り値は stat
; Context : INFCONTEXT* optional -> "wptr"
; InfHandle : void* optional -> "wptr"
; Section : LPCWSTR optional -> "wptr"
; Key : LPCWSTR optional -> "wptr"
; ReturnBuffer : LPWSTR optional, out -> "wptr"
; ReturnBufferSize : DWORD -> "wptr"
; RequiredSize : DWORD* optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupGetLineTextW "SetupGetLineTextW" var, sptr, wstr, wstr, var, int, var
; res = SetupGetLineTextW(Context, InfHandle, Section, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
; Context : INFCONTEXT* optional -> "var"
; InfHandle : void* optional -> "sptr"
; Section : LPCWSTR optional -> "wstr"
; Key : LPCWSTR optional -> "wstr"
; ReturnBuffer : LPWSTR optional, out -> "var"
; ReturnBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupGetLineTextW(INFCONTEXT* Context, void* InfHandle, LPCWSTR Section, LPCWSTR Key, LPWSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupGetLineTextW "SetupGetLineTextW" var, intptr, wstr, wstr, var, int, var
; res = SetupGetLineTextW(Context, InfHandle, Section, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
; Context : INFCONTEXT* optional -> "var"
; InfHandle : void* optional -> "intptr"
; Section : LPCWSTR optional -> "wstr"
; Key : LPCWSTR optional -> "wstr"
; ReturnBuffer : LPWSTR optional, out -> "var"
; ReturnBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupGetLineTextW = setupapi.NewProc("SetupGetLineTextW")
)

// Context (INFCONTEXT* optional), InfHandle (void* optional), Section (LPCWSTR optional), Key (LPCWSTR optional), ReturnBuffer (LPWSTR optional, out), ReturnBufferSize (DWORD), RequiredSize (DWORD* optional, out)
r1, _, err := procSetupGetLineTextW.Call(
	uintptr(Context),
	uintptr(InfHandle),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Section))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(Key))),
	uintptr(ReturnBuffer),
	uintptr(ReturnBufferSize),
	uintptr(RequiredSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetupGetLineTextW(
  Context: Pointer;   // INFCONTEXT* optional
  InfHandle: Pointer;   // void* optional
  Section: PWideChar;   // LPCWSTR optional
  Key: PWideChar;   // LPCWSTR optional
  ReturnBuffer: PWideChar;   // LPWSTR optional, out
  ReturnBufferSize: DWORD;   // DWORD
  RequiredSize: Pointer   // DWORD* optional, out
): BOOL; stdcall;
  external 'SETUPAPI.dll' name 'SetupGetLineTextW';
result := DllCall("SETUPAPI\SetupGetLineTextW"
    , "Ptr", Context   ; INFCONTEXT* optional
    , "Ptr", InfHandle   ; void* optional
    , "WStr", Section   ; LPCWSTR optional
    , "WStr", Key   ; LPCWSTR optional
    , "Ptr", ReturnBuffer   ; LPWSTR optional, out
    , "UInt", ReturnBufferSize   ; DWORD
    , "Ptr", RequiredSize   ; DWORD* optional, out
    , "Int")   ; return: BOOL
●SetupGetLineTextW(Context, InfHandle, Section, Key, ReturnBuffer, ReturnBufferSize, RequiredSize) = DLL("SETUPAPI.dll", "bool SetupGetLineTextW(void*, void*, char*, char*, char*, dword, void*)")
# 呼び出し: SetupGetLineTextW(Context, InfHandle, Section, Key, ReturnBuffer, ReturnBufferSize, RequiredSize)
# Context : INFCONTEXT* optional -> "void*"
# InfHandle : void* optional -> "void*"
# Section : LPCWSTR optional -> "char*"
# Key : LPCWSTR optional -> "char*"
# ReturnBuffer : LPWSTR optional, out -> "char*"
# ReturnBufferSize : DWORD -> "dword"
# RequiredSize : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。