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対象の開いているINFハンドル。
InfContextINFCONTEXT*inoptional対象行を示すINFCONTEXT構造体へのポインタ。NULLでFileNameを使う。
FileNameLPCWSTRinoptionalサイズを求めるソースファイル名(Unicode)。InfContext指定時はNULL可。
SectionLPCWSTRinoptionalファイルが属するコピーセクション名(Unicode)。NULL可。
FileSizeDWORD*out求めたファイルサイズを受け取る出力ポインタ。
RoundingFactorDWORDinサイズを切り上げる丸め単位(バイト)。0で丸めなし。

戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 版の利用を推奨。
const std = @import("std");

extern "setupapi" fn SetupGetSourceFileSizeW(
    InfHandle: ?*anyopaque, // void*
    InfContext: [*c]INFCONTEXT, // INFCONTEXT* optional
    FileName: [*c]const u16, // LPCWSTR optional
    Section: [*c]const u16, // LPCWSTR optional
    FileSize: [*c]u32, // DWORD* out
    RoundingFactor: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc SetupGetSourceFileSizeW(
    InfHandle: pointer,  # void*
    InfContext: ptr INFCONTEXT,  # INFCONTEXT* optional
    FileName: WideCString,  # LPCWSTR optional
    Section: WideCString,  # LPCWSTR optional
    FileSize: ptr uint32,  # DWORD* out
    RoundingFactor: uint32  # DWORD
): int32 {.importc: "SetupGetSourceFileSizeW", stdcall, dynlib: "SETUPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "setupapi");
extern(Windows)
int SetupGetSourceFileSizeW(
    void* InfHandle,   // void*
    INFCONTEXT* InfContext,   // INFCONTEXT* optional
    const(wchar)* FileName,   // LPCWSTR optional
    const(wchar)* Section,   // LPCWSTR optional
    uint* FileSize,   // DWORD* out
    uint RoundingFactor   // DWORD
);
ccall((:SetupGetSourceFileSizeW, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{INFCONTEXT}, Cwstring, Cwstring, Ptr{UInt32}, UInt32),
      InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
# InfHandle : void* -> Ptr{Cvoid}
# InfContext : INFCONTEXT* optional -> Ptr{INFCONTEXT}
# FileName : LPCWSTR optional -> Cwstring
# Section : LPCWSTR optional -> Cwstring
# FileSize : DWORD* out -> Ptr{UInt32}
# RoundingFactor : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupGetSourceFileSizeW(
    void* InfHandle,
    void* InfContext,
    const uint16_t* FileName,
    const uint16_t* Section,
    uint32_t* FileSize,
    uint32_t RoundingFactor);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetSourceFileSizeW(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
-- InfHandle : void*
-- InfContext : INFCONTEXT* optional
-- FileName : LPCWSTR optional
-- Section : LPCWSTR optional
-- FileSize : DWORD* out
-- RoundingFactor : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetSourceFileSizeW = lib.func('__stdcall', 'SetupGetSourceFileSizeW', 'int32_t', ['void *', 'void *', 'str16', 'str16', 'uint32_t *', 'uint32_t']);
// SetupGetSourceFileSizeW(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
// InfHandle : void* -> 'void *'
// InfContext : INFCONTEXT* optional -> 'void *'
// FileName : LPCWSTR optional -> 'str16'
// Section : LPCWSTR optional -> 'str16'
// FileSize : DWORD* out -> 'uint32_t *'
// RoundingFactor : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupGetSourceFileSizeW: { parameters: ["pointer", "pointer", "buffer", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupGetSourceFileSizeW(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
// InfHandle : void* -> "pointer"
// InfContext : INFCONTEXT* optional -> "pointer"
// FileName : LPCWSTR optional -> "buffer"
// Section : LPCWSTR optional -> "buffer"
// FileSize : DWORD* out -> "pointer"
// RoundingFactor : DWORD -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupGetSourceFileSizeW(
    void* InfHandle,
    void* InfContext,
    const uint16_t* FileName,
    const uint16_t* Section,
    uint32_t* FileSize,
    uint32_t RoundingFactor);
C, "SETUPAPI.dll");
// $ffi->SetupGetSourceFileSizeW(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor);
// InfHandle : void*
// InfContext : INFCONTEXT* optional
// FileName : LPCWSTR optional
// Section : LPCWSTR optional
// FileSize : DWORD* out
// RoundingFactor : DWORD
// 構造体/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.UNICODE_OPTIONS);
    boolean SetupGetSourceFileSizeW(
        Pointer InfHandle,   // void*
        Pointer InfContext,   // INFCONTEXT* optional
        WString FileName,   // LPCWSTR optional
        WString Section,   // LPCWSTR optional
        IntByReference FileSize,   // DWORD* out
        int RoundingFactor   // DWORD
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupGetSourceFileSizeW = SetupGetSourceFileSizeW(
    InfHandle : Void*,   # void*
    InfContext : INFCONTEXT*,   # INFCONTEXT* optional
    FileName : UInt16*,   # LPCWSTR optional
    Section : UInt16*,   # LPCWSTR optional
    FileSize : UInt32*,   # DWORD* out
    RoundingFactor : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupGetSourceFileSizeWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, Uint32);
typedef SetupGetSourceFileSizeWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Pointer<Uint32>, int);
final SetupGetSourceFileSizeW = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupGetSourceFileSizeWNative, SetupGetSourceFileSizeWDart>('SetupGetSourceFileSizeW');
// InfHandle : void* -> Pointer<Void>
// InfContext : INFCONTEXT* optional -> Pointer<Void>
// FileName : LPCWSTR optional -> Pointer<Utf16>
// Section : LPCWSTR optional -> Pointer<Utf16>
// FileSize : DWORD* out -> Pointer<Uint32>
// RoundingFactor : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupGetSourceFileSizeW"
  c_SetupGetSourceFileSizeW :: Ptr () -> Ptr () -> CWString -> CWString -> Ptr Word32 -> Word32 -> IO CInt
-- InfHandle : void* -> Ptr ()
-- InfContext : INFCONTEXT* optional -> Ptr ()
-- FileName : LPCWSTR optional -> CWString
-- Section : LPCWSTR optional -> CWString
-- FileSize : DWORD* out -> Ptr Word32
-- RoundingFactor : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupgetsourcefilesizew =
  foreign "SetupGetSourceFileSizeW"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* InfContext : INFCONTEXT* optional -> (ptr void) *)
(* FileName : LPCWSTR optional -> (ptr uint16_t) *)
(* Section : LPCWSTR optional -> (ptr uint16_t) *)
(* FileSize : DWORD* out -> (ptr uint32_t) *)
(* RoundingFactor : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupGetSourceFileSizeW" setup-get-source-file-size-w :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (inf-context :pointer)   ; INFCONTEXT* optional
  (file-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (section (:string :encoding :utf-16le))   ; LPCWSTR optional
  (file-size :pointer)   ; DWORD* out
  (rounding-factor :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupGetSourceFileSizeW = Win32::API::More->new('SETUPAPI',
    'BOOL SetupGetSourceFileSizeW(LPVOID InfHandle, LPVOID InfContext, LPCWSTR FileName, LPCWSTR Section, LPVOID FileSize, DWORD RoundingFactor)');
# my $ret = $SetupGetSourceFileSizeW->Call($InfHandle, $InfContext, $FileName, $Section, $FileSize, $RoundingFactor);
# InfHandle : void* -> LPVOID
# InfContext : INFCONTEXT* optional -> LPVOID
# FileName : LPCWSTR optional -> LPCWSTR
# Section : LPCWSTR optional -> LPCWSTR
# FileSize : DWORD* out -> LPVOID
# RoundingFactor : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型