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

SetICMProfileW

関数
DCに使用するICMプロファイルを設定する(Unicode版)。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetICMProfileW(
    HDC hdc,
    LPWSTR lpFileName
);

パラメーター

名前方向
hdcHDCin
lpFileNameLPWSTRin

戻り値の型: BOOL

各言語での呼び出し定義

// GDI32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetICMProfileW(
    HDC hdc,
    LPWSTR lpFileName
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool SetICMProfileW(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName   // LPWSTR
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SetICMProfileW(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String   ' LPWSTR
) As Boolean
End Function
' hdc : HDC
' lpFileName : LPWSTR
Declare PtrSafe Function SetICMProfileW Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpFileName As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetICMProfileW = ctypes.windll.gdi32.SetICMProfileW
SetICMProfileW.restype = wintypes.BOOL
SetICMProfileW.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCWSTR,  # lpFileName : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
SetICMProfileW = Fiddle::Function.new(
  lib['SetICMProfileW'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpFileName : LPWSTR
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn SetICMProfileW(
        hdc: *mut core::ffi::c_void,  // HDC
        lpFileName: *mut u16  // LPWSTR
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern bool SetICMProfileW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpFileName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetICMProfileW' -Namespace Win32 -PassThru
# $api::SetICMProfileW(hdc, lpFileName)
#uselib "GDI32.dll"
#func global SetICMProfileW "SetICMProfileW" wptr, wptr
; SetICMProfileW hdc, lpFileName   ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpFileName : LPWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global SetICMProfileW "SetICMProfileW" sptr, wstr
; res = SetICMProfileW(hdc, lpFileName)
; hdc : HDC -> "sptr"
; lpFileName : LPWSTR -> "wstr"
; BOOL SetICMProfileW(HDC hdc, LPWSTR lpFileName)
#uselib "GDI32.dll"
#cfunc global SetICMProfileW "SetICMProfileW" intptr, wstr
; res = SetICMProfileW(hdc, lpFileName)
; hdc : HDC -> "intptr"
; lpFileName : LPWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetICMProfileW = gdi32.NewProc("SetICMProfileW")
)

// hdc (HDC), lpFileName (LPWSTR)
r1, _, err := procSetICMProfileW.Call(
	uintptr(hdc),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetICMProfileW(
  hdc: THandle;   // HDC
  lpFileName: PWideChar   // LPWSTR
): BOOL; stdcall;
  external 'GDI32.dll' name 'SetICMProfileW';
result := DllCall("GDI32\SetICMProfileW"
    , "Ptr", hdc   ; HDC
    , "WStr", lpFileName   ; LPWSTR
    , "Int")   ; return: BOOL
●SetICMProfileW(hdc, lpFileName) = DLL("GDI32.dll", "bool SetICMProfileW(void*, char*)")
# 呼び出し: SetICMProfileW(hdc, lpFileName)
# hdc : HDC -> "void*"
# lpFileName : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。