CreateLogMarshallingArea
関数シグネチャ
// clfsw32.dll
#include <windows.h>
BOOL CreateLogMarshallingArea(
HANDLE hLog,
CLFS_BLOCK_ALLOCATION pfnAllocBuffer,
CLFS_BLOCK_DEALLOCATION pfnFreeBuffer,
void* pvBlockAllocContext,
DWORD cbMarshallingBuffer,
DWORD cMaxWriteBuffers,
DWORD cMaxReadBuffers,
void** ppvMarshal
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hLog | HANDLE | in | CreateLogFile から取得したログへのハンドル。 このログハンドルは、専用ログまたは多重化ログのいずれかを参照できます。 |
| pfnAllocBuffer | CLFS_BLOCK_ALLOCATION | in | ログブロック用のメモリを割り当てるコールバック関数。 このパラメーターが NULL の場合、Common Log File System (CLFS) は既定のブロック割り当て関数を提供します。pfnFreeBuffer パラメーターでブロック解放コールバックを指定する場合、このパラメーターを NULL にすることはできません。 次の例は、ブロック割り当てコールバック関数の構文を示しています。
|
| pfnFreeBuffer | CLFS_BLOCK_DEALLOCATION | in | pfnAllocBuffer によって割り当てられたログブロックを解放するコールバック関数。 このパラメーターが NULL の場合、CLFS は既定のブロック解放関数を提供します。pfnAllocBuffer パラメーターでブロック割り当てコールバックを指定する場合、このパラメーターを NULL にすることはできません。 次の例は、ブロック解放コールバック関数の構文を示しています。
"ClfsBlockDeallocProc" の buffer パラメーターは、pfnAllocBuffer が指すコールバックを使用して割り当てられたブロックを指している必要があります。 |
| pvBlockAllocContext | void* | inout | バッファーが指定されている場合に、ブロックの割り当てルーチンと解放ルーチンへユーザーコンテキストとして渡されるバッファーへのポインター。 pfnAllocBuffer が NULL の場合、このパラメーターは無視されます。 |
| cbMarshallingBuffer | DWORD | in | 新しいマーシャリング領域で使用される個々のログ I/O ブロックのサイズ (バイト単位)。これは安定記憶媒体上のセクターサイズの倍数でなければなりません。セクターサイズは、GetDiskFreeSpace 関数の lpBytesPerSector パラメーターで返される値です。 レコードがこの値より長い場合、追加または読み取りはできません。 |
| cMaxWriteBuffers | DWORD | in | 書き込み操作のために任意の時点で割り当て可能なブロックの最大数。 この値はデータフラッシュの頻度に影響を与える可能性があります。データフラッシュサイクルの頻度を制御する制限を指定する必要がない場合は、INFINITE を指定します。 |
| cMaxReadBuffers | DWORD | in | 読み取り操作のために任意の時点で割り当て可能なブロックの最大数。 読み取りコンテキストは少なくとも 1 つの読み取りブロックを使用します。 |
| ppvMarshal | void** | inout | CreateLogMarshallingArea が正常に完了したときに CLFS が割り当てるマーシャリングコンテキストへのポインター。 このコンテキストは、ログマーシャリング領域に対するすべての読み取り、追加、書き込み、フラッシュの操作で使用する必要があります。マーシャリングコンテキストを使用してマーシャリング領域にアクセスするすべての操作はスレッドセーフです。操作が成功しなかった場合、このパラメーターは NULL になります。 |
戻り値の型: BOOL
公式ドキュメント
ログのマーシャリング領域を作成し、成功した場合はマーシャリングコンテキストを返します。マーシャリング領域を作成する前に、ログには少なくとも 1 つのコンテナーが必要です。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。
次の一覧は、考えられるエラーコードを示しています。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// clfsw32.dll
#include <windows.h>
BOOL CreateLogMarshallingArea(
HANDLE hLog,
CLFS_BLOCK_ALLOCATION pfnAllocBuffer,
CLFS_BLOCK_DEALLOCATION pfnFreeBuffer,
void* pvBlockAllocContext,
DWORD cbMarshallingBuffer,
DWORD cMaxWriteBuffers,
DWORD cMaxReadBuffers,
void** ppvMarshal
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("clfsw32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool CreateLogMarshallingArea(
IntPtr hLog, // HANDLE
IntPtr pfnAllocBuffer, // CLFS_BLOCK_ALLOCATION
IntPtr pfnFreeBuffer, // CLFS_BLOCK_DEALLOCATION
IntPtr pvBlockAllocContext, // void* in/out
uint cbMarshallingBuffer, // DWORD
uint cMaxWriteBuffers, // DWORD
uint cMaxReadBuffers, // DWORD
IntPtr ppvMarshal // void** in/out
);<DllImport("clfsw32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateLogMarshallingArea(
hLog As IntPtr, ' HANDLE
pfnAllocBuffer As IntPtr, ' CLFS_BLOCK_ALLOCATION
pfnFreeBuffer As IntPtr, ' CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext As IntPtr, ' void* in/out
cbMarshallingBuffer As UInteger, ' DWORD
cMaxWriteBuffers As UInteger, ' DWORD
cMaxReadBuffers As UInteger, ' DWORD
ppvMarshal As IntPtr ' void** in/out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hLog : HANDLE
' pfnAllocBuffer : CLFS_BLOCK_ALLOCATION
' pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION
' pvBlockAllocContext : void* in/out
' cbMarshallingBuffer : DWORD
' cMaxWriteBuffers : DWORD
' cMaxReadBuffers : DWORD
' ppvMarshal : void** in/out
Declare PtrSafe Function CreateLogMarshallingArea Lib "clfsw32" ( _
ByVal hLog As LongPtr, _
ByVal pfnAllocBuffer As LongPtr, _
ByVal pfnFreeBuffer As LongPtr, _
ByVal pvBlockAllocContext As LongPtr, _
ByVal cbMarshallingBuffer As Long, _
ByVal cMaxWriteBuffers As Long, _
ByVal cMaxReadBuffers As Long, _
ByVal ppvMarshal As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateLogMarshallingArea = ctypes.windll.clfsw32.CreateLogMarshallingArea
CreateLogMarshallingArea.restype = wintypes.BOOL
CreateLogMarshallingArea.argtypes = [
wintypes.HANDLE, # hLog : HANDLE
ctypes.c_void_p, # pfnAllocBuffer : CLFS_BLOCK_ALLOCATION
ctypes.c_void_p, # pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION
ctypes.POINTER(None), # pvBlockAllocContext : void* in/out
wintypes.DWORD, # cbMarshallingBuffer : DWORD
wintypes.DWORD, # cMaxWriteBuffers : DWORD
wintypes.DWORD, # cMaxReadBuffers : DWORD
ctypes.c_void_p, # ppvMarshal : void** in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('clfsw32.dll')
CreateLogMarshallingArea = Fiddle::Function.new(
lib['CreateLogMarshallingArea'],
[
Fiddle::TYPE_VOIDP, # hLog : HANDLE
Fiddle::TYPE_VOIDP, # pfnAllocBuffer : CLFS_BLOCK_ALLOCATION
Fiddle::TYPE_VOIDP, # pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION
Fiddle::TYPE_VOIDP, # pvBlockAllocContext : void* in/out
-Fiddle::TYPE_INT, # cbMarshallingBuffer : DWORD
-Fiddle::TYPE_INT, # cMaxWriteBuffers : DWORD
-Fiddle::TYPE_INT, # cMaxReadBuffers : DWORD
Fiddle::TYPE_VOIDP, # ppvMarshal : void** in/out
],
Fiddle::TYPE_INT)#[link(name = "clfsw32")]
extern "system" {
fn CreateLogMarshallingArea(
hLog: *mut core::ffi::c_void, // HANDLE
pfnAllocBuffer: *const core::ffi::c_void, // CLFS_BLOCK_ALLOCATION
pfnFreeBuffer: *const core::ffi::c_void, // CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext: *mut (), // void* in/out
cbMarshallingBuffer: u32, // DWORD
cMaxWriteBuffers: u32, // DWORD
cMaxReadBuffers: u32, // DWORD
ppvMarshal: *mut *mut () // void** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("clfsw32.dll", SetLastError = true)]
public static extern bool CreateLogMarshallingArea(IntPtr hLog, IntPtr pfnAllocBuffer, IntPtr pfnFreeBuffer, IntPtr pvBlockAllocContext, uint cbMarshallingBuffer, uint cMaxWriteBuffers, uint cMaxReadBuffers, IntPtr ppvMarshal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'clfsw32_CreateLogMarshallingArea' -Namespace Win32 -PassThru
# $api::CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)#uselib "clfsw32.dll"
#func global CreateLogMarshallingArea "CreateLogMarshallingArea" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateLogMarshallingArea hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal ; 戻り値は stat
; hLog : HANDLE -> "sptr"
; pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> "sptr"
; pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> "sptr"
; pvBlockAllocContext : void* in/out -> "sptr"
; cbMarshallingBuffer : DWORD -> "sptr"
; cMaxWriteBuffers : DWORD -> "sptr"
; cMaxReadBuffers : DWORD -> "sptr"
; ppvMarshal : void** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "clfsw32.dll"
#cfunc global CreateLogMarshallingArea "CreateLogMarshallingArea" sptr, sptr, sptr, sptr, int, int, int, sptr
; res = CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
; hLog : HANDLE -> "sptr"
; pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> "sptr"
; pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> "sptr"
; pvBlockAllocContext : void* in/out -> "sptr"
; cbMarshallingBuffer : DWORD -> "int"
; cMaxWriteBuffers : DWORD -> "int"
; cMaxReadBuffers : DWORD -> "int"
; ppvMarshal : void** in/out -> "sptr"; BOOL CreateLogMarshallingArea(HANDLE hLog, CLFS_BLOCK_ALLOCATION pfnAllocBuffer, CLFS_BLOCK_DEALLOCATION pfnFreeBuffer, void* pvBlockAllocContext, DWORD cbMarshallingBuffer, DWORD cMaxWriteBuffers, DWORD cMaxReadBuffers, void** ppvMarshal)
#uselib "clfsw32.dll"
#cfunc global CreateLogMarshallingArea "CreateLogMarshallingArea" intptr, intptr, intptr, intptr, int, int, int, intptr
; res = CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
; hLog : HANDLE -> "intptr"
; pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> "intptr"
; pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> "intptr"
; pvBlockAllocContext : void* in/out -> "intptr"
; cbMarshallingBuffer : DWORD -> "int"
; cMaxWriteBuffers : DWORD -> "int"
; cMaxReadBuffers : DWORD -> "int"
; ppvMarshal : void** in/out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
clfsw32 = windows.NewLazySystemDLL("clfsw32.dll")
procCreateLogMarshallingArea = clfsw32.NewProc("CreateLogMarshallingArea")
)
// hLog (HANDLE), pfnAllocBuffer (CLFS_BLOCK_ALLOCATION), pfnFreeBuffer (CLFS_BLOCK_DEALLOCATION), pvBlockAllocContext (void* in/out), cbMarshallingBuffer (DWORD), cMaxWriteBuffers (DWORD), cMaxReadBuffers (DWORD), ppvMarshal (void** in/out)
r1, _, err := procCreateLogMarshallingArea.Call(
uintptr(hLog),
uintptr(pfnAllocBuffer),
uintptr(pfnFreeBuffer),
uintptr(pvBlockAllocContext),
uintptr(cbMarshallingBuffer),
uintptr(cMaxWriteBuffers),
uintptr(cMaxReadBuffers),
uintptr(ppvMarshal),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CreateLogMarshallingArea(
hLog: THandle; // HANDLE
pfnAllocBuffer: Pointer; // CLFS_BLOCK_ALLOCATION
pfnFreeBuffer: Pointer; // CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext: Pointer; // void* in/out
cbMarshallingBuffer: DWORD; // DWORD
cMaxWriteBuffers: DWORD; // DWORD
cMaxReadBuffers: DWORD; // DWORD
ppvMarshal: Pointer // void** in/out
): BOOL; stdcall;
external 'clfsw32.dll' name 'CreateLogMarshallingArea';result := DllCall("clfsw32\CreateLogMarshallingArea"
, "Ptr", hLog ; HANDLE
, "Ptr", pfnAllocBuffer ; CLFS_BLOCK_ALLOCATION
, "Ptr", pfnFreeBuffer ; CLFS_BLOCK_DEALLOCATION
, "Ptr", pvBlockAllocContext ; void* in/out
, "UInt", cbMarshallingBuffer ; DWORD
, "UInt", cMaxWriteBuffers ; DWORD
, "UInt", cMaxReadBuffers ; DWORD
, "Ptr", ppvMarshal ; void** in/out
, "Int") ; return: BOOL●CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal) = DLL("clfsw32.dll", "bool CreateLogMarshallingArea(void*, void*, void*, void*, dword, dword, dword, void*)")
# 呼び出し: CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
# hLog : HANDLE -> "void*"
# pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> "void*"
# pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> "void*"
# pvBlockAllocContext : void* in/out -> "void*"
# cbMarshallingBuffer : DWORD -> "dword"
# cMaxWriteBuffers : DWORD -> "dword"
# cMaxReadBuffers : DWORD -> "dword"
# ppvMarshal : void** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "clfsw32" fn CreateLogMarshallingArea(
hLog: ?*anyopaque, // HANDLE
pfnAllocBuffer: ?*anyopaque, // CLFS_BLOCK_ALLOCATION
pfnFreeBuffer: ?*anyopaque, // CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext: ?*anyopaque, // void* in/out
cbMarshallingBuffer: u32, // DWORD
cMaxWriteBuffers: u32, // DWORD
cMaxReadBuffers: u32, // DWORD
ppvMarshal: ?*anyopaque // void** in/out
) callconv(std.os.windows.WINAPI) i32;proc CreateLogMarshallingArea(
hLog: pointer, # HANDLE
pfnAllocBuffer: pointer, # CLFS_BLOCK_ALLOCATION
pfnFreeBuffer: pointer, # CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext: pointer, # void* in/out
cbMarshallingBuffer: uint32, # DWORD
cMaxWriteBuffers: uint32, # DWORD
cMaxReadBuffers: uint32, # DWORD
ppvMarshal: pointer # void** in/out
): int32 {.importc: "CreateLogMarshallingArea", stdcall, dynlib: "clfsw32.dll".}pragma(lib, "clfsw32");
extern(Windows)
int CreateLogMarshallingArea(
void* hLog, // HANDLE
void* pfnAllocBuffer, // CLFS_BLOCK_ALLOCATION
void* pfnFreeBuffer, // CLFS_BLOCK_DEALLOCATION
void* pvBlockAllocContext, // void* in/out
uint cbMarshallingBuffer, // DWORD
uint cMaxWriteBuffers, // DWORD
uint cMaxReadBuffers, // DWORD
void** ppvMarshal // void** in/out
);ccall((:CreateLogMarshallingArea, "clfsw32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, UInt32, UInt32, UInt32, Ptr{Cvoid}),
hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
# hLog : HANDLE -> Ptr{Cvoid}
# pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> Ptr{Cvoid}
# pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> Ptr{Cvoid}
# pvBlockAllocContext : void* in/out -> Ptr{Cvoid}
# cbMarshallingBuffer : DWORD -> UInt32
# cMaxWriteBuffers : DWORD -> UInt32
# cMaxReadBuffers : DWORD -> UInt32
# ppvMarshal : void** in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t CreateLogMarshallingArea(
void* hLog,
void* pfnAllocBuffer,
void* pfnFreeBuffer,
void* pvBlockAllocContext,
uint32_t cbMarshallingBuffer,
uint32_t cMaxWriteBuffers,
uint32_t cMaxReadBuffers,
void** ppvMarshal);
]]
local clfsw32 = ffi.load("clfsw32")
-- clfsw32.CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
-- hLog : HANDLE
-- pfnAllocBuffer : CLFS_BLOCK_ALLOCATION
-- pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION
-- pvBlockAllocContext : void* in/out
-- cbMarshallingBuffer : DWORD
-- cMaxWriteBuffers : DWORD
-- cMaxReadBuffers : DWORD
-- ppvMarshal : void** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('clfsw32.dll');
const CreateLogMarshallingArea = lib.func('__stdcall', 'CreateLogMarshallingArea', 'int32_t', ['void *', 'void *', 'void *', 'void *', 'uint32_t', 'uint32_t', 'uint32_t', 'void *']);
// CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
// hLog : HANDLE -> 'void *'
// pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> 'void *'
// pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> 'void *'
// pvBlockAllocContext : void* in/out -> 'void *'
// cbMarshallingBuffer : DWORD -> 'uint32_t'
// cMaxWriteBuffers : DWORD -> 'uint32_t'
// cMaxReadBuffers : DWORD -> 'uint32_t'
// ppvMarshal : void** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("clfsw32.dll", {
CreateLogMarshallingArea: { parameters: ["pointer", "pointer", "pointer", "pointer", "u32", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal)
// hLog : HANDLE -> "pointer"
// pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> "pointer"
// pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> "pointer"
// pvBlockAllocContext : void* in/out -> "pointer"
// cbMarshallingBuffer : DWORD -> "u32"
// cMaxWriteBuffers : DWORD -> "u32"
// cMaxReadBuffers : DWORD -> "u32"
// ppvMarshal : void** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t CreateLogMarshallingArea(
void* hLog,
void* pfnAllocBuffer,
void* pfnFreeBuffer,
void* pvBlockAllocContext,
uint32_t cbMarshallingBuffer,
uint32_t cMaxWriteBuffers,
uint32_t cMaxReadBuffers,
void** ppvMarshal);
C, "clfsw32.dll");
// $ffi->CreateLogMarshallingArea(hLog, pfnAllocBuffer, pfnFreeBuffer, pvBlockAllocContext, cbMarshallingBuffer, cMaxWriteBuffers, cMaxReadBuffers, ppvMarshal);
// hLog : HANDLE
// pfnAllocBuffer : CLFS_BLOCK_ALLOCATION
// pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION
// pvBlockAllocContext : void* in/out
// cbMarshallingBuffer : DWORD
// cMaxWriteBuffers : DWORD
// cMaxReadBuffers : DWORD
// ppvMarshal : void** in/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 Clfsw32 extends StdCallLibrary {
Clfsw32 INSTANCE = Native.load("clfsw32", Clfsw32.class);
boolean CreateLogMarshallingArea(
Pointer hLog, // HANDLE
Callback pfnAllocBuffer, // CLFS_BLOCK_ALLOCATION
Callback pfnFreeBuffer, // CLFS_BLOCK_DEALLOCATION
Pointer pvBlockAllocContext, // void* in/out
int cbMarshallingBuffer, // DWORD
int cMaxWriteBuffers, // DWORD
int cMaxReadBuffers, // DWORD
Pointer ppvMarshal // void** in/out
);
}@[Link("clfsw32")]
lib Libclfsw32
fun CreateLogMarshallingArea = CreateLogMarshallingArea(
hLog : Void*, # HANDLE
pfnAllocBuffer : Void*, # CLFS_BLOCK_ALLOCATION
pfnFreeBuffer : Void*, # CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext : Void*, # void* in/out
cbMarshallingBuffer : UInt32, # DWORD
cMaxWriteBuffers : UInt32, # DWORD
cMaxReadBuffers : UInt32, # DWORD
ppvMarshal : Void** # void** in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CreateLogMarshallingAreaNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32, Uint32, Uint32, Pointer<Void>);
typedef CreateLogMarshallingAreaDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, int, int, int, Pointer<Void>);
final CreateLogMarshallingArea = DynamicLibrary.open('clfsw32.dll')
.lookupFunction<CreateLogMarshallingAreaNative, CreateLogMarshallingAreaDart>('CreateLogMarshallingArea');
// hLog : HANDLE -> Pointer<Void>
// pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> Pointer<Void>
// pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> Pointer<Void>
// pvBlockAllocContext : void* in/out -> Pointer<Void>
// cbMarshallingBuffer : DWORD -> Uint32
// cMaxWriteBuffers : DWORD -> Uint32
// cMaxReadBuffers : DWORD -> Uint32
// ppvMarshal : void** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CreateLogMarshallingArea(
hLog: THandle; // HANDLE
pfnAllocBuffer: Pointer; // CLFS_BLOCK_ALLOCATION
pfnFreeBuffer: Pointer; // CLFS_BLOCK_DEALLOCATION
pvBlockAllocContext: Pointer; // void* in/out
cbMarshallingBuffer: DWORD; // DWORD
cMaxWriteBuffers: DWORD; // DWORD
cMaxReadBuffers: DWORD; // DWORD
ppvMarshal: Pointer // void** in/out
): BOOL; stdcall;
external 'clfsw32.dll' name 'CreateLogMarshallingArea';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateLogMarshallingArea"
c_CreateLogMarshallingArea :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> Word32 -> Word32 -> Word32 -> Ptr () -> IO CInt
-- hLog : HANDLE -> Ptr ()
-- pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> Ptr ()
-- pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> Ptr ()
-- pvBlockAllocContext : void* in/out -> Ptr ()
-- cbMarshallingBuffer : DWORD -> Word32
-- cMaxWriteBuffers : DWORD -> Word32
-- cMaxReadBuffers : DWORD -> Word32
-- ppvMarshal : void** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createlogmarshallingarea =
foreign "CreateLogMarshallingArea"
((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hLog : HANDLE -> (ptr void) *)
(* pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> (ptr void) *)
(* pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> (ptr void) *)
(* pvBlockAllocContext : void* in/out -> (ptr void) *)
(* cbMarshallingBuffer : DWORD -> uint32_t *)
(* cMaxWriteBuffers : DWORD -> uint32_t *)
(* cMaxReadBuffers : DWORD -> uint32_t *)
(* ppvMarshal : void** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library clfsw32 (t "clfsw32.dll"))
(cffi:use-foreign-library clfsw32)
(cffi:defcfun ("CreateLogMarshallingArea" create-log-marshalling-area :convention :stdcall) :int32
(h-log :pointer) ; HANDLE
(pfn-alloc-buffer :pointer) ; CLFS_BLOCK_ALLOCATION
(pfn-free-buffer :pointer) ; CLFS_BLOCK_DEALLOCATION
(pv-block-alloc-context :pointer) ; void* in/out
(cb-marshalling-buffer :uint32) ; DWORD
(c-max-write-buffers :uint32) ; DWORD
(c-max-read-buffers :uint32) ; DWORD
(ppv-marshal :pointer)) ; void** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateLogMarshallingArea = Win32::API::More->new('clfsw32',
'BOOL CreateLogMarshallingArea(HANDLE hLog, LPVOID pfnAllocBuffer, LPVOID pfnFreeBuffer, LPVOID pvBlockAllocContext, DWORD cbMarshallingBuffer, DWORD cMaxWriteBuffers, DWORD cMaxReadBuffers, LPVOID ppvMarshal)');
# my $ret = $CreateLogMarshallingArea->Call($hLog, $pfnAllocBuffer, $pfnFreeBuffer, $pvBlockAllocContext, $cbMarshallingBuffer, $cMaxWriteBuffers, $cMaxReadBuffers, $ppvMarshal);
# hLog : HANDLE -> HANDLE
# pfnAllocBuffer : CLFS_BLOCK_ALLOCATION -> LPVOID
# pfnFreeBuffer : CLFS_BLOCK_DEALLOCATION -> LPVOID
# pvBlockAllocContext : void* in/out -> LPVOID
# cbMarshallingBuffer : DWORD -> DWORD
# cMaxWriteBuffers : DWORD -> DWORD
# cMaxReadBuffers : DWORD -> DWORD
# ppvMarshal : void** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
- f CreateLogFile — CLFSのログファイルを作成または開く。
- f DeleteLogMarshallingArea — CLFSログのマーシャリング領域を削除する。