ホーム › Storage.Compression › CreateDecompressor
CreateDecompressor
関数指定アルゴリズムの展開器ハンドルを作成する。
シグネチャ
// Cabinet.dll
#include <windows.h>
BOOL CreateDecompressor(
COMPRESS_ALGORITHM Algorithm,
COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, // optional
DECOMPRESSOR_HANDLE* DecompressorHandle
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Algorithm | COMPRESS_ALGORITHM | in | 使用する展開アルゴリズムを示すCOMPRESS_ALGORITHM列挙値。圧縮時と同じ方式を指定する。 |
| AllocationRoutines | COMPRESS_ALLOCATION_ROUTINES* | inoptional | 独自メモリ割り当て関数を指定するCOMPRESS_ALLOCATION_ROUTINES構造体へのポインタ。既定ならNULL可。 |
| DecompressorHandle | DECOMPRESSOR_HANDLE* | out | 作成した展開ハンドルを受け取るDECOMPRESSOR_HANDLEへのポインタ。出力用。 |
戻り値の型: BOOL
各言語での呼び出し定義
// Cabinet.dll
#include <windows.h>
BOOL CreateDecompressor(
COMPRESS_ALGORITHM Algorithm,
COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, // optional
DECOMPRESSOR_HANDLE* DecompressorHandle
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("Cabinet.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CreateDecompressor(
uint Algorithm, // COMPRESS_ALGORITHM
IntPtr AllocationRoutines, // COMPRESS_ALLOCATION_ROUTINES* optional
IntPtr DecompressorHandle // DECOMPRESSOR_HANDLE* out
);<DllImport("Cabinet.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateDecompressor(
Algorithm As UInteger, ' COMPRESS_ALGORITHM
AllocationRoutines As IntPtr, ' COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle As IntPtr ' DECOMPRESSOR_HANDLE* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' Algorithm : COMPRESS_ALGORITHM
' AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
' DecompressorHandle : DECOMPRESSOR_HANDLE* out
Declare PtrSafe Function CreateDecompressor Lib "cabinet" ( _
ByVal Algorithm As Long, _
ByVal AllocationRoutines As LongPtr, _
ByVal DecompressorHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateDecompressor = ctypes.windll.cabinet.CreateDecompressor
CreateDecompressor.restype = wintypes.BOOL
CreateDecompressor.argtypes = [
wintypes.DWORD, # Algorithm : COMPRESS_ALGORITHM
ctypes.c_void_p, # AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
ctypes.c_void_p, # DecompressorHandle : DECOMPRESSOR_HANDLE* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('Cabinet.dll')
CreateDecompressor = Fiddle::Function.new(
lib['CreateDecompressor'],
[
-Fiddle::TYPE_INT, # Algorithm : COMPRESS_ALGORITHM
Fiddle::TYPE_VOIDP, # AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
Fiddle::TYPE_VOIDP, # DecompressorHandle : DECOMPRESSOR_HANDLE* out
],
Fiddle::TYPE_INT)#[link(name = "cabinet")]
extern "system" {
fn CreateDecompressor(
Algorithm: u32, // COMPRESS_ALGORITHM
AllocationRoutines: *mut COMPRESS_ALLOCATION_ROUTINES, // COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle: *mut *mut core::ffi::c_void // DECOMPRESSOR_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 CreateDecompressor(uint Algorithm, IntPtr AllocationRoutines, IntPtr DecompressorHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'Cabinet_CreateDecompressor' -Namespace Win32 -PassThru
# $api::CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle)#uselib "Cabinet.dll"
#func global CreateDecompressor "CreateDecompressor" sptr, sptr, sptr
; CreateDecompressor Algorithm, varptr(AllocationRoutines), DecompressorHandle ; 戻り値は stat
; Algorithm : COMPRESS_ALGORITHM -> "sptr"
; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "sptr"
; DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "Cabinet.dll" #cfunc global CreateDecompressor "CreateDecompressor" int, var, sptr ; res = CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle) ; Algorithm : COMPRESS_ALGORITHM -> "int" ; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "var" ; DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "Cabinet.dll" #cfunc global CreateDecompressor "CreateDecompressor" int, sptr, sptr ; res = CreateDecompressor(Algorithm, varptr(AllocationRoutines), DecompressorHandle) ; Algorithm : COMPRESS_ALGORITHM -> "int" ; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "sptr" ; DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL CreateDecompressor(COMPRESS_ALGORITHM Algorithm, COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, DECOMPRESSOR_HANDLE* DecompressorHandle) #uselib "Cabinet.dll" #cfunc global CreateDecompressor "CreateDecompressor" int, var, intptr ; res = CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle) ; Algorithm : COMPRESS_ALGORITHM -> "int" ; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "var" ; DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL CreateDecompressor(COMPRESS_ALGORITHM Algorithm, COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, DECOMPRESSOR_HANDLE* DecompressorHandle) #uselib "Cabinet.dll" #cfunc global CreateDecompressor "CreateDecompressor" int, intptr, intptr ; res = CreateDecompressor(Algorithm, varptr(AllocationRoutines), DecompressorHandle) ; Algorithm : COMPRESS_ALGORITHM -> "int" ; AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "intptr" ; DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
cabinet = windows.NewLazySystemDLL("Cabinet.dll")
procCreateDecompressor = cabinet.NewProc("CreateDecompressor")
)
// Algorithm (COMPRESS_ALGORITHM), AllocationRoutines (COMPRESS_ALLOCATION_ROUTINES* optional), DecompressorHandle (DECOMPRESSOR_HANDLE* out)
r1, _, err := procCreateDecompressor.Call(
uintptr(Algorithm),
uintptr(AllocationRoutines),
uintptr(DecompressorHandle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CreateDecompressor(
Algorithm: DWORD; // COMPRESS_ALGORITHM
AllocationRoutines: Pointer; // COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle: Pointer // DECOMPRESSOR_HANDLE* out
): BOOL; stdcall;
external 'Cabinet.dll' name 'CreateDecompressor';result := DllCall("Cabinet\CreateDecompressor"
, "UInt", Algorithm ; COMPRESS_ALGORITHM
, "Ptr", AllocationRoutines ; COMPRESS_ALLOCATION_ROUTINES* optional
, "Ptr", DecompressorHandle ; DECOMPRESSOR_HANDLE* out
, "Int") ; return: BOOL●CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle) = DLL("Cabinet.dll", "bool CreateDecompressor(dword, void*, void*)")
# 呼び出し: CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle)
# Algorithm : COMPRESS_ALGORITHM -> "dword"
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "void*"
# DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "cabinet" fn CreateDecompressor(
Algorithm: u32, // COMPRESS_ALGORITHM
AllocationRoutines: [*c]COMPRESS_ALLOCATION_ROUTINES, // COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle: ?*anyopaque // DECOMPRESSOR_HANDLE* out
) callconv(std.os.windows.WINAPI) i32;proc CreateDecompressor(
Algorithm: uint32, # COMPRESS_ALGORITHM
AllocationRoutines: ptr COMPRESS_ALLOCATION_ROUTINES, # COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle: pointer # DECOMPRESSOR_HANDLE* out
): int32 {.importc: "CreateDecompressor", stdcall, dynlib: "Cabinet.dll".}pragma(lib, "cabinet");
extern(Windows)
int CreateDecompressor(
uint Algorithm, // COMPRESS_ALGORITHM
COMPRESS_ALLOCATION_ROUTINES* AllocationRoutines, // COMPRESS_ALLOCATION_ROUTINES* optional
void* DecompressorHandle // DECOMPRESSOR_HANDLE* out
);ccall((:CreateDecompressor, "Cabinet.dll"), stdcall, Int32,
(UInt32, Ptr{COMPRESS_ALLOCATION_ROUTINES}, Ptr{Cvoid}),
Algorithm, AllocationRoutines, DecompressorHandle)
# Algorithm : COMPRESS_ALGORITHM -> UInt32
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Ptr{COMPRESS_ALLOCATION_ROUTINES}
# DecompressorHandle : DECOMPRESSOR_HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CreateDecompressor(
uint32_t Algorithm,
void* AllocationRoutines,
void* DecompressorHandle);
]]
local cabinet = ffi.load("cabinet")
-- cabinet.CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle)
-- Algorithm : COMPRESS_ALGORITHM
-- AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
-- DecompressorHandle : DECOMPRESSOR_HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('Cabinet.dll');
const CreateDecompressor = lib.func('__stdcall', 'CreateDecompressor', 'int32_t', ['uint32_t', 'void *', 'void *']);
// CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle)
// Algorithm : COMPRESS_ALGORITHM -> 'uint32_t'
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> 'void *'
// DecompressorHandle : DECOMPRESSOR_HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("Cabinet.dll", {
CreateDecompressor: { parameters: ["u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle)
// Algorithm : COMPRESS_ALGORITHM -> "u32"
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> "pointer"
// DecompressorHandle : DECOMPRESSOR_HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CreateDecompressor(
uint32_t Algorithm,
void* AllocationRoutines,
void* DecompressorHandle);
C, "Cabinet.dll");
// $ffi->CreateDecompressor(Algorithm, AllocationRoutines, DecompressorHandle);
// Algorithm : COMPRESS_ALGORITHM
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional
// DecompressorHandle : DECOMPRESSOR_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 CreateDecompressor(
int Algorithm, // COMPRESS_ALGORITHM
Pointer AllocationRoutines, // COMPRESS_ALLOCATION_ROUTINES* optional
Pointer DecompressorHandle // DECOMPRESSOR_HANDLE* out
);
}@[Link("cabinet")]
lib LibCabinet
fun CreateDecompressor = CreateDecompressor(
Algorithm : UInt32, # COMPRESS_ALGORITHM
AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES*, # COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle : Void* # DECOMPRESSOR_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 CreateDecompressorNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Void>);
typedef CreateDecompressorDart = int Function(int, Pointer<Void>, Pointer<Void>);
final CreateDecompressor = DynamicLibrary.open('Cabinet.dll')
.lookupFunction<CreateDecompressorNative, CreateDecompressorDart>('CreateDecompressor');
// Algorithm : COMPRESS_ALGORITHM -> Uint32
// AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Pointer<Void>
// DecompressorHandle : DECOMPRESSOR_HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CreateDecompressor(
Algorithm: DWORD; // COMPRESS_ALGORITHM
AllocationRoutines: Pointer; // COMPRESS_ALLOCATION_ROUTINES* optional
DecompressorHandle: Pointer // DECOMPRESSOR_HANDLE* out
): BOOL; stdcall;
external 'Cabinet.dll' name 'CreateDecompressor';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateDecompressor"
c_CreateDecompressor :: Word32 -> Ptr () -> Ptr () -> IO CInt
-- Algorithm : COMPRESS_ALGORITHM -> Word32
-- AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> Ptr ()
-- DecompressorHandle : DECOMPRESSOR_HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createdecompressor =
foreign "CreateDecompressor"
(uint32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* Algorithm : COMPRESS_ALGORITHM -> uint32_t *)
(* AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> (ptr void) *)
(* DecompressorHandle : DECOMPRESSOR_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 ("CreateDecompressor" create-decompressor :convention :stdcall) :int32
(algorithm :uint32) ; COMPRESS_ALGORITHM
(allocation-routines :pointer) ; COMPRESS_ALLOCATION_ROUTINES* optional
(decompressor-handle :pointer)) ; DECOMPRESSOR_HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateDecompressor = Win32::API::More->new('Cabinet',
'BOOL CreateDecompressor(DWORD Algorithm, LPVOID AllocationRoutines, HANDLE DecompressorHandle)');
# my $ret = $CreateDecompressor->Call($Algorithm, $AllocationRoutines, $DecompressorHandle);
# Algorithm : COMPRESS_ALGORITHM -> DWORD
# AllocationRoutines : COMPRESS_ALLOCATION_ROUTINES* optional -> LPVOID
# DecompressorHandle : DECOMPRESSOR_HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。