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

TranslateColors

関数
色変換を用いて色配列を変換する。
DLLmscms.dll呼出規約winapi

シグネチャ

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

BOOL TranslateColors(
    INT_PTR hColorTransform,
    COLOR* paInputColors,
    DWORD nColors,
    COLORTYPE ctInput,
    COLOR* paOutputColors,
    COLORTYPE ctOutput
);

パラメーター

名前方向説明
hColorTransformINT_PTRin適用するカラー変換のハンドル。
paInputColorsCOLOR*in変換元の色値を格納したCOLOR共用体配列へのポインタ。
nColorsDWORDin変換する色の個数。
ctInputCOLORTYPEin入力色データの色形式を示す列挙値(RGB・CMYK等)。
paOutputColorsCOLOR*out変換後の色値を格納するCOLOR共用体配列へのポインタ。
ctOutputCOLORTYPEin出力色データの色形式を示す列挙値(RGB・CMYK等)。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL TranslateColors(
    INT_PTR hColorTransform,
    COLOR* paInputColors,
    DWORD nColors,
    COLORTYPE ctInput,
    COLOR* paOutputColors,
    COLORTYPE ctOutput
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll", ExactSpelling = true)]
static extern bool TranslateColors(
    IntPtr hColorTransform,   // INT_PTR
    IntPtr paInputColors,   // COLOR*
    uint nColors,   // DWORD
    int ctInput,   // COLORTYPE
    IntPtr paOutputColors,   // COLOR* out
    int ctOutput   // COLORTYPE
);
<DllImport("mscms.dll", ExactSpelling:=True)>
Public Shared Function TranslateColors(
    hColorTransform As IntPtr,   ' INT_PTR
    paInputColors As IntPtr,   ' COLOR*
    nColors As UInteger,   ' DWORD
    ctInput As Integer,   ' COLORTYPE
    paOutputColors As IntPtr,   ' COLOR* out
    ctOutput As Integer   ' COLORTYPE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hColorTransform : INT_PTR
' paInputColors : COLOR*
' nColors : DWORD
' ctInput : COLORTYPE
' paOutputColors : COLOR* out
' ctOutput : COLORTYPE
Declare PtrSafe Function TranslateColors Lib "mscms" ( _
    ByVal hColorTransform As LongPtr, _
    ByVal paInputColors As LongPtr, _
    ByVal nColors As Long, _
    ByVal ctInput As Long, _
    ByVal paOutputColors As LongPtr, _
    ByVal ctOutput As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

TranslateColors = ctypes.windll.mscms.TranslateColors
TranslateColors.restype = wintypes.BOOL
TranslateColors.argtypes = [
    ctypes.c_ssize_t,  # hColorTransform : INT_PTR
    ctypes.c_void_p,  # paInputColors : COLOR*
    wintypes.DWORD,  # nColors : DWORD
    ctypes.c_int,  # ctInput : COLORTYPE
    ctypes.c_void_p,  # paOutputColors : COLOR* out
    ctypes.c_int,  # ctOutput : COLORTYPE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mscms.dll')
TranslateColors = Fiddle::Function.new(
  lib['TranslateColors'],
  [
    Fiddle::TYPE_INTPTR_T,  # hColorTransform : INT_PTR
    Fiddle::TYPE_VOIDP,  # paInputColors : COLOR*
    -Fiddle::TYPE_INT,  # nColors : DWORD
    Fiddle::TYPE_INT,  # ctInput : COLORTYPE
    Fiddle::TYPE_VOIDP,  # paOutputColors : COLOR* out
    Fiddle::TYPE_INT,  # ctOutput : COLORTYPE
  ],
  Fiddle::TYPE_INT)
#[link(name = "mscms")]
extern "system" {
    fn TranslateColors(
        hColorTransform: isize,  // INT_PTR
        paInputColors: *mut COLOR,  // COLOR*
        nColors: u32,  // DWORD
        ctInput: i32,  // COLORTYPE
        paOutputColors: *mut COLOR,  // COLOR* out
        ctOutput: i32  // COLORTYPE
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mscms.dll")]
public static extern bool TranslateColors(IntPtr hColorTransform, IntPtr paInputColors, uint nColors, int ctInput, IntPtr paOutputColors, int ctOutput);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mscms_TranslateColors' -Namespace Win32 -PassThru
# $api::TranslateColors(hColorTransform, paInputColors, nColors, ctInput, paOutputColors, ctOutput)
#uselib "mscms.dll"
#func global TranslateColors "TranslateColors" sptr, sptr, sptr, sptr, sptr, sptr
; TranslateColors hColorTransform, varptr(paInputColors), nColors, ctInput, varptr(paOutputColors), ctOutput   ; 戻り値は stat
; hColorTransform : INT_PTR -> "sptr"
; paInputColors : COLOR* -> "sptr"
; nColors : DWORD -> "sptr"
; ctInput : COLORTYPE -> "sptr"
; paOutputColors : COLOR* out -> "sptr"
; ctOutput : COLORTYPE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "mscms.dll"
#cfunc global TranslateColors "TranslateColors" sptr, var, int, int, var, int
; res = TranslateColors(hColorTransform, paInputColors, nColors, ctInput, paOutputColors, ctOutput)
; hColorTransform : INT_PTR -> "sptr"
; paInputColors : COLOR* -> "var"
; nColors : DWORD -> "int"
; ctInput : COLORTYPE -> "int"
; paOutputColors : COLOR* out -> "var"
; ctOutput : COLORTYPE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL TranslateColors(INT_PTR hColorTransform, COLOR* paInputColors, DWORD nColors, COLORTYPE ctInput, COLOR* paOutputColors, COLORTYPE ctOutput)
#uselib "mscms.dll"
#cfunc global TranslateColors "TranslateColors" intptr, var, int, int, var, int
; res = TranslateColors(hColorTransform, paInputColors, nColors, ctInput, paOutputColors, ctOutput)
; hColorTransform : INT_PTR -> "intptr"
; paInputColors : COLOR* -> "var"
; nColors : DWORD -> "int"
; ctInput : COLORTYPE -> "int"
; paOutputColors : COLOR* out -> "var"
; ctOutput : COLORTYPE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mscms = windows.NewLazySystemDLL("mscms.dll")
	procTranslateColors = mscms.NewProc("TranslateColors")
)

// hColorTransform (INT_PTR), paInputColors (COLOR*), nColors (DWORD), ctInput (COLORTYPE), paOutputColors (COLOR* out), ctOutput (COLORTYPE)
r1, _, err := procTranslateColors.Call(
	uintptr(hColorTransform),
	uintptr(paInputColors),
	uintptr(nColors),
	uintptr(ctInput),
	uintptr(paOutputColors),
	uintptr(ctOutput),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function TranslateColors(
  hColorTransform: NativeInt;   // INT_PTR
  paInputColors: Pointer;   // COLOR*
  nColors: DWORD;   // DWORD
  ctInput: Integer;   // COLORTYPE
  paOutputColors: Pointer;   // COLOR* out
  ctOutput: Integer   // COLORTYPE
): BOOL; stdcall;
  external 'mscms.dll' name 'TranslateColors';
result := DllCall("mscms\TranslateColors"
    , "Ptr", hColorTransform   ; INT_PTR
    , "Ptr", paInputColors   ; COLOR*
    , "UInt", nColors   ; DWORD
    , "Int", ctInput   ; COLORTYPE
    , "Ptr", paOutputColors   ; COLOR* out
    , "Int", ctOutput   ; COLORTYPE
    , "Int")   ; return: BOOL
●TranslateColors(hColorTransform, paInputColors, nColors, ctInput, paOutputColors, ctOutput) = DLL("mscms.dll", "bool TranslateColors(int, void*, dword, int, void*, int)")
# 呼び出し: TranslateColors(hColorTransform, paInputColors, nColors, ctInput, paOutputColors, ctOutput)
# hColorTransform : INT_PTR -> "int"
# paInputColors : COLOR* -> "void*"
# nColors : DWORD -> "dword"
# ctInput : COLORTYPE -> "int"
# paOutputColors : COLOR* out -> "void*"
# ctOutput : COLORTYPE -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef TranslateColorsNative = Int32 Function(IntPtr, Pointer<Void>, Uint32, Int32, Pointer<Void>, Int32);
typedef TranslateColorsDart = int Function(int, Pointer<Void>, int, int, Pointer<Void>, int);
final TranslateColors = DynamicLibrary.open('mscms.dll')
    .lookupFunction<TranslateColorsNative, TranslateColorsDart>('TranslateColors');
// hColorTransform : INT_PTR -> IntPtr
// paInputColors : COLOR* -> Pointer<Void>
// nColors : DWORD -> Uint32
// ctInput : COLORTYPE -> Int32
// paOutputColors : COLOR* out -> Pointer<Void>
// ctOutput : COLORTYPE -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function TranslateColors(
  hColorTransform: NativeInt;   // INT_PTR
  paInputColors: Pointer;   // COLOR*
  nColors: DWORD;   // DWORD
  ctInput: Integer;   // COLORTYPE
  paOutputColors: Pointer;   // COLOR* out
  ctOutput: Integer   // COLORTYPE
): BOOL; stdcall;
  external 'mscms.dll' name 'TranslateColors';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "TranslateColors"
  c_TranslateColors :: CIntPtr -> Ptr () -> Word32 -> Int32 -> Ptr () -> Int32 -> IO CInt
-- hColorTransform : INT_PTR -> CIntPtr
-- paInputColors : COLOR* -> Ptr ()
-- nColors : DWORD -> Word32
-- ctInput : COLORTYPE -> Int32
-- paOutputColors : COLOR* out -> Ptr ()
-- ctOutput : COLORTYPE -> Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let translatecolors =
  foreign "TranslateColors"
    (intptr_t @-> (ptr void) @-> uint32_t @-> int32_t @-> (ptr void) @-> int32_t @-> returning int32_t)
(* hColorTransform : INT_PTR -> intptr_t *)
(* paInputColors : COLOR* -> (ptr void) *)
(* nColors : DWORD -> uint32_t *)
(* ctInput : COLORTYPE -> int32_t *)
(* paOutputColors : COLOR* out -> (ptr void) *)
(* ctOutput : COLORTYPE -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mscms (t "mscms.dll"))
(cffi:use-foreign-library mscms)

(cffi:defcfun ("TranslateColors" translate-colors :convention :stdcall) :int32
  (h-color-transform :int64)   ; INT_PTR
  (pa-input-colors :pointer)   ; COLOR*
  (n-colors :uint32)   ; DWORD
  (ct-input :int32)   ; COLORTYPE
  (pa-output-colors :pointer)   ; COLOR* out
  (ct-output :int32))   ; COLORTYPE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $TranslateColors = Win32::API::More->new('mscms',
    'BOOL TranslateColors(LPARAM hColorTransform, LPVOID paInputColors, DWORD nColors, int ctInput, LPVOID paOutputColors, int ctOutput)');
# my $ret = $TranslateColors->Call($hColorTransform, $paInputColors, $nColors, $ctInput, $paOutputColors, $ctOutput);
# hColorTransform : INT_PTR -> LPARAM
# paInputColors : COLOR* -> LPVOID
# nColors : DWORD -> DWORD
# ctInput : COLORTYPE -> int
# paOutputColors : COLOR* out -> LPVOID
# ctOutput : COLORTYPE -> int
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型