Win32 API 日本語リファレンス
ホームStorage.Compression › Compress

Compress

関数
圧縮器でデータを圧縮しバッファへ出力する。
DLLCabinet.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

// Cabinet.dll
#include <windows.h>

BOOL Compress(
    COMPRESSOR_HANDLE CompressorHandle,
    const void* UncompressedData,   // optional
    UINT_PTR UncompressedDataSize,
    void* CompressedBuffer,   // optional
    UINT_PTR CompressedBufferSize,
    UINT_PTR* CompressedDataSize
);

パラメーター

名前方向
CompressorHandleCOMPRESSOR_HANDLEin
UncompressedDatavoid*inoptional
UncompressedDataSizeUINT_PTRin
CompressedBuffervoid*outoptional
CompressedBufferSizeUINT_PTRin
CompressedDataSizeUINT_PTR*out

戻り値の型: BOOL

各言語での呼び出し定義

// Cabinet.dll
#include <windows.h>

BOOL Compress(
    COMPRESSOR_HANDLE CompressorHandle,
    const void* UncompressedData,   // optional
    UINT_PTR UncompressedDataSize,
    void* CompressedBuffer,   // optional
    UINT_PTR CompressedBufferSize,
    UINT_PTR* CompressedDataSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("Cabinet.dll", SetLastError = true, ExactSpelling = true)]
static extern bool Compress(
    IntPtr CompressorHandle,   // COMPRESSOR_HANDLE
    IntPtr UncompressedData,   // void* optional
    UIntPtr UncompressedDataSize,   // UINT_PTR
    IntPtr CompressedBuffer,   // void* optional, out
    UIntPtr CompressedBufferSize,   // UINT_PTR
    out UIntPtr CompressedDataSize   // UINT_PTR* out
);
<DllImport("Cabinet.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function Compress(
    CompressorHandle As IntPtr,   ' COMPRESSOR_HANDLE
    UncompressedData As IntPtr,   ' void* optional
    UncompressedDataSize As UIntPtr,   ' UINT_PTR
    CompressedBuffer As IntPtr,   ' void* optional, out
    CompressedBufferSize As UIntPtr,   ' UINT_PTR
    <Out> ByRef CompressedDataSize As UIntPtr   ' UINT_PTR* out
) As Boolean
End Function
' CompressorHandle : COMPRESSOR_HANDLE
' UncompressedData : void* optional
' UncompressedDataSize : UINT_PTR
' CompressedBuffer : void* optional, out
' CompressedBufferSize : UINT_PTR
' CompressedDataSize : UINT_PTR* out
Declare PtrSafe Function Compress Lib "cabinet" ( _
    ByVal CompressorHandle As LongPtr, _
    ByVal UncompressedData As LongPtr, _
    ByVal UncompressedDataSize As LongPtr, _
    ByVal CompressedBuffer As LongPtr, _
    ByVal CompressedBufferSize As LongPtr, _
    ByRef CompressedDataSize As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

Compress = ctypes.windll.cabinet.Compress
Compress.restype = wintypes.BOOL
Compress.argtypes = [
    wintypes.HANDLE,  # CompressorHandle : COMPRESSOR_HANDLE
    ctypes.POINTER(None),  # UncompressedData : void* optional
    ctypes.c_size_t,  # UncompressedDataSize : UINT_PTR
    ctypes.POINTER(None),  # CompressedBuffer : void* optional, out
    ctypes.c_size_t,  # CompressedBufferSize : UINT_PTR
    ctypes.POINTER(ctypes.c_size_t),  # CompressedDataSize : UINT_PTR* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('Cabinet.dll')
Compress = Fiddle::Function.new(
  lib['Compress'],
  [
    Fiddle::TYPE_VOIDP,  # CompressorHandle : COMPRESSOR_HANDLE
    Fiddle::TYPE_VOIDP,  # UncompressedData : void* optional
    Fiddle::TYPE_UINTPTR_T,  # UncompressedDataSize : UINT_PTR
    Fiddle::TYPE_VOIDP,  # CompressedBuffer : void* optional, out
    Fiddle::TYPE_UINTPTR_T,  # CompressedBufferSize : UINT_PTR
    Fiddle::TYPE_VOIDP,  # CompressedDataSize : UINT_PTR* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "cabinet")]
extern "system" {
    fn Compress(
        CompressorHandle: *mut core::ffi::c_void,  // COMPRESSOR_HANDLE
        UncompressedData: *const (),  // void* optional
        UncompressedDataSize: usize,  // UINT_PTR
        CompressedBuffer: *mut (),  // void* optional, out
        CompressedBufferSize: usize,  // UINT_PTR
        CompressedDataSize: *mut usize  // UINT_PTR* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("Cabinet.dll", SetLastError = true)]
public static extern bool Compress(IntPtr CompressorHandle, IntPtr UncompressedData, UIntPtr UncompressedDataSize, IntPtr CompressedBuffer, UIntPtr CompressedBufferSize, out UIntPtr CompressedDataSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Cabinet_Compress' -Namespace Win32 -PassThru
# $api::Compress(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize)
#uselib "Cabinet.dll"
#func global Compress "Compress" sptr, sptr, sptr, sptr, sptr, sptr
; Compress CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, varptr(CompressedDataSize)   ; 戻り値は stat
; CompressorHandle : COMPRESSOR_HANDLE -> "sptr"
; UncompressedData : void* optional -> "sptr"
; UncompressedDataSize : UINT_PTR -> "sptr"
; CompressedBuffer : void* optional, out -> "sptr"
; CompressedBufferSize : UINT_PTR -> "sptr"
; CompressedDataSize : UINT_PTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "Cabinet.dll"
#cfunc global Compress "Compress" sptr, sptr, sptr, sptr, sptr, var
; res = Compress(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize)
; CompressorHandle : COMPRESSOR_HANDLE -> "sptr"
; UncompressedData : void* optional -> "sptr"
; UncompressedDataSize : UINT_PTR -> "sptr"
; CompressedBuffer : void* optional, out -> "sptr"
; CompressedBufferSize : UINT_PTR -> "sptr"
; CompressedDataSize : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL Compress(COMPRESSOR_HANDLE CompressorHandle, void* UncompressedData, UINT_PTR UncompressedDataSize, void* CompressedBuffer, UINT_PTR CompressedBufferSize, UINT_PTR* CompressedDataSize)
#uselib "Cabinet.dll"
#cfunc global Compress "Compress" intptr, intptr, intptr, intptr, intptr, var
; res = Compress(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize)
; CompressorHandle : COMPRESSOR_HANDLE -> "intptr"
; UncompressedData : void* optional -> "intptr"
; UncompressedDataSize : UINT_PTR -> "intptr"
; CompressedBuffer : void* optional, out -> "intptr"
; CompressedBufferSize : UINT_PTR -> "intptr"
; CompressedDataSize : UINT_PTR* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cabinet = windows.NewLazySystemDLL("Cabinet.dll")
	procCompress = cabinet.NewProc("Compress")
)

// CompressorHandle (COMPRESSOR_HANDLE), UncompressedData (void* optional), UncompressedDataSize (UINT_PTR), CompressedBuffer (void* optional, out), CompressedBufferSize (UINT_PTR), CompressedDataSize (UINT_PTR* out)
r1, _, err := procCompress.Call(
	uintptr(CompressorHandle),
	uintptr(UncompressedData),
	uintptr(UncompressedDataSize),
	uintptr(CompressedBuffer),
	uintptr(CompressedBufferSize),
	uintptr(CompressedDataSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function Compress(
  CompressorHandle: THandle;   // COMPRESSOR_HANDLE
  UncompressedData: Pointer;   // void* optional
  UncompressedDataSize: NativeUInt;   // UINT_PTR
  CompressedBuffer: Pointer;   // void* optional, out
  CompressedBufferSize: NativeUInt;   // UINT_PTR
  CompressedDataSize: Pointer   // UINT_PTR* out
): BOOL; stdcall;
  external 'Cabinet.dll' name 'Compress';
result := DllCall("Cabinet\Compress"
    , "Ptr", CompressorHandle   ; COMPRESSOR_HANDLE
    , "Ptr", UncompressedData   ; void* optional
    , "UPtr", UncompressedDataSize   ; UINT_PTR
    , "Ptr", CompressedBuffer   ; void* optional, out
    , "UPtr", CompressedBufferSize   ; UINT_PTR
    , "Ptr", CompressedDataSize   ; UINT_PTR* out
    , "Int")   ; return: BOOL
●Compress(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize) = DLL("Cabinet.dll", "bool Compress(void*, void*, int, void*, int, void*)")
# 呼び出し: Compress(CompressorHandle, UncompressedData, UncompressedDataSize, CompressedBuffer, CompressedBufferSize, CompressedDataSize)
# CompressorHandle : COMPRESSOR_HANDLE -> "void*"
# UncompressedData : void* optional -> "void*"
# UncompressedDataSize : UINT_PTR -> "int"
# CompressedBuffer : void* optional, out -> "void*"
# CompressedBufferSize : UINT_PTR -> "int"
# CompressedDataSize : UINT_PTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。