Win32 API 日本語リファレンス
ホームUI.ColorSystem › TranslateBitmapBits

TranslateBitmapBits

関数
色変換を用いてビットマップのビットを変換する。
DLLmscms.dll呼出規約winapi

シグネチャ

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

BOOL TranslateBitmapBits(
    INT_PTR hColorTransform,
    void* pSrcBits,
    BMFORMAT bmInput,
    DWORD dwWidth,
    DWORD dwHeight,
    DWORD dwInputStride,
    void* pDestBits,
    BMFORMAT bmOutput,
    DWORD dwOutputStride,
    LPBMCALLBACKFN pfnCallBack,   // optional
    LPARAM ulCallbackData   // optional
);

パラメーター

名前方向説明
hColorTransformINT_PTRin適用するカラー変換のハンドル。
pSrcBitsvoid*in変換元ビットマップのピクセルデータを指すポインタ。
bmInputBMFORMATin入力ビットマップのピクセルフォーマットを示す列挙値。
dwWidthDWORDinビットマップの幅(ピクセル数)。
dwHeightDWORDinビットマップの高さ(ピクセル数)。
dwInputStrideDWORDin入力ビットマップ1走査線のバイト数(ストライド)。
pDestBitsvoid*out変換後のピクセルデータを格納する出力バッファへのポインタ。
bmOutputBMFORMATin出力ビットマップのピクセルフォーマットを示す列挙値。
dwOutputStrideDWORDin出力ビットマップ1走査線のバイト数(ストライド)。
pfnCallBackLPBMCALLBACKFNinoptional処理進捗を通知するコールバック関数のポインタ。NULL可。
ulCallbackDataLPARAMinoptionalコールバック関数へ渡すアプリケーション定義のデータ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL TranslateBitmapBits(
    INT_PTR hColorTransform,
    void* pSrcBits,
    BMFORMAT bmInput,
    DWORD dwWidth,
    DWORD dwHeight,
    DWORD dwInputStride,
    void* pDestBits,
    BMFORMAT bmOutput,
    DWORD dwOutputStride,
    LPBMCALLBACKFN pfnCallBack,   // optional
    LPARAM ulCallbackData   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll", ExactSpelling = true)]
static extern bool TranslateBitmapBits(
    IntPtr hColorTransform,   // INT_PTR
    IntPtr pSrcBits,   // void*
    int bmInput,   // BMFORMAT
    uint dwWidth,   // DWORD
    uint dwHeight,   // DWORD
    uint dwInputStride,   // DWORD
    IntPtr pDestBits,   // void* out
    int bmOutput,   // BMFORMAT
    uint dwOutputStride,   // DWORD
    IntPtr pfnCallBack,   // LPBMCALLBACKFN optional
    IntPtr ulCallbackData   // LPARAM optional
);
<DllImport("mscms.dll", ExactSpelling:=True)>
Public Shared Function TranslateBitmapBits(
    hColorTransform As IntPtr,   ' INT_PTR
    pSrcBits As IntPtr,   ' void*
    bmInput As Integer,   ' BMFORMAT
    dwWidth As UInteger,   ' DWORD
    dwHeight As UInteger,   ' DWORD
    dwInputStride As UInteger,   ' DWORD
    pDestBits As IntPtr,   ' void* out
    bmOutput As Integer,   ' BMFORMAT
    dwOutputStride As UInteger,   ' DWORD
    pfnCallBack As IntPtr,   ' LPBMCALLBACKFN optional
    ulCallbackData As IntPtr   ' LPARAM optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hColorTransform : INT_PTR
' pSrcBits : void*
' bmInput : BMFORMAT
' dwWidth : DWORD
' dwHeight : DWORD
' dwInputStride : DWORD
' pDestBits : void* out
' bmOutput : BMFORMAT
' dwOutputStride : DWORD
' pfnCallBack : LPBMCALLBACKFN optional
' ulCallbackData : LPARAM optional
Declare PtrSafe Function TranslateBitmapBits Lib "mscms" ( _
    ByVal hColorTransform As LongPtr, _
    ByVal pSrcBits As LongPtr, _
    ByVal bmInput As Long, _
    ByVal dwWidth As Long, _
    ByVal dwHeight As Long, _
    ByVal dwInputStride As Long, _
    ByVal pDestBits As LongPtr, _
    ByVal bmOutput As Long, _
    ByVal dwOutputStride As Long, _
    ByVal pfnCallBack As LongPtr, _
    ByVal ulCallbackData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TranslateBitmapBits = ctypes.windll.mscms.TranslateBitmapBits
TranslateBitmapBits.restype = wintypes.BOOL
TranslateBitmapBits.argtypes = [
    ctypes.c_ssize_t,  # hColorTransform : INT_PTR
    ctypes.POINTER(None),  # pSrcBits : void*
    ctypes.c_int,  # bmInput : BMFORMAT
    wintypes.DWORD,  # dwWidth : DWORD
    wintypes.DWORD,  # dwHeight : DWORD
    wintypes.DWORD,  # dwInputStride : DWORD
    ctypes.POINTER(None),  # pDestBits : void* out
    ctypes.c_int,  # bmOutput : BMFORMAT
    wintypes.DWORD,  # dwOutputStride : DWORD
    ctypes.c_void_p,  # pfnCallBack : LPBMCALLBACKFN optional
    ctypes.c_ssize_t,  # ulCallbackData : LPARAM optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mscms.dll')
TranslateBitmapBits = Fiddle::Function.new(
  lib['TranslateBitmapBits'],
  [
    Fiddle::TYPE_INTPTR_T,  # hColorTransform : INT_PTR
    Fiddle::TYPE_VOIDP,  # pSrcBits : void*
    Fiddle::TYPE_INT,  # bmInput : BMFORMAT
    -Fiddle::TYPE_INT,  # dwWidth : DWORD
    -Fiddle::TYPE_INT,  # dwHeight : DWORD
    -Fiddle::TYPE_INT,  # dwInputStride : DWORD
    Fiddle::TYPE_VOIDP,  # pDestBits : void* out
    Fiddle::TYPE_INT,  # bmOutput : BMFORMAT
    -Fiddle::TYPE_INT,  # dwOutputStride : DWORD
    Fiddle::TYPE_VOIDP,  # pfnCallBack : LPBMCALLBACKFN optional
    Fiddle::TYPE_INTPTR_T,  # ulCallbackData : LPARAM optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "mscms")]
extern "system" {
    fn TranslateBitmapBits(
        hColorTransform: isize,  // INT_PTR
        pSrcBits: *mut (),  // void*
        bmInput: i32,  // BMFORMAT
        dwWidth: u32,  // DWORD
        dwHeight: u32,  // DWORD
        dwInputStride: u32,  // DWORD
        pDestBits: *mut (),  // void* out
        bmOutput: i32,  // BMFORMAT
        dwOutputStride: u32,  // DWORD
        pfnCallBack: *const core::ffi::c_void,  // LPBMCALLBACKFN optional
        ulCallbackData: isize  // LPARAM optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll")]
public static extern bool TranslateBitmapBits(IntPtr hColorTransform, IntPtr pSrcBits, int bmInput, uint dwWidth, uint dwHeight, uint dwInputStride, IntPtr pDestBits, int bmOutput, uint dwOutputStride, IntPtr pfnCallBack, IntPtr ulCallbackData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mscms_TranslateBitmapBits' -Namespace Win32 -PassThru
# $api::TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
#uselib "mscms.dll"
#func global TranslateBitmapBits "TranslateBitmapBits" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; TranslateBitmapBits hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData   ; 戻り値は stat
; hColorTransform : INT_PTR -> "sptr"
; pSrcBits : void* -> "sptr"
; bmInput : BMFORMAT -> "sptr"
; dwWidth : DWORD -> "sptr"
; dwHeight : DWORD -> "sptr"
; dwInputStride : DWORD -> "sptr"
; pDestBits : void* out -> "sptr"
; bmOutput : BMFORMAT -> "sptr"
; dwOutputStride : DWORD -> "sptr"
; pfnCallBack : LPBMCALLBACKFN optional -> "sptr"
; ulCallbackData : LPARAM optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "mscms.dll"
#cfunc global TranslateBitmapBits "TranslateBitmapBits" sptr, sptr, int, int, int, int, sptr, int, int, sptr, sptr
; res = TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
; hColorTransform : INT_PTR -> "sptr"
; pSrcBits : void* -> "sptr"
; bmInput : BMFORMAT -> "int"
; dwWidth : DWORD -> "int"
; dwHeight : DWORD -> "int"
; dwInputStride : DWORD -> "int"
; pDestBits : void* out -> "sptr"
; bmOutput : BMFORMAT -> "int"
; dwOutputStride : DWORD -> "int"
; pfnCallBack : LPBMCALLBACKFN optional -> "sptr"
; ulCallbackData : LPARAM optional -> "sptr"
; BOOL TranslateBitmapBits(INT_PTR hColorTransform, void* pSrcBits, BMFORMAT bmInput, DWORD dwWidth, DWORD dwHeight, DWORD dwInputStride, void* pDestBits, BMFORMAT bmOutput, DWORD dwOutputStride, LPBMCALLBACKFN pfnCallBack, LPARAM ulCallbackData)
#uselib "mscms.dll"
#cfunc global TranslateBitmapBits "TranslateBitmapBits" intptr, intptr, int, int, int, int, intptr, int, int, intptr, intptr
; res = TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
; hColorTransform : INT_PTR -> "intptr"
; pSrcBits : void* -> "intptr"
; bmInput : BMFORMAT -> "int"
; dwWidth : DWORD -> "int"
; dwHeight : DWORD -> "int"
; dwInputStride : DWORD -> "int"
; pDestBits : void* out -> "intptr"
; bmOutput : BMFORMAT -> "int"
; dwOutputStride : DWORD -> "int"
; pfnCallBack : LPBMCALLBACKFN optional -> "intptr"
; ulCallbackData : LPARAM optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mscms = windows.NewLazySystemDLL("mscms.dll")
	procTranslateBitmapBits = mscms.NewProc("TranslateBitmapBits")
)

// hColorTransform (INT_PTR), pSrcBits (void*), bmInput (BMFORMAT), dwWidth (DWORD), dwHeight (DWORD), dwInputStride (DWORD), pDestBits (void* out), bmOutput (BMFORMAT), dwOutputStride (DWORD), pfnCallBack (LPBMCALLBACKFN optional), ulCallbackData (LPARAM optional)
r1, _, err := procTranslateBitmapBits.Call(
	uintptr(hColorTransform),
	uintptr(pSrcBits),
	uintptr(bmInput),
	uintptr(dwWidth),
	uintptr(dwHeight),
	uintptr(dwInputStride),
	uintptr(pDestBits),
	uintptr(bmOutput),
	uintptr(dwOutputStride),
	uintptr(pfnCallBack),
	uintptr(ulCallbackData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function TranslateBitmapBits(
  hColorTransform: NativeInt;   // INT_PTR
  pSrcBits: Pointer;   // void*
  bmInput: Integer;   // BMFORMAT
  dwWidth: DWORD;   // DWORD
  dwHeight: DWORD;   // DWORD
  dwInputStride: DWORD;   // DWORD
  pDestBits: Pointer;   // void* out
  bmOutput: Integer;   // BMFORMAT
  dwOutputStride: DWORD;   // DWORD
  pfnCallBack: Pointer;   // LPBMCALLBACKFN optional
  ulCallbackData: NativeInt   // LPARAM optional
): BOOL; stdcall;
  external 'mscms.dll' name 'TranslateBitmapBits';
result := DllCall("mscms\TranslateBitmapBits"
    , "Ptr", hColorTransform   ; INT_PTR
    , "Ptr", pSrcBits   ; void*
    , "Int", bmInput   ; BMFORMAT
    , "UInt", dwWidth   ; DWORD
    , "UInt", dwHeight   ; DWORD
    , "UInt", dwInputStride   ; DWORD
    , "Ptr", pDestBits   ; void* out
    , "Int", bmOutput   ; BMFORMAT
    , "UInt", dwOutputStride   ; DWORD
    , "Ptr", pfnCallBack   ; LPBMCALLBACKFN optional
    , "Ptr", ulCallbackData   ; LPARAM optional
    , "Int")   ; return: BOOL
●TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData) = DLL("mscms.dll", "bool TranslateBitmapBits(int, void*, int, dword, dword, dword, void*, int, dword, void*, int)")
# 呼び出し: TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
# hColorTransform : INT_PTR -> "int"
# pSrcBits : void* -> "void*"
# bmInput : BMFORMAT -> "int"
# dwWidth : DWORD -> "dword"
# dwHeight : DWORD -> "dword"
# dwInputStride : DWORD -> "dword"
# pDestBits : void* out -> "void*"
# bmOutput : BMFORMAT -> "int"
# dwOutputStride : DWORD -> "dword"
# pfnCallBack : LPBMCALLBACKFN optional -> "void*"
# ulCallbackData : LPARAM optional -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mscms" fn TranslateBitmapBits(
    hColorTransform: isize, // INT_PTR
    pSrcBits: ?*anyopaque, // void*
    bmInput: i32, // BMFORMAT
    dwWidth: u32, // DWORD
    dwHeight: u32, // DWORD
    dwInputStride: u32, // DWORD
    pDestBits: ?*anyopaque, // void* out
    bmOutput: i32, // BMFORMAT
    dwOutputStride: u32, // DWORD
    pfnCallBack: ?*anyopaque, // LPBMCALLBACKFN optional
    ulCallbackData: isize // LPARAM optional
) callconv(std.os.windows.WINAPI) i32;
proc TranslateBitmapBits(
    hColorTransform: int,  # INT_PTR
    pSrcBits: pointer,  # void*
    bmInput: int32,  # BMFORMAT
    dwWidth: uint32,  # DWORD
    dwHeight: uint32,  # DWORD
    dwInputStride: uint32,  # DWORD
    pDestBits: pointer,  # void* out
    bmOutput: int32,  # BMFORMAT
    dwOutputStride: uint32,  # DWORD
    pfnCallBack: pointer,  # LPBMCALLBACKFN optional
    ulCallbackData: int  # LPARAM optional
): int32 {.importc: "TranslateBitmapBits", stdcall, dynlib: "mscms.dll".}
pragma(lib, "mscms");
extern(Windows)
int TranslateBitmapBits(
    ptrdiff_t hColorTransform,   // INT_PTR
    void* pSrcBits,   // void*
    int bmInput,   // BMFORMAT
    uint dwWidth,   // DWORD
    uint dwHeight,   // DWORD
    uint dwInputStride,   // DWORD
    void* pDestBits,   // void* out
    int bmOutput,   // BMFORMAT
    uint dwOutputStride,   // DWORD
    void* pfnCallBack,   // LPBMCALLBACKFN optional
    ptrdiff_t ulCallbackData   // LPARAM optional
);
ccall((:TranslateBitmapBits, "mscms.dll"), stdcall, Int32,
      (Int, Ptr{Cvoid}, Int32, UInt32, UInt32, UInt32, Ptr{Cvoid}, Int32, UInt32, Ptr{Cvoid}, Int),
      hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
# hColorTransform : INT_PTR -> Int
# pSrcBits : void* -> Ptr{Cvoid}
# bmInput : BMFORMAT -> Int32
# dwWidth : DWORD -> UInt32
# dwHeight : DWORD -> UInt32
# dwInputStride : DWORD -> UInt32
# pDestBits : void* out -> Ptr{Cvoid}
# bmOutput : BMFORMAT -> Int32
# dwOutputStride : DWORD -> UInt32
# pfnCallBack : LPBMCALLBACKFN optional -> Ptr{Cvoid}
# ulCallbackData : LPARAM optional -> Int
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t TranslateBitmapBits(
    intptr_t hColorTransform,
    void* pSrcBits,
    int32_t bmInput,
    uint32_t dwWidth,
    uint32_t dwHeight,
    uint32_t dwInputStride,
    void* pDestBits,
    int32_t bmOutput,
    uint32_t dwOutputStride,
    void* pfnCallBack,
    intptr_t ulCallbackData);
]]
local mscms = ffi.load("mscms")
-- mscms.TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
-- hColorTransform : INT_PTR
-- pSrcBits : void*
-- bmInput : BMFORMAT
-- dwWidth : DWORD
-- dwHeight : DWORD
-- dwInputStride : DWORD
-- pDestBits : void* out
-- bmOutput : BMFORMAT
-- dwOutputStride : DWORD
-- pfnCallBack : LPBMCALLBACKFN optional
-- ulCallbackData : LPARAM optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('mscms.dll');
const TranslateBitmapBits = lib.func('__stdcall', 'TranslateBitmapBits', 'int32_t', ['intptr_t', 'void *', 'int32_t', 'uint32_t', 'uint32_t', 'uint32_t', 'void *', 'int32_t', 'uint32_t', 'void *', 'intptr_t']);
// TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
// hColorTransform : INT_PTR -> 'intptr_t'
// pSrcBits : void* -> 'void *'
// bmInput : BMFORMAT -> 'int32_t'
// dwWidth : DWORD -> 'uint32_t'
// dwHeight : DWORD -> 'uint32_t'
// dwInputStride : DWORD -> 'uint32_t'
// pDestBits : void* out -> 'void *'
// bmOutput : BMFORMAT -> 'int32_t'
// dwOutputStride : DWORD -> 'uint32_t'
// pfnCallBack : LPBMCALLBACKFN optional -> 'void *'
// ulCallbackData : LPARAM optional -> 'intptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("mscms.dll", {
  TranslateBitmapBits: { parameters: ["isize", "pointer", "i32", "u32", "u32", "u32", "pointer", "i32", "u32", "pointer", "isize"], result: "i32" },
});
// lib.symbols.TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData)
// hColorTransform : INT_PTR -> "isize"
// pSrcBits : void* -> "pointer"
// bmInput : BMFORMAT -> "i32"
// dwWidth : DWORD -> "u32"
// dwHeight : DWORD -> "u32"
// dwInputStride : DWORD -> "u32"
// pDestBits : void* out -> "pointer"
// bmOutput : BMFORMAT -> "i32"
// dwOutputStride : DWORD -> "u32"
// pfnCallBack : LPBMCALLBACKFN optional -> "pointer"
// ulCallbackData : LPARAM optional -> "isize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t TranslateBitmapBits(
    intptr_t hColorTransform,
    void* pSrcBits,
    int32_t bmInput,
    uint32_t dwWidth,
    uint32_t dwHeight,
    uint32_t dwInputStride,
    void* pDestBits,
    int32_t bmOutput,
    uint32_t dwOutputStride,
    void* pfnCallBack,
    intptr_t ulCallbackData);
C, "mscms.dll");
// $ffi->TranslateBitmapBits(hColorTransform, pSrcBits, bmInput, dwWidth, dwHeight, dwInputStride, pDestBits, bmOutput, dwOutputStride, pfnCallBack, ulCallbackData);
// hColorTransform : INT_PTR
// pSrcBits : void*
// bmInput : BMFORMAT
// dwWidth : DWORD
// dwHeight : DWORD
// dwInputStride : DWORD
// pDestBits : void* out
// bmOutput : BMFORMAT
// dwOutputStride : DWORD
// pfnCallBack : LPBMCALLBACKFN optional
// ulCallbackData : LPARAM optional
// 構造体/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 Mscms extends StdCallLibrary {
    Mscms INSTANCE = Native.load("mscms", Mscms.class);
    boolean TranslateBitmapBits(
        long hColorTransform,   // INT_PTR
        Pointer pSrcBits,   // void*
        int bmInput,   // BMFORMAT
        int dwWidth,   // DWORD
        int dwHeight,   // DWORD
        int dwInputStride,   // DWORD
        Pointer pDestBits,   // void* out
        int bmOutput,   // BMFORMAT
        int dwOutputStride,   // DWORD
        Callback pfnCallBack,   // LPBMCALLBACKFN optional
        long ulCallbackData   // LPARAM optional
    );
}
@[Link("mscms")]
lib Libmscms
  fun TranslateBitmapBits = TranslateBitmapBits(
    hColorTransform : LibC::SSizeT,   # INT_PTR
    pSrcBits : Void*,   # void*
    bmInput : Int32,   # BMFORMAT
    dwWidth : UInt32,   # DWORD
    dwHeight : UInt32,   # DWORD
    dwInputStride : UInt32,   # DWORD
    pDestBits : Void*,   # void* out
    bmOutput : Int32,   # BMFORMAT
    dwOutputStride : UInt32,   # DWORD
    pfnCallBack : Void*,   # LPBMCALLBACKFN optional
    ulCallbackData : LibC::SSizeT   # LPARAM optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef TranslateBitmapBitsNative = Int32 Function(IntPtr, Pointer<Void>, Int32, Uint32, Uint32, Uint32, Pointer<Void>, Int32, Uint32, Pointer<Void>, IntPtr);
typedef TranslateBitmapBitsDart = int Function(int, Pointer<Void>, int, int, int, int, Pointer<Void>, int, int, Pointer<Void>, int);
final TranslateBitmapBits = DynamicLibrary.open('mscms.dll')
    .lookupFunction<TranslateBitmapBitsNative, TranslateBitmapBitsDart>('TranslateBitmapBits');
// hColorTransform : INT_PTR -> IntPtr
// pSrcBits : void* -> Pointer<Void>
// bmInput : BMFORMAT -> Int32
// dwWidth : DWORD -> Uint32
// dwHeight : DWORD -> Uint32
// dwInputStride : DWORD -> Uint32
// pDestBits : void* out -> Pointer<Void>
// bmOutput : BMFORMAT -> Int32
// dwOutputStride : DWORD -> Uint32
// pfnCallBack : LPBMCALLBACKFN optional -> Pointer<Void>
// ulCallbackData : LPARAM optional -> IntPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TranslateBitmapBits(
  hColorTransform: NativeInt;   // INT_PTR
  pSrcBits: Pointer;   // void*
  bmInput: Integer;   // BMFORMAT
  dwWidth: DWORD;   // DWORD
  dwHeight: DWORD;   // DWORD
  dwInputStride: DWORD;   // DWORD
  pDestBits: Pointer;   // void* out
  bmOutput: Integer;   // BMFORMAT
  dwOutputStride: DWORD;   // DWORD
  pfnCallBack: Pointer;   // LPBMCALLBACKFN optional
  ulCallbackData: NativeInt   // LPARAM optional
): BOOL; stdcall;
  external 'mscms.dll' name 'TranslateBitmapBits';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TranslateBitmapBits"
  c_TranslateBitmapBits :: CIntPtr -> Ptr () -> Int32 -> Word32 -> Word32 -> Word32 -> Ptr () -> Int32 -> Word32 -> Ptr () -> CIntPtr -> IO CInt
-- hColorTransform : INT_PTR -> CIntPtr
-- pSrcBits : void* -> Ptr ()
-- bmInput : BMFORMAT -> Int32
-- dwWidth : DWORD -> Word32
-- dwHeight : DWORD -> Word32
-- dwInputStride : DWORD -> Word32
-- pDestBits : void* out -> Ptr ()
-- bmOutput : BMFORMAT -> Int32
-- dwOutputStride : DWORD -> Word32
-- pfnCallBack : LPBMCALLBACKFN optional -> Ptr ()
-- ulCallbackData : LPARAM optional -> CIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let translatebitmapbits =
  foreign "TranslateBitmapBits"
    (intptr_t @-> (ptr void) @-> int32_t @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr void) @-> int32_t @-> uint32_t @-> (ptr void) @-> intptr_t @-> returning int32_t)
(* hColorTransform : INT_PTR -> intptr_t *)
(* pSrcBits : void* -> (ptr void) *)
(* bmInput : BMFORMAT -> int32_t *)
(* dwWidth : DWORD -> uint32_t *)
(* dwHeight : DWORD -> uint32_t *)
(* dwInputStride : DWORD -> uint32_t *)
(* pDestBits : void* out -> (ptr void) *)
(* bmOutput : BMFORMAT -> int32_t *)
(* dwOutputStride : DWORD -> uint32_t *)
(* pfnCallBack : LPBMCALLBACKFN optional -> (ptr void) *)
(* ulCallbackData : LPARAM optional -> intptr_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mscms (t "mscms.dll"))
(cffi:use-foreign-library mscms)

(cffi:defcfun ("TranslateBitmapBits" translate-bitmap-bits :convention :stdcall) :int32
  (h-color-transform :int64)   ; INT_PTR
  (p-src-bits :pointer)   ; void*
  (bm-input :int32)   ; BMFORMAT
  (dw-width :uint32)   ; DWORD
  (dw-height :uint32)   ; DWORD
  (dw-input-stride :uint32)   ; DWORD
  (p-dest-bits :pointer)   ; void* out
  (bm-output :int32)   ; BMFORMAT
  (dw-output-stride :uint32)   ; DWORD
  (pfn-call-back :pointer)   ; LPBMCALLBACKFN optional
  (ul-callback-data :int64))   ; LPARAM optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TranslateBitmapBits = Win32::API::More->new('mscms',
    'BOOL TranslateBitmapBits(LPARAM hColorTransform, LPVOID pSrcBits, int bmInput, DWORD dwWidth, DWORD dwHeight, DWORD dwInputStride, LPVOID pDestBits, int bmOutput, DWORD dwOutputStride, LPVOID pfnCallBack, LPARAM ulCallbackData)');
# my $ret = $TranslateBitmapBits->Call($hColorTransform, $pSrcBits, $bmInput, $dwWidth, $dwHeight, $dwInputStride, $pDestBits, $bmOutput, $dwOutputStride, $pfnCallBack, $ulCallbackData);
# hColorTransform : INT_PTR -> LPARAM
# pSrcBits : void* -> LPVOID
# bmInput : BMFORMAT -> int
# dwWidth : DWORD -> DWORD
# dwHeight : DWORD -> DWORD
# dwInputStride : DWORD -> DWORD
# pDestBits : void* out -> LPVOID
# bmOutput : BMFORMAT -> int
# dwOutputStride : DWORD -> DWORD
# pfnCallBack : LPBMCALLBACKFN optional -> LPVOID
# ulCallbackData : LPARAM optional -> LPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型