ホーム › System.Ole › OleTranslateColor
OleTranslateColor
関数OLE_COLOR値をGDIのCOLORREF値に変換する。
シグネチャ
// OLEAUT32.dll
#include <windows.h>
HRESULT OleTranslateColor(
DWORD clr,
HPALETTE hpal,
COLORREF* lpcolorref
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| clr | DWORD | in | COLORREF に変換する OLE カラー。 |
| hpal | HPALETTE | in | 変換の基準として使用するパレット。 |
| lpcolorref | COLORREF* | out | 変換後の COLORREF 結果を受け取る、呼び出し元の変数へのポインター。このパラメーターには NULL を指定でき、その場合、呼び出し元は変換可能な色が存在するかどうかの確認のみを行うことを示します。 |
戻り値の型: HRESULT
公式ドキュメント
OLE_COLOR 型を COLORREF に変換します。
戻り値
この関数は、標準の戻り値 E_INVALIDARG および E_UNEXPECTED に加えて、次の値をサポートします。
| 戻り値 | 説明 |
|---|---|
| 色が正常に変換されました。 |
解説(Remarks)
次の表は、色の変換について説明します。
| OLE_COLOR | hPal | COLORREF |
|---|---|---|
| 無効 | 未定義 (E_INVALIDARG) | |
| 0x800000xx (xx が有効な GetSysColor インデックスでない場合) | 未定義 (E_INVALIDARG) | |
| 無効 | 未定義 (E_INVALIDARG) | |
| 0x0100iiii (iiii が有効なパレットインデックスでない場合) | 有効なパレット | 未定義 (E_INVALIDARG) |
| 0x800000xx (xx が有効な GetSysColor インデックスの場合) | NULL | 0x00bbggrr |
| 0x0100iiii (iiii が有効なパレットインデックスの場合) | NULL | 0x0100iiii |
| 0x02bbggrr (パレット相対) | NULL | 0x02bbggrr |
| 0x00bbggrr | NULL | 0x00bbggrr |
| 0x800000xx (xx が有効な GetSysColor インデックスの場合) | 有効なパレット | 0x00bbggrr |
| 0x0100iiii (iiii が hPal 内の有効なパレットインデックスの場合) | 有効なパレット | 0x0100iiii |
| 0x02bbggrr (パレット相対) | 有効なパレット | 0x02bbggrr |
| 0x00bbggrr | 有効なパレット | 0x02bbggrr |
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// OLEAUT32.dll
#include <windows.h>
HRESULT OleTranslateColor(
DWORD clr,
HPALETTE hpal,
COLORREF* lpcolorref
);[DllImport("OLEAUT32.dll", ExactSpelling = true)]
static extern int OleTranslateColor(
uint clr, // DWORD
IntPtr hpal, // HPALETTE
out uint lpcolorref // COLORREF* out
);<DllImport("OLEAUT32.dll", ExactSpelling:=True)>
Public Shared Function OleTranslateColor(
clr As UInteger, ' DWORD
hpal As IntPtr, ' HPALETTE
<Out> ByRef lpcolorref As UInteger ' COLORREF* out
) As Integer
End Function' clr : DWORD
' hpal : HPALETTE
' lpcolorref : COLORREF* out
Declare PtrSafe Function OleTranslateColor Lib "oleaut32" ( _
ByVal clr As Long, _
ByVal hpal As LongPtr, _
ByRef lpcolorref As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
OleTranslateColor = ctypes.windll.oleaut32.OleTranslateColor
OleTranslateColor.restype = ctypes.c_int
OleTranslateColor.argtypes = [
wintypes.DWORD, # clr : DWORD
wintypes.HANDLE, # hpal : HPALETTE
ctypes.c_void_p, # lpcolorref : COLORREF* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('OLEAUT32.dll')
OleTranslateColor = Fiddle::Function.new(
lib['OleTranslateColor'],
[
-Fiddle::TYPE_INT, # clr : DWORD
Fiddle::TYPE_VOIDP, # hpal : HPALETTE
Fiddle::TYPE_VOIDP, # lpcolorref : COLORREF* out
],
Fiddle::TYPE_INT)#[link(name = "oleaut32")]
extern "system" {
fn OleTranslateColor(
clr: u32, // DWORD
hpal: *mut core::ffi::c_void, // HPALETTE
lpcolorref: *mut u32 // COLORREF* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("OLEAUT32.dll")]
public static extern int OleTranslateColor(uint clr, IntPtr hpal, out uint lpcolorref);
"@
$api = Add-Type -MemberDefinition $sig -Name 'OLEAUT32_OleTranslateColor' -Namespace Win32 -PassThru
# $api::OleTranslateColor(clr, hpal, lpcolorref)#uselib "OLEAUT32.dll"
#func global OleTranslateColor "OleTranslateColor" sptr, sptr, sptr
; OleTranslateColor clr, hpal, varptr(lpcolorref) ; 戻り値は stat
; clr : DWORD -> "sptr"
; hpal : HPALETTE -> "sptr"
; lpcolorref : COLORREF* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "OLEAUT32.dll" #cfunc global OleTranslateColor "OleTranslateColor" int, sptr, var ; res = OleTranslateColor(clr, hpal, lpcolorref) ; clr : DWORD -> "int" ; hpal : HPALETTE -> "sptr" ; lpcolorref : COLORREF* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "OLEAUT32.dll" #cfunc global OleTranslateColor "OleTranslateColor" int, sptr, sptr ; res = OleTranslateColor(clr, hpal, varptr(lpcolorref)) ; clr : DWORD -> "int" ; hpal : HPALETTE -> "sptr" ; lpcolorref : COLORREF* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT OleTranslateColor(DWORD clr, HPALETTE hpal, COLORREF* lpcolorref) #uselib "OLEAUT32.dll" #cfunc global OleTranslateColor "OleTranslateColor" int, intptr, var ; res = OleTranslateColor(clr, hpal, lpcolorref) ; clr : DWORD -> "int" ; hpal : HPALETTE -> "intptr" ; lpcolorref : COLORREF* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT OleTranslateColor(DWORD clr, HPALETTE hpal, COLORREF* lpcolorref) #uselib "OLEAUT32.dll" #cfunc global OleTranslateColor "OleTranslateColor" int, intptr, intptr ; res = OleTranslateColor(clr, hpal, varptr(lpcolorref)) ; clr : DWORD -> "int" ; hpal : HPALETTE -> "intptr" ; lpcolorref : COLORREF* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
oleaut32 = windows.NewLazySystemDLL("OLEAUT32.dll")
procOleTranslateColor = oleaut32.NewProc("OleTranslateColor")
)
// clr (DWORD), hpal (HPALETTE), lpcolorref (COLORREF* out)
r1, _, err := procOleTranslateColor.Call(
uintptr(clr),
uintptr(hpal),
uintptr(lpcolorref),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction OleTranslateColor(
clr: DWORD; // DWORD
hpal: THandle; // HPALETTE
lpcolorref: Pointer // COLORREF* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'OleTranslateColor';result := DllCall("OLEAUT32\OleTranslateColor"
, "UInt", clr ; DWORD
, "Ptr", hpal ; HPALETTE
, "Ptr", lpcolorref ; COLORREF* out
, "Int") ; return: HRESULT●OleTranslateColor(clr, hpal, lpcolorref) = DLL("OLEAUT32.dll", "int OleTranslateColor(dword, void*, void*)")
# 呼び出し: OleTranslateColor(clr, hpal, lpcolorref)
# clr : DWORD -> "dword"
# hpal : HPALETTE -> "void*"
# lpcolorref : COLORREF* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "oleaut32" fn OleTranslateColor(
clr: u32, // DWORD
hpal: ?*anyopaque, // HPALETTE
lpcolorref: [*c]u32 // COLORREF* out
) callconv(std.os.windows.WINAPI) i32;proc OleTranslateColor(
clr: uint32, # DWORD
hpal: pointer, # HPALETTE
lpcolorref: ptr uint32 # COLORREF* out
): int32 {.importc: "OleTranslateColor", stdcall, dynlib: "OLEAUT32.dll".}pragma(lib, "oleaut32");
extern(Windows)
int OleTranslateColor(
uint clr, // DWORD
void* hpal, // HPALETTE
uint* lpcolorref // COLORREF* out
);ccall((:OleTranslateColor, "OLEAUT32.dll"), stdcall, Int32,
(UInt32, Ptr{Cvoid}, Ptr{UInt32}),
clr, hpal, lpcolorref)
# clr : DWORD -> UInt32
# hpal : HPALETTE -> Ptr{Cvoid}
# lpcolorref : COLORREF* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t OleTranslateColor(
uint32_t clr,
void* hpal,
uint32_t* lpcolorref);
]]
local oleaut32 = ffi.load("oleaut32")
-- oleaut32.OleTranslateColor(clr, hpal, lpcolorref)
-- clr : DWORD
-- hpal : HPALETTE
-- lpcolorref : COLORREF* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('OLEAUT32.dll');
const OleTranslateColor = lib.func('__stdcall', 'OleTranslateColor', 'int32_t', ['uint32_t', 'void *', 'uint32_t *']);
// OleTranslateColor(clr, hpal, lpcolorref)
// clr : DWORD -> 'uint32_t'
// hpal : HPALETTE -> 'void *'
// lpcolorref : COLORREF* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("OLEAUT32.dll", {
OleTranslateColor: { parameters: ["u32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.OleTranslateColor(clr, hpal, lpcolorref)
// clr : DWORD -> "u32"
// hpal : HPALETTE -> "pointer"
// lpcolorref : COLORREF* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t OleTranslateColor(
uint32_t clr,
void* hpal,
uint32_t* lpcolorref);
C, "OLEAUT32.dll");
// $ffi->OleTranslateColor(clr, hpal, lpcolorref);
// clr : DWORD
// hpal : HPALETTE
// lpcolorref : COLORREF* 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 Oleaut32 extends StdCallLibrary {
Oleaut32 INSTANCE = Native.load("oleaut32", Oleaut32.class);
int OleTranslateColor(
int clr, // DWORD
Pointer hpal, // HPALETTE
IntByReference lpcolorref // COLORREF* out
);
}@[Link("oleaut32")]
lib LibOLEAUT32
fun OleTranslateColor = OleTranslateColor(
clr : UInt32, # DWORD
hpal : Void*, # HPALETTE
lpcolorref : UInt32* # COLORREF* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef OleTranslateColorNative = Int32 Function(Uint32, Pointer<Void>, Pointer<Uint32>);
typedef OleTranslateColorDart = int Function(int, Pointer<Void>, Pointer<Uint32>);
final OleTranslateColor = DynamicLibrary.open('OLEAUT32.dll')
.lookupFunction<OleTranslateColorNative, OleTranslateColorDart>('OleTranslateColor');
// clr : DWORD -> Uint32
// hpal : HPALETTE -> Pointer<Void>
// lpcolorref : COLORREF* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function OleTranslateColor(
clr: DWORD; // DWORD
hpal: THandle; // HPALETTE
lpcolorref: Pointer // COLORREF* out
): Integer; stdcall;
external 'OLEAUT32.dll' name 'OleTranslateColor';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "OleTranslateColor"
c_OleTranslateColor :: Word32 -> Ptr () -> Ptr Word32 -> IO Int32
-- clr : DWORD -> Word32
-- hpal : HPALETTE -> Ptr ()
-- lpcolorref : COLORREF* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let oletranslatecolor =
foreign "OleTranslateColor"
(uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* clr : DWORD -> uint32_t *)
(* hpal : HPALETTE -> (ptr void) *)
(* lpcolorref : COLORREF* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library oleaut32 (t "OLEAUT32.dll"))
(cffi:use-foreign-library oleaut32)
(cffi:defcfun ("OleTranslateColor" ole-translate-color :convention :stdcall) :int32
(clr :uint32) ; DWORD
(hpal :pointer) ; HPALETTE
(lpcolorref :pointer)) ; COLORREF* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $OleTranslateColor = Win32::API::More->new('OLEAUT32',
'int OleTranslateColor(DWORD clr, HANDLE hpal, LPVOID lpcolorref)');
# my $ret = $OleTranslateColor->Call($clr, $hpal, $lpcolorref);
# clr : DWORD -> DWORD
# hpal : HPALETTE -> HANDLE
# lpcolorref : COLORREF* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。