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

SetupGetFileCompressionInfoA

関数
ソースファイルの圧縮形式やサイズ情報を取得する(ANSI)。
DLLSETUPAPI.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

DWORD SetupGetFileCompressionInfoA(
    LPCSTR SourceFileName,
    LPSTR* ActualSourceFileName,
    DWORD* SourceFileSize,
    DWORD* TargetFileSize,
    FILE_COMPRESSION_TYPE* CompressionType
);

パラメーター

名前方向説明
SourceFileNameLPCSTRin圧縮状態を調べる元ファイル名(ANSI)。
ActualSourceFileNameLPSTR*out実際に見つかったソースファイル名を受け取るポインタ。呼び出し側でLocalFree解放が必要。
SourceFileSizeDWORD*out圧縮された状態でのファイルサイズを受け取る出力ポインタ。
TargetFileSizeDWORD*out展開後のファイルサイズを受け取る出力ポインタ。
CompressionTypeFILE_COMPRESSION_TYPE*out検出された圧縮形式を受け取る出力ポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD SetupGetFileCompressionInfoA(
    LPCSTR SourceFileName,
    LPSTR* ActualSourceFileName,
    DWORD* SourceFileSize,
    DWORD* TargetFileSize,
    FILE_COMPRESSION_TYPE* CompressionType
);
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern uint SetupGetFileCompressionInfoA(
    [MarshalAs(UnmanagedType.LPStr)] string SourceFileName,   // LPCSTR
    IntPtr ActualSourceFileName,   // LPSTR* out
    out uint SourceFileSize,   // DWORD* out
    out uint TargetFileSize,   // DWORD* out
    out uint CompressionType   // FILE_COMPRESSION_TYPE* out
);
<DllImport("SETUPAPI.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetupGetFileCompressionInfoA(
    <MarshalAs(UnmanagedType.LPStr)> SourceFileName As String,   ' LPCSTR
    ActualSourceFileName As IntPtr,   ' LPSTR* out
    <Out> ByRef SourceFileSize As UInteger,   ' DWORD* out
    <Out> ByRef TargetFileSize As UInteger,   ' DWORD* out
    <Out> ByRef CompressionType As UInteger   ' FILE_COMPRESSION_TYPE* out
) As UInteger
End Function
' SourceFileName : LPCSTR
' ActualSourceFileName : LPSTR* out
' SourceFileSize : DWORD* out
' TargetFileSize : DWORD* out
' CompressionType : FILE_COMPRESSION_TYPE* out
Declare PtrSafe Function SetupGetFileCompressionInfoA Lib "setupapi" ( _
    ByVal SourceFileName As String, _
    ByVal ActualSourceFileName As LongPtr, _
    ByRef SourceFileSize As Long, _
    ByRef TargetFileSize As Long, _
    ByRef CompressionType As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetupGetFileCompressionInfoA = ctypes.windll.setupapi.SetupGetFileCompressionInfoA
SetupGetFileCompressionInfoA.restype = wintypes.DWORD
SetupGetFileCompressionInfoA.argtypes = [
    wintypes.LPCSTR,  # SourceFileName : LPCSTR
    ctypes.c_void_p,  # ActualSourceFileName : LPSTR* out
    ctypes.POINTER(wintypes.DWORD),  # SourceFileSize : DWORD* out
    ctypes.POINTER(wintypes.DWORD),  # TargetFileSize : DWORD* out
    ctypes.c_void_p,  # CompressionType : FILE_COMPRESSION_TYPE* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SETUPAPI.dll')
SetupGetFileCompressionInfoA = Fiddle::Function.new(
  lib['SetupGetFileCompressionInfoA'],
  [
    Fiddle::TYPE_VOIDP,  # SourceFileName : LPCSTR
    Fiddle::TYPE_VOIDP,  # ActualSourceFileName : LPSTR* out
    Fiddle::TYPE_VOIDP,  # SourceFileSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # TargetFileSize : DWORD* out
    Fiddle::TYPE_VOIDP,  # CompressionType : FILE_COMPRESSION_TYPE* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "setupapi")]
extern "system" {
    fn SetupGetFileCompressionInfoA(
        SourceFileName: *const u8,  // LPCSTR
        ActualSourceFileName: *mut *mut u8,  // LPSTR* out
        SourceFileSize: *mut u32,  // DWORD* out
        TargetFileSize: *mut u32,  // DWORD* out
        CompressionType: *mut u32  // FILE_COMPRESSION_TYPE* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("SETUPAPI.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern uint SetupGetFileCompressionInfoA([MarshalAs(UnmanagedType.LPStr)] string SourceFileName, IntPtr ActualSourceFileName, out uint SourceFileSize, out uint TargetFileSize, out uint CompressionType);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SETUPAPI_SetupGetFileCompressionInfoA' -Namespace Win32 -PassThru
# $api::SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
#uselib "SETUPAPI.dll"
#func global SetupGetFileCompressionInfoA "SetupGetFileCompressionInfoA" sptr, sptr, sptr, sptr, sptr
; SetupGetFileCompressionInfoA SourceFileName, varptr(ActualSourceFileName), varptr(SourceFileSize), varptr(TargetFileSize), varptr(CompressionType)   ; 戻り値は stat
; SourceFileName : LPCSTR -> "sptr"
; ActualSourceFileName : LPSTR* out -> "sptr"
; SourceFileSize : DWORD* out -> "sptr"
; TargetFileSize : DWORD* out -> "sptr"
; CompressionType : FILE_COMPRESSION_TYPE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "SETUPAPI.dll"
#cfunc global SetupGetFileCompressionInfoA "SetupGetFileCompressionInfoA" str, var, var, var, var
; res = SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
; SourceFileName : LPCSTR -> "str"
; ActualSourceFileName : LPSTR* out -> "var"
; SourceFileSize : DWORD* out -> "var"
; TargetFileSize : DWORD* out -> "var"
; CompressionType : FILE_COMPRESSION_TYPE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD SetupGetFileCompressionInfoA(LPCSTR SourceFileName, LPSTR* ActualSourceFileName, DWORD* SourceFileSize, DWORD* TargetFileSize, FILE_COMPRESSION_TYPE* CompressionType)
#uselib "SETUPAPI.dll"
#cfunc global SetupGetFileCompressionInfoA "SetupGetFileCompressionInfoA" str, var, var, var, var
; res = SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
; SourceFileName : LPCSTR -> "str"
; ActualSourceFileName : LPSTR* out -> "var"
; SourceFileSize : DWORD* out -> "var"
; TargetFileSize : DWORD* out -> "var"
; CompressionType : FILE_COMPRESSION_TYPE* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	setupapi = windows.NewLazySystemDLL("SETUPAPI.dll")
	procSetupGetFileCompressionInfoA = setupapi.NewProc("SetupGetFileCompressionInfoA")
)

// SourceFileName (LPCSTR), ActualSourceFileName (LPSTR* out), SourceFileSize (DWORD* out), TargetFileSize (DWORD* out), CompressionType (FILE_COMPRESSION_TYPE* out)
r1, _, err := procSetupGetFileCompressionInfoA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(SourceFileName))),
	uintptr(ActualSourceFileName),
	uintptr(SourceFileSize),
	uintptr(TargetFileSize),
	uintptr(CompressionType),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function SetupGetFileCompressionInfoA(
  SourceFileName: PAnsiChar;   // LPCSTR
  ActualSourceFileName: PPAnsiChar;   // LPSTR* out
  SourceFileSize: Pointer;   // DWORD* out
  TargetFileSize: Pointer;   // DWORD* out
  CompressionType: Pointer   // FILE_COMPRESSION_TYPE* out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupGetFileCompressionInfoA';
result := DllCall("SETUPAPI\SetupGetFileCompressionInfoA"
    , "AStr", SourceFileName   ; LPCSTR
    , "Ptr", ActualSourceFileName   ; LPSTR* out
    , "Ptr", SourceFileSize   ; DWORD* out
    , "Ptr", TargetFileSize   ; DWORD* out
    , "Ptr", CompressionType   ; FILE_COMPRESSION_TYPE* out
    , "UInt")   ; return: DWORD
●SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType) = DLL("SETUPAPI.dll", "dword SetupGetFileCompressionInfoA(char*, void*, void*, void*, void*)")
# 呼び出し: SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
# SourceFileName : LPCSTR -> "char*"
# ActualSourceFileName : LPSTR* out -> "void*"
# SourceFileSize : DWORD* out -> "void*"
# TargetFileSize : DWORD* out -> "void*"
# CompressionType : FILE_COMPRESSION_TYPE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "setupapi" fn SetupGetFileCompressionInfoA(
    SourceFileName: [*c]const u8, // LPCSTR
    ActualSourceFileName: [*c][*c]u8, // LPSTR* out
    SourceFileSize: [*c]u32, // DWORD* out
    TargetFileSize: [*c]u32, // DWORD* out
    CompressionType: [*c]u32 // FILE_COMPRESSION_TYPE* out
) callconv(std.os.windows.WINAPI) u32;
proc SetupGetFileCompressionInfoA(
    SourceFileName: cstring,  # LPCSTR
    ActualSourceFileName: ptr cstring,  # LPSTR* out
    SourceFileSize: ptr uint32,  # DWORD* out
    TargetFileSize: ptr uint32,  # DWORD* out
    CompressionType: ptr uint32  # FILE_COMPRESSION_TYPE* out
): uint32 {.importc: "SetupGetFileCompressionInfoA", stdcall, dynlib: "SETUPAPI.dll".}
pragma(lib, "setupapi");
extern(Windows)
uint SetupGetFileCompressionInfoA(
    const(char)* SourceFileName,   // LPCSTR
    char** ActualSourceFileName,   // LPSTR* out
    uint* SourceFileSize,   // DWORD* out
    uint* TargetFileSize,   // DWORD* out
    uint* CompressionType   // FILE_COMPRESSION_TYPE* out
);
ccall((:SetupGetFileCompressionInfoA, "SETUPAPI.dll"), stdcall, UInt32,
      (Cstring, Ptr{Ptr{UInt8}}, Ptr{UInt32}, Ptr{UInt32}, Ptr{UInt32}),
      SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
# SourceFileName : LPCSTR -> Cstring
# ActualSourceFileName : LPSTR* out -> Ptr{Ptr{UInt8}}
# SourceFileSize : DWORD* out -> Ptr{UInt32}
# TargetFileSize : DWORD* out -> Ptr{UInt32}
# CompressionType : FILE_COMPRESSION_TYPE* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t SetupGetFileCompressionInfoA(
    const char* SourceFileName,
    char** ActualSourceFileName,
    uint32_t* SourceFileSize,
    uint32_t* TargetFileSize,
    uint32_t* CompressionType);
]]
local setupapi = ffi.load("setupapi")
-- setupapi.SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
-- SourceFileName : LPCSTR
-- ActualSourceFileName : LPSTR* out
-- SourceFileSize : DWORD* out
-- TargetFileSize : DWORD* out
-- CompressionType : FILE_COMPRESSION_TYPE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('SETUPAPI.dll');
const SetupGetFileCompressionInfoA = lib.func('__stdcall', 'SetupGetFileCompressionInfoA', 'uint32_t', ['str', 'void *', 'uint32_t *', 'uint32_t *', 'uint32_t *']);
// SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
// SourceFileName : LPCSTR -> 'str'
// ActualSourceFileName : LPSTR* out -> 'void *'
// SourceFileSize : DWORD* out -> 'uint32_t *'
// TargetFileSize : DWORD* out -> 'uint32_t *'
// CompressionType : FILE_COMPRESSION_TYPE* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("SETUPAPI.dll", {
  SetupGetFileCompressionInfoA: { parameters: ["buffer", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType)
// SourceFileName : LPCSTR -> "buffer"
// ActualSourceFileName : LPSTR* out -> "pointer"
// SourceFileSize : DWORD* out -> "pointer"
// TargetFileSize : DWORD* out -> "pointer"
// CompressionType : FILE_COMPRESSION_TYPE* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t SetupGetFileCompressionInfoA(
    const char* SourceFileName,
    char** ActualSourceFileName,
    uint32_t* SourceFileSize,
    uint32_t* TargetFileSize,
    uint32_t* CompressionType);
C, "SETUPAPI.dll");
// $ffi->SetupGetFileCompressionInfoA(SourceFileName, ActualSourceFileName, SourceFileSize, TargetFileSize, CompressionType);
// SourceFileName : LPCSTR
// ActualSourceFileName : LPSTR* out
// SourceFileSize : DWORD* out
// TargetFileSize : DWORD* out
// CompressionType : FILE_COMPRESSION_TYPE* out
// 構造体/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);
    int SetupGetFileCompressionInfoA(
        String SourceFileName,   // LPCSTR
        PointerByReference ActualSourceFileName,   // LPSTR* out
        IntByReference SourceFileSize,   // DWORD* out
        IntByReference TargetFileSize,   // DWORD* out
        IntByReference CompressionType   // FILE_COMPRESSION_TYPE* out
    );
}
@[Link("setupapi")]
lib LibSETUPAPI
  fun SetupGetFileCompressionInfoA = SetupGetFileCompressionInfoA(
    SourceFileName : UInt8*,   # LPCSTR
    ActualSourceFileName : UInt8**,   # LPSTR* out
    SourceFileSize : UInt32*,   # DWORD* out
    TargetFileSize : UInt32*,   # DWORD* out
    CompressionType : UInt32*   # FILE_COMPRESSION_TYPE* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetupGetFileCompressionInfoANative = Uint32 Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Uint32>);
typedef SetupGetFileCompressionInfoADart = int Function(Pointer<Utf8>, Pointer<Pointer<Utf8>>, Pointer<Uint32>, Pointer<Uint32>, Pointer<Uint32>);
final SetupGetFileCompressionInfoA = DynamicLibrary.open('SETUPAPI.dll')
    .lookupFunction<SetupGetFileCompressionInfoANative, SetupGetFileCompressionInfoADart>('SetupGetFileCompressionInfoA');
// SourceFileName : LPCSTR -> Pointer<Utf8>
// ActualSourceFileName : LPSTR* out -> Pointer<Pointer<Utf8>>
// SourceFileSize : DWORD* out -> Pointer<Uint32>
// TargetFileSize : DWORD* out -> Pointer<Uint32>
// CompressionType : FILE_COMPRESSION_TYPE* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetupGetFileCompressionInfoA(
  SourceFileName: PAnsiChar;   // LPCSTR
  ActualSourceFileName: PPAnsiChar;   // LPSTR* out
  SourceFileSize: Pointer;   // DWORD* out
  TargetFileSize: Pointer;   // DWORD* out
  CompressionType: Pointer   // FILE_COMPRESSION_TYPE* out
): DWORD; stdcall;
  external 'SETUPAPI.dll' name 'SetupGetFileCompressionInfoA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetupGetFileCompressionInfoA"
  c_SetupGetFileCompressionInfoA :: CString -> Ptr CString -> Ptr Word32 -> Ptr Word32 -> Ptr Word32 -> IO Word32
-- SourceFileName : LPCSTR -> CString
-- ActualSourceFileName : LPSTR* out -> Ptr CString
-- SourceFileSize : DWORD* out -> Ptr Word32
-- TargetFileSize : DWORD* out -> Ptr Word32
-- CompressionType : FILE_COMPRESSION_TYPE* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let setupgetfilecompressioninfoa =
  foreign "SetupGetFileCompressionInfoA"
    (string @-> (ptr string) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> (ptr uint32_t) @-> returning uint32_t)
(* SourceFileName : LPCSTR -> string *)
(* ActualSourceFileName : LPSTR* out -> (ptr string) *)
(* SourceFileSize : DWORD* out -> (ptr uint32_t) *)
(* TargetFileSize : DWORD* out -> (ptr uint32_t) *)
(* CompressionType : FILE_COMPRESSION_TYPE* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library setupapi (t "SETUPAPI.dll"))
(cffi:use-foreign-library setupapi)

(cffi:defcfun ("SetupGetFileCompressionInfoA" setup-get-file-compression-info-a :convention :stdcall) :uint32
  (source-file-name :string)   ; LPCSTR
  (actual-source-file-name :pointer)   ; LPSTR* out
  (source-file-size :pointer)   ; DWORD* out
  (target-file-size :pointer)   ; DWORD* out
  (compression-type :pointer))   ; FILE_COMPRESSION_TYPE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetupGetFileCompressionInfoA = Win32::API::More->new('SETUPAPI',
    'DWORD SetupGetFileCompressionInfoA(LPCSTR SourceFileName, LPVOID ActualSourceFileName, LPVOID SourceFileSize, LPVOID TargetFileSize, LPVOID CompressionType)');
# my $ret = $SetupGetFileCompressionInfoA->Call($SourceFileName, $ActualSourceFileName, $SourceFileSize, $TargetFileSize, $CompressionType);
# SourceFileName : LPCSTR -> LPCSTR
# ActualSourceFileName : LPSTR* out -> LPVOID
# SourceFileSize : DWORD* out -> LPVOID
# TargetFileSize : DWORD* out -> LPVOID
# CompressionType : FILE_COMPRESSION_TYPE* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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