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

SetupGetSourceFileSizeA

関数
INFに記載されたソースファイルのサイズを取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupGetSourceFileSizeA(
    void* InfHandle,
    INFCONTEXT* InfContext,   // optional
    LPCSTR FileName,   // optional
    LPCSTR Section,   // optional
    DWORD* FileSize,
    DWORD RoundingFactor
);

パラメーター

名前方向
InfHandlevoid*in
InfContextINFCONTEXT*inoptional
FileNameLPCSTRinoptional
SectionLPCSTRinoptional
FileSizeDWORD*out
RoundingFactorDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupGetSourceFileSizeA = setupapi.NewProc("SetupGetSourceFileSizeA")
)

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