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

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

extern "setupapi" fn SetupGetSourceFileSizeA(
    InfHandle: ?*anyopaque, // void*
    InfContext: [*c]INFCONTEXT, // INFCONTEXT* optional
    FileName: [*c]const u8, // LPCSTR optional
    Section: [*c]const u8, // LPCSTR optional
    FileSize: [*c]u32, // DWORD* out
    RoundingFactor: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc SetupGetSourceFileSizeA(
    InfHandle: pointer,  # void*
    InfContext: ptr INFCONTEXT,  # INFCONTEXT* optional
    FileName: cstring,  # LPCSTR optional
    Section: cstring,  # LPCSTR optional
    FileSize: ptr uint32,  # DWORD* out
    RoundingFactor: uint32  # DWORD
): int32 {.importc: "SetupGetSourceFileSizeA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
int SetupGetSourceFileSizeA(
    void* InfHandle,   // void*
    INFCONTEXT* InfContext,   // INFCONTEXT* optional
    const(char)* FileName,   // LPCSTR optional
    const(char)* Section,   // LPCSTR optional
    uint* FileSize,   // DWORD* out
    uint RoundingFactor   // DWORD
);
ccall((:SetupGetSourceFileSizeA, "SETUPAPI.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{INFCONTEXT}, Cstring, Cstring, Ptr{UInt32}, UInt32),
      InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
# InfHandle : void* -> Ptr{Cvoid}
# InfContext : INFCONTEXT* optional -> Ptr{INFCONTEXT}
# FileName : LPCSTR optional -> Cstring
# Section : LPCSTR optional -> Cstring
# FileSize : DWORD* out -> Ptr{UInt32}
# RoundingFactor : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetupGetSourceFileSizeA(
    void* InfHandle,
    void* InfContext,
    const char* FileName,
    const char* Section,
    uint32_t* FileSize,
    uint32_t RoundingFactor);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetSourceFileSizeA(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
-- InfHandle : void*
-- InfContext : INFCONTEXT* optional
-- FileName : LPCSTR optional
-- Section : LPCSTR optional
-- FileSize : DWORD* out
-- RoundingFactor : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetSourceFileSizeA = lib.func('__stdcall', 'SetupGetSourceFileSizeA', 'int32_t', ['void *', 'void *', 'str', 'str', 'uint32_t *', 'uint32_t']);
// SetupGetSourceFileSizeA(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
// InfHandle : void* -> 'void *'
// InfContext : INFCONTEXT* optional -> 'void *'
// FileName : LPCSTR optional -> 'str'
// Section : LPCSTR optional -> 'str'
// FileSize : DWORD* out -> 'uint32_t *'
// RoundingFactor : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupGetSourceFileSizeA: { parameters: ["pointer", "pointer", "buffer", "buffer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetupGetSourceFileSizeA(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor)
// InfHandle : void* -> "pointer"
// InfContext : INFCONTEXT* optional -> "pointer"
// FileName : LPCSTR optional -> "buffer"
// Section : LPCSTR optional -> "buffer"
// FileSize : DWORD* out -> "pointer"
// RoundingFactor : DWORD -> "u32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetupGetSourceFileSizeA(
    void* InfHandle,
    void* InfContext,
    const char* FileName,
    const char* Section,
    uint32_t* FileSize,
    uint32_t RoundingFactor);
C, "SETUPAPI.dll");
// $ffi->SetupGetSourceFileSizeA(InfHandle, InfContext, FileName, Section, FileSize, RoundingFactor);
// InfHandle : void*
// InfContext : INFCONTEXT* optional
// FileName : LPCSTR optional
// Section : LPCSTR 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.ASCII_OPTIONS);
    boolean SetupGetSourceFileSizeA(
        Pointer InfHandle,   // void*
        Pointer InfContext,   // INFCONTEXT* optional
        String FileName,   // LPCSTR optional
        String Section,   // LPCSTR optional
        IntByReference FileSize,   // DWORD* out
        int RoundingFactor   // DWORD
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupGetSourceFileSizeA = SetupGetSourceFileSizeA(
    InfHandle : Void*,   # void*
    InfContext : INFCONTEXT*,   # INFCONTEXT* optional
    FileName : UInt8*,   # LPCSTR optional
    Section : UInt8*,   # LPCSTR 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 SetupGetSourceFileSizeANative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>, Uint32);
typedef SetupGetSourceFileSizeADart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf8>, Pointer<Utf8>, Pointer<Uint32>, int);
final SetupGetSourceFileSizeA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupGetSourceFileSizeANative, SetupGetSourceFileSizeADart>('SetupGetSourceFileSizeA');
// InfHandle : void* -> Pointer<Void>
// InfContext : INFCONTEXT* optional -> Pointer<Void>
// FileName : LPCSTR optional -> Pointer<Utf8>
// Section : LPCSTR optional -> Pointer<Utf8>
// FileSize : DWORD* out -> Pointer<Uint32>
// RoundingFactor : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let setupgetsourcefilesizea =
  foreign "SetupGetSourceFileSizeA"
    ((ptr void) @-> (ptr void) @-> string @-> string @-> (ptr uint32_t) @-> uint32_t @-> returning int32_t)
(* InfHandle : void* -> (ptr void) *)
(* InfContext : INFCONTEXT* optional -> (ptr void) *)
(* FileName : LPCSTR optional -> string *)
(* Section : LPCSTR optional -> string *)
(* 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 ("SetupGetSourceFileSizeA" setup-get-source-file-size-a :convention :stdcall) :int32
  (inf-handle :pointer)   ; void*
  (inf-context :pointer)   ; INFCONTEXT* optional
  (file-name :string)   ; LPCSTR optional
  (section :string)   ; LPCSTR 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 $SetupGetSourceFileSizeA = Win32::API::More->new('SETUPAPI',
    'BOOL SetupGetSourceFileSizeA(LPVOID InfHandle, LPVOID InfContext, LPCSTR FileName, LPCSTR Section, LPVOID FileSize, DWORD RoundingFactor)');
# my $ret = $SetupGetSourceFileSizeA->Call($InfHandle, $InfContext, $FileName, $Section, $FileSize, $RoundingFactor);
# InfHandle : void* -> LPVOID
# InfContext : INFCONTEXT* optional -> LPVOID
# FileName : LPCSTR optional -> LPCSTR
# Section : LPCSTR optional -> LPCSTR
# FileSize : DWORD* out -> LPVOID
# RoundingFactor : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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