ホーム › UI.ColorSystem › ColorProfileAddDisplayAssociation
ColorProfileAddDisplayAssociation
関数カラープロファイルを指定ディスプレイに関連付ける。
シグネチャ
// mscms.dll
#include <windows.h>
HRESULT ColorProfileAddDisplayAssociation(
WCS_PROFILE_MANAGEMENT_SCOPE scope,
LPCWSTR profileName,
LUID targetAdapterID,
DWORD sourceID,
BOOL setAsDefault,
BOOL associateAsAdvancedColor
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| scope | WCS_PROFILE_MANAGEMENT_SCOPE | in | 操作対象の管理範囲(システム全体/現在ユーザー)を示すWCSスコープ列挙値。 |
| profileName | LPCWSTR | in | ディスプレイに関連付けるカラープロファイル名を指すワイド文字列ポインタ。 |
| targetAdapterID | LUID | in | 対象ディスプレイのアダプタを識別するLUID値。 |
| sourceID | DWORD | in | アダプタ上の対象ソース(出力)を識別するID。 |
| setAsDefault | BOOL | in | TRUEで当該プロファイルを既定に設定するかを指定するフラグ。 |
| associateAsAdvancedColor | BOOL | in | TRUEでHDR等の拡張色プロファイルとして関連付けるかを指定するフラグ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// mscms.dll
#include <windows.h>
HRESULT ColorProfileAddDisplayAssociation(
WCS_PROFILE_MANAGEMENT_SCOPE scope,
LPCWSTR profileName,
LUID targetAdapterID,
DWORD sourceID,
BOOL setAsDefault,
BOOL associateAsAdvancedColor
);[DllImport("mscms.dll", ExactSpelling = true)]
static extern int ColorProfileAddDisplayAssociation(
int scope, // WCS_PROFILE_MANAGEMENT_SCOPE
[MarshalAs(UnmanagedType.LPWStr)] string profileName, // LPCWSTR
LUID targetAdapterID, // LUID
uint sourceID, // DWORD
bool setAsDefault, // BOOL
bool associateAsAdvancedColor // BOOL
);<DllImport("mscms.dll", ExactSpelling:=True)>
Public Shared Function ColorProfileAddDisplayAssociation(
scope As Integer, ' WCS_PROFILE_MANAGEMENT_SCOPE
<MarshalAs(UnmanagedType.LPWStr)> profileName As String, ' LPCWSTR
targetAdapterID As LUID, ' LUID
sourceID As UInteger, ' DWORD
setAsDefault As Boolean, ' BOOL
associateAsAdvancedColor As Boolean ' BOOL
) As Integer
End Function' scope : WCS_PROFILE_MANAGEMENT_SCOPE
' profileName : LPCWSTR
' targetAdapterID : LUID
' sourceID : DWORD
' setAsDefault : BOOL
' associateAsAdvancedColor : BOOL
Declare PtrSafe Function ColorProfileAddDisplayAssociation Lib "mscms" ( _
ByVal scope As Long, _
ByVal profileName As LongPtr, _
ByVal targetAdapterID As LongPtr, _
ByVal sourceID As Long, _
ByVal setAsDefault As Long, _
ByVal associateAsAdvancedColor As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ColorProfileAddDisplayAssociation = ctypes.windll.mscms.ColorProfileAddDisplayAssociation
ColorProfileAddDisplayAssociation.restype = ctypes.c_int
ColorProfileAddDisplayAssociation.argtypes = [
ctypes.c_int, # scope : WCS_PROFILE_MANAGEMENT_SCOPE
wintypes.LPCWSTR, # profileName : LPCWSTR
LUID, # targetAdapterID : LUID
wintypes.DWORD, # sourceID : DWORD
wintypes.BOOL, # setAsDefault : BOOL
wintypes.BOOL, # associateAsAdvancedColor : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mscms.dll')
ColorProfileAddDisplayAssociation = Fiddle::Function.new(
lib['ColorProfileAddDisplayAssociation'],
[
Fiddle::TYPE_INT, # scope : WCS_PROFILE_MANAGEMENT_SCOPE
Fiddle::TYPE_VOIDP, # profileName : LPCWSTR
Fiddle::TYPE_VOIDP, # targetAdapterID : LUID
-Fiddle::TYPE_INT, # sourceID : DWORD
Fiddle::TYPE_INT, # setAsDefault : BOOL
Fiddle::TYPE_INT, # associateAsAdvancedColor : BOOL
],
Fiddle::TYPE_INT)#[link(name = "mscms")]
extern "system" {
fn ColorProfileAddDisplayAssociation(
scope: i32, // WCS_PROFILE_MANAGEMENT_SCOPE
profileName: *const u16, // LPCWSTR
targetAdapterID: LUID, // LUID
sourceID: u32, // DWORD
setAsDefault: i32, // BOOL
associateAsAdvancedColor: i32 // BOOL
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("mscms.dll")]
public static extern int ColorProfileAddDisplayAssociation(int scope, [MarshalAs(UnmanagedType.LPWStr)] string profileName, LUID targetAdapterID, uint sourceID, bool setAsDefault, bool associateAsAdvancedColor);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mscms_ColorProfileAddDisplayAssociation' -Namespace Win32 -PassThru
# $api::ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)#uselib "mscms.dll"
#func global ColorProfileAddDisplayAssociation "ColorProfileAddDisplayAssociation" sptr, sptr, sptr, sptr, sptr, sptr
; ColorProfileAddDisplayAssociation scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor ; 戻り値は stat
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "sptr"
; profileName : LPCWSTR -> "sptr"
; targetAdapterID : LUID -> "sptr"
; sourceID : DWORD -> "sptr"
; setAsDefault : BOOL -> "sptr"
; associateAsAdvancedColor : BOOL -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "mscms.dll"
#cfunc global ColorProfileAddDisplayAssociation "ColorProfileAddDisplayAssociation" int, wstr, int, int, int, int
; res = ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
; profileName : LPCWSTR -> "wstr"
; targetAdapterID : LUID -> "int"
; sourceID : DWORD -> "int"
; setAsDefault : BOOL -> "int"
; associateAsAdvancedColor : BOOL -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。; HRESULT ColorProfileAddDisplayAssociation(WCS_PROFILE_MANAGEMENT_SCOPE scope, LPCWSTR profileName, LUID targetAdapterID, DWORD sourceID, BOOL setAsDefault, BOOL associateAsAdvancedColor)
#uselib "mscms.dll"
#cfunc global ColorProfileAddDisplayAssociation "ColorProfileAddDisplayAssociation" int, wstr, int, int, int, int
; res = ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
; profileName : LPCWSTR -> "wstr"
; targetAdapterID : LUID -> "int"
; sourceID : DWORD -> "int"
; setAsDefault : BOOL -> "int"
; associateAsAdvancedColor : BOOL -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mscms = windows.NewLazySystemDLL("mscms.dll")
procColorProfileAddDisplayAssociation = mscms.NewProc("ColorProfileAddDisplayAssociation")
)
// scope (WCS_PROFILE_MANAGEMENT_SCOPE), profileName (LPCWSTR), targetAdapterID (LUID), sourceID (DWORD), setAsDefault (BOOL), associateAsAdvancedColor (BOOL)
r1, _, err := procColorProfileAddDisplayAssociation.Call(
uintptr(scope),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(profileName))),
uintptr(targetAdapterID),
uintptr(sourceID),
uintptr(setAsDefault),
uintptr(associateAsAdvancedColor),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction ColorProfileAddDisplayAssociation(
scope: Integer; // WCS_PROFILE_MANAGEMENT_SCOPE
profileName: PWideChar; // LPCWSTR
targetAdapterID: LUID; // LUID
sourceID: DWORD; // DWORD
setAsDefault: BOOL; // BOOL
associateAsAdvancedColor: BOOL // BOOL
): Integer; stdcall;
external 'mscms.dll' name 'ColorProfileAddDisplayAssociation';result := DllCall("mscms\ColorProfileAddDisplayAssociation"
, "Int", scope ; WCS_PROFILE_MANAGEMENT_SCOPE
, "WStr", profileName ; LPCWSTR
, "Ptr", targetAdapterID ; LUID
, "UInt", sourceID ; DWORD
, "Int", setAsDefault ; BOOL
, "Int", associateAsAdvancedColor ; BOOL
, "Int") ; return: HRESULT●ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor) = DLL("mscms.dll", "int ColorProfileAddDisplayAssociation(int, char*, void*, dword, bool, bool)")
# 呼び出し: ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
# profileName : LPCWSTR -> "char*"
# targetAdapterID : LUID -> "void*"
# sourceID : DWORD -> "dword"
# setAsDefault : BOOL -> "bool"
# associateAsAdvancedColor : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mscms" fn ColorProfileAddDisplayAssociation(
scope: i32, // WCS_PROFILE_MANAGEMENT_SCOPE
profileName: [*c]const u16, // LPCWSTR
targetAdapterID: LUID, // LUID
sourceID: u32, // DWORD
setAsDefault: i32, // BOOL
associateAsAdvancedColor: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;proc ColorProfileAddDisplayAssociation(
scope: int32, # WCS_PROFILE_MANAGEMENT_SCOPE
profileName: WideCString, # LPCWSTR
targetAdapterID: LUID, # LUID
sourceID: uint32, # DWORD
setAsDefault: int32, # BOOL
associateAsAdvancedColor: int32 # BOOL
): int32 {.importc: "ColorProfileAddDisplayAssociation", stdcall, dynlib: "mscms.dll".}pragma(lib, "mscms");
extern(Windows)
int ColorProfileAddDisplayAssociation(
int scope, // WCS_PROFILE_MANAGEMENT_SCOPE
const(wchar)* profileName, // LPCWSTR
LUID targetAdapterID, // LUID
uint sourceID, // DWORD
int setAsDefault, // BOOL
int associateAsAdvancedColor // BOOL
);ccall((:ColorProfileAddDisplayAssociation, "mscms.dll"), stdcall, Int32,
(Int32, Cwstring, LUID, UInt32, Int32, Int32),
scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
# profileName : LPCWSTR -> Cwstring
# targetAdapterID : LUID -> LUID
# sourceID : DWORD -> UInt32
# setAsDefault : BOOL -> Int32
# associateAsAdvancedColor : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ColorProfileAddDisplayAssociation(
int32_t scope,
const uint16_t* profileName,
LUID targetAdapterID,
uint32_t sourceID,
int32_t setAsDefault,
int32_t associateAsAdvancedColor);
]]
local mscms = ffi.load("mscms")
-- mscms.ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
-- scope : WCS_PROFILE_MANAGEMENT_SCOPE
-- profileName : LPCWSTR
-- targetAdapterID : LUID
-- sourceID : DWORD
-- setAsDefault : BOOL
-- associateAsAdvancedColor : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mscms.dll');
const ColorProfileAddDisplayAssociation = lib.func('__stdcall', 'ColorProfileAddDisplayAssociation', 'int32_t', ['int32_t', 'str16', 'LUID', 'uint32_t', 'int32_t', 'int32_t']);
// ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> 'int32_t'
// profileName : LPCWSTR -> 'str16'
// targetAdapterID : LUID -> 'LUID'
// sourceID : DWORD -> 'uint32_t'
// setAsDefault : BOOL -> 'int32_t'
// associateAsAdvancedColor : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mscms.dll", {
ColorProfileAddDisplayAssociation: { parameters: ["i32", "buffer", "buffer", "u32", "i32", "i32"], result: "i32" },
});
// lib.symbols.ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor)
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "i32"
// profileName : LPCWSTR -> "buffer"
// targetAdapterID : LUID -> "buffer"
// sourceID : DWORD -> "u32"
// setAsDefault : BOOL -> "i32"
// associateAsAdvancedColor : BOOL -> "i32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ColorProfileAddDisplayAssociation(
int32_t scope,
const uint16_t* profileName,
LUID targetAdapterID,
uint32_t sourceID,
int32_t setAsDefault,
int32_t associateAsAdvancedColor);
C, "mscms.dll");
// $ffi->ColorProfileAddDisplayAssociation(scope, profileName, targetAdapterID, sourceID, setAsDefault, associateAsAdvancedColor);
// scope : WCS_PROFILE_MANAGEMENT_SCOPE
// profileName : LPCWSTR
// targetAdapterID : LUID
// sourceID : DWORD
// setAsDefault : BOOL
// associateAsAdvancedColor : BOOL
// 構造体/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);
int ColorProfileAddDisplayAssociation(
int scope, // WCS_PROFILE_MANAGEMENT_SCOPE
WString profileName, // LPCWSTR
LUID /* extends Structure (by value) */ targetAdapterID, // LUID
int sourceID, // DWORD
boolean setAsDefault, // BOOL
boolean associateAsAdvancedColor // BOOL
);
}@[Link("mscms")]
lib Libmscms
fun ColorProfileAddDisplayAssociation = ColorProfileAddDisplayAssociation(
scope : Int32, # WCS_PROFILE_MANAGEMENT_SCOPE
profileName : UInt16*, # LPCWSTR
targetAdapterID : LUID, # LUID
sourceID : UInt32, # DWORD
setAsDefault : Int32, # BOOL
associateAsAdvancedColor : Int32 # BOOL
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ColorProfileAddDisplayAssociationNative = Int32 Function(Int32, Pointer<Utf16>, LUID, Uint32, Int32, Int32);
typedef ColorProfileAddDisplayAssociationDart = int Function(int, Pointer<Utf16>, int, int, int, int);
final ColorProfileAddDisplayAssociation = DynamicLibrary.open('mscms.dll')
.lookupFunction<ColorProfileAddDisplayAssociationNative, ColorProfileAddDisplayAssociationDart>('ColorProfileAddDisplayAssociation');
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
// profileName : LPCWSTR -> Pointer<Utf16>
// targetAdapterID : LUID -> LUID
// sourceID : DWORD -> Uint32
// setAsDefault : BOOL -> Int32
// associateAsAdvancedColor : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ColorProfileAddDisplayAssociation(
scope: Integer; // WCS_PROFILE_MANAGEMENT_SCOPE
profileName: PWideChar; // LPCWSTR
targetAdapterID: LUID; // LUID
sourceID: DWORD; // DWORD
setAsDefault: BOOL; // BOOL
associateAsAdvancedColor: BOOL // BOOL
): Integer; stdcall;
external 'mscms.dll' name 'ColorProfileAddDisplayAssociation';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ColorProfileAddDisplayAssociation"
c_ColorProfileAddDisplayAssociation :: Int32 -> CWString -> LUID -> Word32 -> CInt -> CInt -> IO Int32
-- scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
-- profileName : LPCWSTR -> CWString
-- targetAdapterID : LUID -> LUID
-- sourceID : DWORD -> Word32
-- setAsDefault : BOOL -> CInt
-- associateAsAdvancedColor : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let colorprofileadddisplayassociation =
foreign "ColorProfileAddDisplayAssociation"
(int32_t @-> (ptr uint16_t) @-> LUID @-> uint32_t @-> int32_t @-> int32_t @-> returning int32_t)
(* scope : WCS_PROFILE_MANAGEMENT_SCOPE -> int32_t *)
(* profileName : LPCWSTR -> (ptr uint16_t) *)
(* targetAdapterID : LUID -> LUID *)
(* sourceID : DWORD -> uint32_t *)
(* setAsDefault : BOOL -> int32_t *)
(* associateAsAdvancedColor : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mscms (t "mscms.dll"))
(cffi:use-foreign-library mscms)
(cffi:defcfun ("ColorProfileAddDisplayAssociation" color-profile-add-display-association :convention :stdcall) :int32
(scope :int32) ; WCS_PROFILE_MANAGEMENT_SCOPE
(profile-name (:string :encoding :utf-16le)) ; LPCWSTR
(target-adapter-id (:struct luid)) ; LUID
(source-id :uint32) ; DWORD
(set-as-default :int32) ; BOOL
(associate-as-advanced-color :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ColorProfileAddDisplayAssociation = Win32::API::More->new('mscms',
'int ColorProfileAddDisplayAssociation(int scope, LPCWSTR profileName, LPVOID targetAdapterID, DWORD sourceID, BOOL setAsDefault, BOOL associateAsAdvancedColor)');
# my $ret = $ColorProfileAddDisplayAssociation->Call($scope, $profileName, $targetAdapterID, $sourceID, $setAsDefault, $associateAsAdvancedColor);
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> int
# profileName : LPCWSTR -> LPCWSTR
# targetAdapterID : LUID -> LPVOID
# sourceID : DWORD -> DWORD
# setAsDefault : BOOL -> BOOL
# associateAsAdvancedColor : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。