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

CreateCompressor

関数
指定アルゴリズムの圧縮器ハンドルを作成する。
DLLCabinet.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

BOOL CreateCompressor(
    COMPRESS_ALGORITHM Algorithm,
    COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines,   // optional
    COMPRESSOR_HANDLE* CompressorHandle
);

パラメーター

名前方向説明
AlgorithmCOMPRESS_ALGORITHMin使用する圧縮アルゴリズムを示すCOMPRESS_ALGORITHM列挙値。XPRESSやLZMS等を指定する。
AllocationRoutinesCOMPRESS_ALLOCATION_ROUTINES*inoptional独自メモリ割り当て関数を指定するCOMPRESS_ALLOCATION_ROUTINES構造体へのポインタ。既定ならNULL可。
CompressorHandleCOMPRESSOR_HANDLE*out作成した圧縮ハンドルを受け取るCOMPRESSOR_HANDLEへのポインタ。出力用。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL CreateCompressor(
    COMPRESS_ALGORITHM Algorithm,
    COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines,   // optional
    COMPRESSOR_HANDLE* CompressorHandle
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("Cabinet.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CreateCompressor(
    uint Algorithm,   // COMPRESS_ALGORITHM
    IntPtr AllocationRoutines,   // COMPRESS_ALLOCATION_ROUTINES* optional
    IntPtr CompressorHandle   // COMPRESSOR_HANDLE* out
);
<DllImport("Cabinet.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateCompressor(
    Algorithm As UInteger,   ' COMPRESS_ALGORITHM
    AllocationRoutines As IntPtr,   ' COMPRESS_ALLOCATION_ROUTINES* optional
    CompressorHandle As IntPtr   ' COMPRESSOR_HANDLE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' Algorithm : COMPRESS_ALGORITHM
' AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
' CompressorHandle : COMPRESSOR_HANDLE* out
Declare PtrSafe Function CreateCompressor Lib "cabinet" ( _
    ByVal Algorithm As Long, _
    ByVal AllocationRoutines As LongPtr, _
    ByVal CompressorHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateCompressor = ctypes.windll.cabinet.CreateCompressor
CreateCompressor.restype = wintypes.BOOL
CreateCompressor.argtypes = [
    wintypes.DWORD,  # Algorithm : COMPRESS_ALGORITHM
    ctypes.c_void_p,  # AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
    ctypes.c_void_p,  # CompressorHandle : COMPRESSOR_HANDLE* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('Cabinet.dll')
CreateCompressor = Fiddle::Function.new(
  lib['CreateCompressor'],
  [
    -Fiddle::TYPE_INT,  # Algorithm : COMPRESS_ALGORITHM
    Fiddle::TYPE_VOIDP,  # AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
    Fiddle::TYPE_VOIDP,  # CompressorHandle : COMPRESSOR_HANDLE* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "cabinet")]
extern "system" {
    fn CreateCompressor(
        Algorithm: u32,  // COMPRESS_ALGORITHM
        AllocationRoutines: *mut COMPRESS_ALLOCATION_ROUTINES,  // COMPRESS_ALLOCATION_ROUTINES* optional
        CompressorHandle: *mut *mut core::ffi::c_void  // COMPRESSOR_HANDLE* 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 CreateCompressor(uint Algorithm, IntPtr AllocationRoutines, IntPtr CompressorHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Cabinet_CreateCompressor' -Namespace Win32 -PassThru
# $api::CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
#uselib "Cabinet.dll"
#func global CreateCompressor "CreateCompressor" sptr, sptr, sptr
; CreateCompressor Algorithm, varptr(AllocationRoutines), CompressorHandle   ; 戻り値は stat
; Algorithm : COMPRESS_ALGORITHM -> "sptr"
; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "sptr"
; CompressorHandle : COMPRESSOR_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "Cabinet.dll"
#cfunc global CreateCompressor "CreateCompressor" int, var, sptr
; res = CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
; Algorithm : COMPRESS_ALGORITHM -> "int"
; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "var"
; CompressorHandle : COMPRESSOR_HANDLE* out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CreateCompressor(COMPRESS_ALGORITHM Algorithm, COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, COMPRESSOR_HANDLE* CompressorHandle)
#uselib "Cabinet.dll"
#cfunc global CreateCompressor "CreateCompressor" int, var, intptr
; res = CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
; Algorithm : COMPRESS_ALGORITHM -> "int"
; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "var"
; CompressorHandle : COMPRESSOR_HANDLE* out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	cabinet = windows.NewLazySystemDLL("Cabinet.dll")
	procCreateCompressor = cabinet.NewProc("CreateCompressor")
)

// Algorithm (COMPRESS_ALGORITHM), AllocationRoutines (COMPRESS_ALLOCATION_ROUTINES* optional), CompressorHandle (COMPRESSOR_HANDLE* out)
r1, _, err := procCreateCompressor.Call(
	uintptr(Algorithm),
	uintptr(AllocationRoutines),
	uintptr(CompressorHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CreateCompressor(
  Algorithm: DWORD;   // COMPRESS_ALGORITHM
  AllocationRoutines: Pointer;   // COMPRESS_ALLOCATION_ROUTINES* optional
  CompressorHandle: Pointer   // COMPRESSOR_HANDLE* out
): BOOL; stdcall;
  external 'Cabinet.dll' name 'CreateCompressor';
result := DllCall("Cabinet\CreateCompressor"
    , "UInt", Algorithm   ; COMPRESS_ALGORITHM
    , "Ptr", AllocationRoutines   ; COMPRESS_ALLOCATION_ROUTINES* optional
    , "Ptr", CompressorHandle   ; COMPRESSOR_HANDLE* out
    , "Int")   ; return: BOOL
●CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle) = DLL("Cabinet.dll", "bool CreateCompressor(dword, void*, void*)")
# 呼び出し: CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
# Algorithm : COMPRESS_ALGORITHM -> "dword"
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "void*"
# CompressorHandle : COMPRESSOR_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "cabinet" fn CreateCompressor(
    Algorithm: u32, // COMPRESS_ALGORITHM
    AllocationRoutines: [*c]COMPRESS_ALLOCATION_ROUTINES, // COMPRESS_ALLOCATION_ROUTINES* optional
    CompressorHandle: ?*anyopaque // COMPRESSOR_HANDLE* out
) callconv(std.os.windows.WINAPI) i32;
proc CreateCompressor(
    Algorithm: uint32,  # COMPRESS_ALGORITHM
    AllocationRoutines: ptr COMPRESS_ALLOCATION_ROUTINES,  # COMPRESS_ALLOCATION_ROUTINES* optional
    CompressorHandle: pointer  # COMPRESSOR_HANDLE* out
): int32 {.importc: "CreateCompressor", stdcall, dynlib: "Cabinet.dll".}
pragma(lib, "cabinet");
extern(Windows)
int CreateCompressor(
    uint Algorithm,   // COMPRESS_ALGORITHM
    COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines,   // COMPRESS_ALLOCATION_ROUTINES* optional
    void* CompressorHandle   // COMPRESSOR_HANDLE* out
);
ccall((:CreateCompressor, "Cabinet.dll"), stdcall, Int32,
      (UInt32, Ptr{COMPRESS_ALLOCATION_ROUTINES}, Ptr{Cvoid}),
      Algorithm, AllocationRoutines, CompressorHandle)
# Algorithm : COMPRESS_ALGORITHM -> UInt32
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Ptr{COMPRESS_ALLOCATION_ROUTINES}
# CompressorHandle : COMPRESSOR_HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t CreateCompressor(
    uint32_t Algorithm,
    void* AllocationRoutines,
    void* CompressorHandle);
]]
local cabinet = ffi.load("cabinet")
-- cabinet.CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
-- Algorithm : COMPRESS_ALGORITHM
-- AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
-- CompressorHandle : COMPRESSOR_HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('Cabinet.dll');
const CreateCompressor = lib.func('__stdcall', 'CreateCompressor', 'int32_t', ['uint32_t', 'void *', 'void *']);
// CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
// Algorithm : COMPRESS_ALGORITHM -> 'uint32_t'
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> 'void *'
// CompressorHandle : COMPRESSOR_HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("Cabinet.dll", {
  CreateCompressor: { parameters: ["u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle)
// Algorithm : COMPRESS_ALGORITHM -> "u32"
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "pointer"
// CompressorHandle : COMPRESSOR_HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CreateCompressor(
    uint32_t Algorithm,
    void* AllocationRoutines,
    void* CompressorHandle);
C, "Cabinet.dll");
// $ffi->CreateCompressor(Algorithm, AllocationRoutines, CompressorHandle);
// Algorithm : COMPRESS_ALGORITHM
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
// CompressorHandle : COMPRESSOR_HANDLE* 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 Cabinet extends StdCallLibrary {
    Cabinet INSTANCE = Native.load("cabinet", Cabinet.class);
    boolean CreateCompressor(
        int Algorithm,   // COMPRESS_ALGORITHM
        Pointer AllocationRoutines,   // COMPRESS_ALLOCATION_ROUTINES* optional
        Pointer CompressorHandle   // COMPRESSOR_HANDLE* out
    );
}
@[Link("cabinet")]
lib LibCabinet
  fun CreateCompressor = CreateCompressor(
    Algorithm : UInt32,   # COMPRESS_ALGORITHM
    AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES*,   # COMPRESS_ALLOCATION_ROUTINES* optional
    CompressorHandle : Void*   # COMPRESSOR_HANDLE* out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateCompressorNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Void>);
typedef CreateCompressorDart = int Function(int, Pointer<Void>, Pointer<Void>);
final CreateCompressor = DynamicLibrary.open('Cabinet.dll')
    .lookupFunction<CreateCompressorNative, CreateCompressorDart>('CreateCompressor');
// Algorithm : COMPRESS_ALGORITHM -> Uint32
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Pointer<Void>
// CompressorHandle : COMPRESSOR_HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateCompressor(
  Algorithm: DWORD;   // COMPRESS_ALGORITHM
  AllocationRoutines: Pointer;   // COMPRESS_ALLOCATION_ROUTINES* optional
  CompressorHandle: Pointer   // COMPRESSOR_HANDLE* out
): BOOL; stdcall;
  external 'Cabinet.dll' name 'CreateCompressor';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateCompressor"
  c_CreateCompressor :: Word32 -> Ptr () -> Ptr () -> IO CInt
-- Algorithm : COMPRESS_ALGORITHM -> Word32
-- AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Ptr ()
-- CompressorHandle : COMPRESSOR_HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createcompressor =
  foreign "CreateCompressor"
    (uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* Algorithm : COMPRESS_ALGORITHM -> uint32_t *)
(* AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> (ptr void) *)
(* CompressorHandle : COMPRESSOR_HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library cabinet (t "Cabinet.dll"))
(cffi:use-foreign-library cabinet)

(cffi:defcfun ("CreateCompressor" create-compressor :convention :stdcall) :int32
  (algorithm :uint32)   ; COMPRESS_ALGORITHM
  (allocation-routines :pointer)   ; COMPRESS_ALLOCATION_ROUTINES* optional
  (compressor-handle :pointer))   ; COMPRESSOR_HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateCompressor = Win32::API::More->new('Cabinet',
    'BOOL CreateCompressor(DWORD Algorithm, LPVOID AllocationRoutines, HANDLE CompressorHandle)');
# my $ret = $CreateCompressor->Call($Algorithm, $AllocationRoutines, $CompressorHandle);
# Algorithm : COMPRESS_ALGORITHM -> DWORD
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> LPVOID
# CompressorHandle : COMPRESSOR_HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型