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

SetupGetSourceFileSizeW

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

シグネチャ

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

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

パラメーター

名前方向
InfHandlevoid*in
InfContextINFCONTEXT*inoptional
FileNameLPCWSTRinoptional
SectionLPCWSTRinoptional
FileSizeDWORD*out
RoundingFactorDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL SetupGetSourceFileSizeW(
    void* InfHandle,
    INFCONTEXT* InfContext,   // optional
    LPCWSTR FileName,   // optional
    LPCWSTR Section,   // optional
    DWORD* FileSize,
    DWORD RoundingFactor
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SETUPAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetupGetSourceFileSizeW(
    IntPtr InfHandle,   // void*
    IntPtr InfContext,   // INFCONTEXT* optional
    [MarshalAs(UnmanagedType.LPWStr)] string FileName,   // LPCWSTR optional
    [MarshalAs(UnmanagedType.LPWStr)] string Section,   // LPCWSTR optional
    out uint FileSize,   // DWORD* out
    uint RoundingFactor   // DWORD
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetSourceFileSizeW(
    InfHandle As IntPtr,   ' void*
    InfContext As IntPtr,   ' INFCONTEXT* optional
    <MarshalAs(UnmanagedType.LPWStr)> FileName As String,   ' LPCWSTR optional
    <MarshalAs(UnmanagedType.LPWStr)> Section As String,   ' LPCWSTR optional
    <Out> ByRef FileSize As UInteger,   ' DWORD* out
    RoundingFactor As UInteger   ' DWORD
) As Boolean
End Function
' InfHandle : void*
' InfContext : INFCONTEXT* optional
' FileName : LPCWSTR optional
' Section : LPCWSTR optional
' FileSize : DWORD* out
' RoundingFactor : DWORD
Declare PtrSafe Function SetupGetSourceFileSizeW Lib "setupapi" ( _
    ByVal InfHandle As LongPtr, _
    ByVal InfContext As LongPtr, _
    ByVal FileName As LongPtr, _
    ByVal Section As LongPtr, _
    ByRef FileSize As Long, _
    ByVal RoundingFactor As Long) 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

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

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupGetSourceFileSizeW = setupapi.NewProc("SetupGetSourceFileSizeW")
)

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