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

ColorProfileSetDisplayDefaultAssociation

関数
ディスプレイの既定カラープロファイルを設定する。
DLLmscms.dll呼出規約winapi

シグネチャ

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

HRESULT ColorProfileSetDisplayDefaultAssociation(
    WCS_PROFILE_MANAGEMENT_SCOPE scope,
    LPCWSTR profileName,
    COLORPROFILETYPE profileType,
    COLORPROFILESUBTYPE profileSubType,
    LUID targetAdapterID,
    DWORD sourceID
);

パラメーター

名前方向説明
scopeWCS_PROFILE_MANAGEMENT_SCOPEin操作対象の管理範囲(システム全体/現在ユーザー)を示すWCSスコープ列挙値。
profileNameLPCWSTRin既定に設定するカラープロファイル名を指すワイド文字列ポインタ。
profileTypeCOLORPROFILETYPEinプロファイルの種別(ICC/WCS等)を示す列挙値。
profileSubTypeCOLORPROFILESUBTYPEinプロファイルのサブ種別を示す列挙値。
targetAdapterIDLUIDin対象ディスプレイのアダプタを識別するLUID値。
sourceIDDWORDinアダプタ上の対象ソース(出力)を識別するID。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT ColorProfileSetDisplayDefaultAssociation(
    WCS_PROFILE_MANAGEMENT_SCOPE scope,
    LPCWSTR profileName,
    COLORPROFILETYPE profileType,
    COLORPROFILESUBTYPE profileSubType,
    LUID targetAdapterID,
    DWORD sourceID
);
[DllImport("mscms.dll", ExactSpelling = true)]
static extern int ColorProfileSetDisplayDefaultAssociation(
    int scope,   // WCS_PROFILE_MANAGEMENT_SCOPE
    [MarshalAs(UnmanagedType.LPWStr)] string profileName,   // LPCWSTR
    int profileType,   // COLORPROFILETYPE
    int profileSubType,   // COLORPROFILESUBTYPE
    LUID targetAdapterID,   // LUID
    uint sourceID   // DWORD
);
<DllImport("mscms.dll", ExactSpelling:=True)>
Public Shared Function ColorProfileSetDisplayDefaultAssociation(
    scope As Integer,   ' WCS_PROFILE_MANAGEMENT_SCOPE
    <MarshalAs(UnmanagedType.LPWStr)> profileName As String,   ' LPCWSTR
    profileType As Integer,   ' COLORPROFILETYPE
    profileSubType As Integer,   ' COLORPROFILESUBTYPE
    targetAdapterID As LUID,   ' LUID
    sourceID As UInteger   ' DWORD
) As Integer
End Function
' scope : WCS_PROFILE_MANAGEMENT_SCOPE
' profileName : LPCWSTR
' profileType : COLORPROFILETYPE
' profileSubType : COLORPROFILESUBTYPE
' targetAdapterID : LUID
' sourceID : DWORD
Declare PtrSafe Function ColorProfileSetDisplayDefaultAssociation Lib "mscms" ( _
    ByVal scope As Long, _
    ByVal profileName As LongPtr, _
    ByVal profileType As Long, _
    ByVal profileSubType As Long, _
    ByVal targetAdapterID As LongPtr, _
    ByVal sourceID As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ColorProfileSetDisplayDefaultAssociation = ctypes.windll.mscms.ColorProfileSetDisplayDefaultAssociation
ColorProfileSetDisplayDefaultAssociation.restype = ctypes.c_int
ColorProfileSetDisplayDefaultAssociation.argtypes = [
    ctypes.c_int,  # scope : WCS_PROFILE_MANAGEMENT_SCOPE
    wintypes.LPCWSTR,  # profileName : LPCWSTR
    ctypes.c_int,  # profileType : COLORPROFILETYPE
    ctypes.c_int,  # profileSubType : COLORPROFILESUBTYPE
    LUID,  # targetAdapterID : LUID
    wintypes.DWORD,  # sourceID : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mscms.dll')
ColorProfileSetDisplayDefaultAssociation = Fiddle::Function.new(
  lib['ColorProfileSetDisplayDefaultAssociation'],
  [
    Fiddle::TYPE_INT,  # scope : WCS_PROFILE_MANAGEMENT_SCOPE
    Fiddle::TYPE_VOIDP,  # profileName : LPCWSTR
    Fiddle::TYPE_INT,  # profileType : COLORPROFILETYPE
    Fiddle::TYPE_INT,  # profileSubType : COLORPROFILESUBTYPE
    Fiddle::TYPE_VOIDP,  # targetAdapterID : LUID
    -Fiddle::TYPE_INT,  # sourceID : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "mscms")]
extern "system" {
    fn ColorProfileSetDisplayDefaultAssociation(
        scope: i32,  // WCS_PROFILE_MANAGEMENT_SCOPE
        profileName: *const u16,  // LPCWSTR
        profileType: i32,  // COLORPROFILETYPE
        profileSubType: i32,  // COLORPROFILESUBTYPE
        targetAdapterID: LUID,  // LUID
        sourceID: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("mscms.dll")]
public static extern int ColorProfileSetDisplayDefaultAssociation(int scope, [MarshalAs(UnmanagedType.LPWStr)] string profileName, int profileType, int profileSubType, LUID targetAdapterID, uint sourceID);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mscms_ColorProfileSetDisplayDefaultAssociation' -Namespace Win32 -PassThru
# $api::ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
#uselib "mscms.dll"
#func global ColorProfileSetDisplayDefaultAssociation "ColorProfileSetDisplayDefaultAssociation" sptr, sptr, sptr, sptr, sptr, sptr
; ColorProfileSetDisplayDefaultAssociation scope, profileName, profileType, profileSubType, targetAdapterID, sourceID   ; 戻り値は stat
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "sptr"
; profileName : LPCWSTR -> "sptr"
; profileType : COLORPROFILETYPE -> "sptr"
; profileSubType : COLORPROFILESUBTYPE -> "sptr"
; targetAdapterID : LUID -> "sptr"
; sourceID : DWORD -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "mscms.dll"
#cfunc global ColorProfileSetDisplayDefaultAssociation "ColorProfileSetDisplayDefaultAssociation" int, wstr, int, int, int, int
; res = ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
; profileName : LPCWSTR -> "wstr"
; profileType : COLORPROFILETYPE -> "int"
; profileSubType : COLORPROFILESUBTYPE -> "int"
; targetAdapterID : LUID -> "int"
; sourceID : DWORD -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; HRESULT ColorProfileSetDisplayDefaultAssociation(WCS_PROFILE_MANAGEMENT_SCOPE scope, LPCWSTR profileName, COLORPROFILETYPE profileType, COLORPROFILESUBTYPE profileSubType, LUID targetAdapterID, DWORD sourceID)
#uselib "mscms.dll"
#cfunc global ColorProfileSetDisplayDefaultAssociation "ColorProfileSetDisplayDefaultAssociation" int, wstr, int, int, int, int
; res = ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
; scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
; profileName : LPCWSTR -> "wstr"
; profileType : COLORPROFILETYPE -> "int"
; profileSubType : COLORPROFILESUBTYPE -> "int"
; targetAdapterID : LUID -> "int"
; sourceID : DWORD -> "int"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mscms = windows.NewLazySystemDLL("mscms.dll")
	procColorProfileSetDisplayDefaultAssociation = mscms.NewProc("ColorProfileSetDisplayDefaultAssociation")
)

// scope (WCS_PROFILE_MANAGEMENT_SCOPE), profileName (LPCWSTR), profileType (COLORPROFILETYPE), profileSubType (COLORPROFILESUBTYPE), targetAdapterID (LUID), sourceID (DWORD)
r1, _, err := procColorProfileSetDisplayDefaultAssociation.Call(
	uintptr(scope),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(profileName))),
	uintptr(profileType),
	uintptr(profileSubType),
	uintptr(targetAdapterID),
	uintptr(sourceID),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ColorProfileSetDisplayDefaultAssociation(
  scope: Integer;   // WCS_PROFILE_MANAGEMENT_SCOPE
  profileName: PWideChar;   // LPCWSTR
  profileType: Integer;   // COLORPROFILETYPE
  profileSubType: Integer;   // COLORPROFILESUBTYPE
  targetAdapterID: LUID;   // LUID
  sourceID: DWORD   // DWORD
): Integer; stdcall;
  external 'mscms.dll' name 'ColorProfileSetDisplayDefaultAssociation';
result := DllCall("mscms\ColorProfileSetDisplayDefaultAssociation"
    , "Int", scope   ; WCS_PROFILE_MANAGEMENT_SCOPE
    , "WStr", profileName   ; LPCWSTR
    , "Int", profileType   ; COLORPROFILETYPE
    , "Int", profileSubType   ; COLORPROFILESUBTYPE
    , "Ptr", targetAdapterID   ; LUID
    , "UInt", sourceID   ; DWORD
    , "Int")   ; return: HRESULT
●ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID) = DLL("mscms.dll", "int ColorProfileSetDisplayDefaultAssociation(int, char*, int, int, void*, dword)")
# 呼び出し: ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "int"
# profileName : LPCWSTR -> "char*"
# profileType : COLORPROFILETYPE -> "int"
# profileSubType : COLORPROFILESUBTYPE -> "int"
# targetAdapterID : LUID -> "void*"
# sourceID : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mscms" fn ColorProfileSetDisplayDefaultAssociation(
    scope: i32, // WCS_PROFILE_MANAGEMENT_SCOPE
    profileName: [*c]const u16, // LPCWSTR
    profileType: i32, // COLORPROFILETYPE
    profileSubType: i32, // COLORPROFILESUBTYPE
    targetAdapterID: LUID, // LUID
    sourceID: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;
proc ColorProfileSetDisplayDefaultAssociation(
    scope: int32,  # WCS_PROFILE_MANAGEMENT_SCOPE
    profileName: WideCString,  # LPCWSTR
    profileType: int32,  # COLORPROFILETYPE
    profileSubType: int32,  # COLORPROFILESUBTYPE
    targetAdapterID: LUID,  # LUID
    sourceID: uint32  # DWORD
): int32 {.importc: "ColorProfileSetDisplayDefaultAssociation", stdcall, dynlib: "mscms.dll".}
pragma(lib, "mscms");
extern(Windows)
int ColorProfileSetDisplayDefaultAssociation(
    int scope,   // WCS_PROFILE_MANAGEMENT_SCOPE
    const(wchar)* profileName,   // LPCWSTR
    int profileType,   // COLORPROFILETYPE
    int profileSubType,   // COLORPROFILESUBTYPE
    LUID targetAdapterID,   // LUID
    uint sourceID   // DWORD
);
ccall((:ColorProfileSetDisplayDefaultAssociation, "mscms.dll"), stdcall, Int32,
      (Int32, Cwstring, Int32, Int32, LUID, UInt32),
      scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
# profileName : LPCWSTR -> Cwstring
# profileType : COLORPROFILETYPE -> Int32
# profileSubType : COLORPROFILESUBTYPE -> Int32
# targetAdapterID : LUID -> LUID
# sourceID : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ColorProfileSetDisplayDefaultAssociation(
    int32_t scope,
    const uint16_t* profileName,
    int32_t profileType,
    int32_t profileSubType,
    LUID targetAdapterID,
    uint32_t sourceID);
]]
local mscms = ffi.load("mscms")
-- mscms.ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
-- scope : WCS_PROFILE_MANAGEMENT_SCOPE
-- profileName : LPCWSTR
-- profileType : COLORPROFILETYPE
-- profileSubType : COLORPROFILESUBTYPE
-- targetAdapterID : LUID
-- sourceID : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('mscms.dll');
const ColorProfileSetDisplayDefaultAssociation = lib.func('__stdcall', 'ColorProfileSetDisplayDefaultAssociation', 'int32_t', ['int32_t', 'str16', 'int32_t', 'int32_t', 'LUID', 'uint32_t']);
// ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> 'int32_t'
// profileName : LPCWSTR -> 'str16'
// profileType : COLORPROFILETYPE -> 'int32_t'
// profileSubType : COLORPROFILESUBTYPE -> 'int32_t'
// targetAdapterID : LUID -> 'LUID'
// sourceID : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("mscms.dll", {
  ColorProfileSetDisplayDefaultAssociation: { parameters: ["i32", "buffer", "i32", "i32", "buffer", "u32"], result: "i32" },
});
// lib.symbols.ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID)
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> "i32"
// profileName : LPCWSTR -> "buffer"
// profileType : COLORPROFILETYPE -> "i32"
// profileSubType : COLORPROFILESUBTYPE -> "i32"
// targetAdapterID : LUID -> "buffer"
// sourceID : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ColorProfileSetDisplayDefaultAssociation(
    int32_t scope,
    const uint16_t* profileName,
    int32_t profileType,
    int32_t profileSubType,
    LUID targetAdapterID,
    uint32_t sourceID);
C, "mscms.dll");
// $ffi->ColorProfileSetDisplayDefaultAssociation(scope, profileName, profileType, profileSubType, targetAdapterID, sourceID);
// scope : WCS_PROFILE_MANAGEMENT_SCOPE
// profileName : LPCWSTR
// profileType : COLORPROFILETYPE
// profileSubType : COLORPROFILESUBTYPE
// targetAdapterID : LUID
// sourceID : DWORD
// 構造体/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 ColorProfileSetDisplayDefaultAssociation(
        int scope,   // WCS_PROFILE_MANAGEMENT_SCOPE
        WString profileName,   // LPCWSTR
        int profileType,   // COLORPROFILETYPE
        int profileSubType,   // COLORPROFILESUBTYPE
        LUID /* extends Structure (by value) */ targetAdapterID,   // LUID
        int sourceID   // DWORD
    );
}
@[Link("mscms")]
lib Libmscms
  fun ColorProfileSetDisplayDefaultAssociation = ColorProfileSetDisplayDefaultAssociation(
    scope : Int32,   # WCS_PROFILE_MANAGEMENT_SCOPE
    profileName : UInt16*,   # LPCWSTR
    profileType : Int32,   # COLORPROFILETYPE
    profileSubType : Int32,   # COLORPROFILESUBTYPE
    targetAdapterID : LUID,   # LUID
    sourceID : UInt32   # DWORD
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ColorProfileSetDisplayDefaultAssociationNative = Int32 Function(Int32, Pointer<Utf16>, Int32, Int32, LUID, Uint32);
typedef ColorProfileSetDisplayDefaultAssociationDart = int Function(int, Pointer<Utf16>, int, int, int, int);
final ColorProfileSetDisplayDefaultAssociation = DynamicLibrary.open('mscms.dll')
    .lookupFunction<ColorProfileSetDisplayDefaultAssociationNative, ColorProfileSetDisplayDefaultAssociationDart>('ColorProfileSetDisplayDefaultAssociation');
// scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
// profileName : LPCWSTR -> Pointer<Utf16>
// profileType : COLORPROFILETYPE -> Int32
// profileSubType : COLORPROFILESUBTYPE -> Int32
// targetAdapterID : LUID -> LUID
// sourceID : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ColorProfileSetDisplayDefaultAssociation(
  scope: Integer;   // WCS_PROFILE_MANAGEMENT_SCOPE
  profileName: PWideChar;   // LPCWSTR
  profileType: Integer;   // COLORPROFILETYPE
  profileSubType: Integer;   // COLORPROFILESUBTYPE
  targetAdapterID: LUID;   // LUID
  sourceID: DWORD   // DWORD
): Integer; stdcall;
  external 'mscms.dll' name 'ColorProfileSetDisplayDefaultAssociation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ColorProfileSetDisplayDefaultAssociation"
  c_ColorProfileSetDisplayDefaultAssociation :: Int32 -> CWString -> Int32 -> Int32 -> LUID -> Word32 -> IO Int32
-- scope : WCS_PROFILE_MANAGEMENT_SCOPE -> Int32
-- profileName : LPCWSTR -> CWString
-- profileType : COLORPROFILETYPE -> Int32
-- profileSubType : COLORPROFILESUBTYPE -> Int32
-- targetAdapterID : LUID -> LUID
-- sourceID : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let colorprofilesetdisplaydefaultassociation =
  foreign "ColorProfileSetDisplayDefaultAssociation"
    (int32_t @-> (ptr uint16_t) @-> int32_t @-> int32_t @-> LUID @-> uint32_t @-> returning int32_t)
(* scope : WCS_PROFILE_MANAGEMENT_SCOPE -> int32_t *)
(* profileName : LPCWSTR -> (ptr uint16_t) *)
(* profileType : COLORPROFILETYPE -> int32_t *)
(* profileSubType : COLORPROFILESUBTYPE -> int32_t *)
(* targetAdapterID : LUID -> LUID *)
(* sourceID : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mscms (t "mscms.dll"))
(cffi:use-foreign-library mscms)

(cffi:defcfun ("ColorProfileSetDisplayDefaultAssociation" color-profile-set-display-default-association :convention :stdcall) :int32
  (scope :int32)   ; WCS_PROFILE_MANAGEMENT_SCOPE
  (profile-name (:string :encoding :utf-16le))   ; LPCWSTR
  (profile-type :int32)   ; COLORPROFILETYPE
  (profile-sub-type :int32)   ; COLORPROFILESUBTYPE
  (target-adapter-id (:struct luid))   ; LUID
  (source-id :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ColorProfileSetDisplayDefaultAssociation = Win32::API::More->new('mscms',
    'int ColorProfileSetDisplayDefaultAssociation(int scope, LPCWSTR profileName, int profileType, int profileSubType, LPVOID targetAdapterID, DWORD sourceID)');
# my $ret = $ColorProfileSetDisplayDefaultAssociation->Call($scope, $profileName, $profileType, $profileSubType, $targetAdapterID, $sourceID);
# scope : WCS_PROFILE_MANAGEMENT_SCOPE -> int
# profileName : LPCWSTR -> LPCWSTR
# profileType : COLORPROFILETYPE -> int
# profileSubType : COLORPROFILESUBTYPE -> int
# targetAdapterID : LUID -> LPVOID
# sourceID : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型