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

SetupGetTargetPathA

関数
INFセクションのファイルコピー先パスを取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupGetTargetPathA(
    void* InfHandle,
    INFCONTEXT* InfContext,   // optional
    LPCSTR Section,   // optional
    LPSTR ReturnBuffer,   // optional
    DWORD ReturnBufferSize,
    DWORD* RequiredSize   // optional
);

パラメーター

名前方向
InfHandlevoid*in
InfContextINFCONTEXT*inoptional
SectionLPCSTRinoptional
ReturnBufferLPSTRoutoptional
ReturnBufferSizeDWORDin
RequiredSizeDWORD*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetupGetTargetPathA = ctypes.windll.setupapi.SetupGetTargetPathA
SetupGetTargetPathA.restype = wintypes.BOOL
SetupGetTargetPathA.argtypes = [
    ctypes.POINTER(None),  # InfHandle : void*
    ctypes.c_void_p,  # InfContext : INFCONTEXT* optional
    wintypes.LPCSTR,  # Section : LPCSTR optional
    wintypes.LPSTR,  # ReturnBuffer : LPSTR 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')
SetupGetTargetPathA = Fiddle::Function.new(
  lib['SetupGetTargetPathA'],
  [
    Fiddle::TYPE_VOIDP,  # InfHandle : void*
    Fiddle::TYPE_VOIDP,  # InfContext : INFCONTEXT* optional
    Fiddle::TYPE_VOIDP,  # Section : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # ReturnBuffer : LPSTR optional, out
    -Fiddle::TYPE_INT,  # ReturnBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # RequiredSize : DWORD* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupGetTargetPathA(
        InfHandle: *mut (),  // void*
        InfContext: *mut INFCONTEXT,  // INFCONTEXT* optional
        Section: *const u8,  // LPCSTR optional
        ReturnBuffer: *mut u8,  // LPSTR 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.Ansi, SetLastError = true)]
public static extern bool SetupGetTargetPathA(IntPtr InfHandle, IntPtr InfContext, [MarshalAs(UnmanagedType.LPStr)] string Section, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder ReturnBuffer, uint ReturnBufferSize, IntPtr RequiredSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetTargetPathA' -Namespace Win32 -PassThru
# $api::SetupGetTargetPathA(InfHandle, InfContext, Section, ReturnBuffer, ReturnBufferSize, RequiredSize)
#uselib "SETUPAPI.dll"
#func global SetupGetTargetPathA "SetupGetTargetPathA" sptr, sptr, sptr, sptr, sptr, sptr
; SetupGetTargetPathA InfHandle, varptr(InfContext), Section, varptr(ReturnBuffer), ReturnBufferSize, varptr(RequiredSize)   ; 戻り値は stat
; InfHandle : void* -> "sptr"
; InfContext : INFCONTEXT* optional -> "sptr"
; Section : LPCSTR optional -> "sptr"
; ReturnBuffer : LPSTR optional, out -> "sptr"
; ReturnBufferSize : DWORD -> "sptr"
; RequiredSize : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupGetTargetPathA "SetupGetTargetPathA" sptr, var, str, var, int, var
; res = SetupGetTargetPathA(InfHandle, InfContext, Section, ReturnBuffer, ReturnBufferSize, RequiredSize)
; InfHandle : void* -> "sptr"
; InfContext : INFCONTEXT* optional -> "var"
; Section : LPCSTR optional -> "str"
; ReturnBuffer : LPSTR optional, out -> "var"
; ReturnBufferSize : DWORD -> "int"
; RequiredSize : DWORD* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL SetupGetTargetPathA(void* InfHandle, INFCONTEXT* InfContext, LPCSTR Section, LPSTR ReturnBuffer, DWORD ReturnBufferSize, DWORD* RequiredSize)
#uselib "SETUPAPI.dll"
#cfunc global SetupGetTargetPathA "SetupGetTargetPathA" intptr, var, str, var, int, var
; res = SetupGetTargetPathA(InfHandle, InfContext, Section, ReturnBuffer, ReturnBufferSize, RequiredSize)
; InfHandle : void* -> "intptr"
; InfContext : INFCONTEXT* optional -> "var"
; Section : LPCSTR optional -> "str"
; ReturnBuffer : LPSTR 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")
	procSetupGetTargetPathA = setupapi.NewProc("SetupGetTargetPathA")
)

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