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

SetICMProfileA

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

シグネチャ

// GDI32.dll  (ANSI / -A)
#include <windows.h>

BOOL SetICMProfileA(
    HDC hdc,
    LPSTR lpFileName
);

パラメーター

名前方向説明
hdcHDCinICMプロファイルを設定する対象デバイスコンテキストのハンドル。
lpFileNameLPSTRin設定するICMカラープロファイルのファイルパス(ANSI)を表す文字列。

戻り値の型: BOOL

各言語での呼び出し定義

// GDI32.dll  (ANSI / -A)
#include <windows.h>

BOOL SetICMProfileA(
    HDC hdc,
    LPSTR lpFileName
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool SetICMProfileA(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPStr)] string lpFileName   // LPSTR
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SetICMProfileA(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPStr)> lpFileName As String   ' LPSTR
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hdc : HDC
' lpFileName : LPSTR
Declare PtrSafe Function SetICMProfileA Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpFileName As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetICMProfileA = ctypes.windll.gdi32.SetICMProfileA
SetICMProfileA.restype = wintypes.BOOL
SetICMProfileA.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCSTR,  # lpFileName : LPSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetICMProfileA = gdi32.NewProc("SetICMProfileA")
)

// hdc (HDC), lpFileName (LPSTR)
r1, _, err := procSetICMProfileA.Call(
	uintptr(hdc),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetICMProfileA(
  hdc: THandle;   // HDC
  lpFileName: PAnsiChar   // LPSTR
): BOOL; stdcall;
  external 'GDI32.dll' name 'SetICMProfileA';
result := DllCall("GDI32\SetICMProfileA"
    , "Ptr", hdc   ; HDC
    , "AStr", lpFileName   ; LPSTR
    , "Int")   ; return: BOOL
●SetICMProfileA(hdc, lpFileName) = DLL("GDI32.dll", "bool SetICMProfileA(void*, char*)")
# 呼び出し: SetICMProfileA(hdc, lpFileName)
# hdc : HDC -> "void*"
# lpFileName : LPSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn SetICMProfileA(
    hdc: ?*anyopaque, // HDC
    lpFileName: [*c]const u8 // LPSTR
) callconv(std.os.windows.WINAPI) i32;
proc SetICMProfileA(
    hdc: pointer,  # HDC
    lpFileName: cstring  # LPSTR
): int32 {.importc: "SetICMProfileA", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int SetICMProfileA(
    void* hdc,   // HDC
    const(char)* lpFileName   // LPSTR
);
ccall((:SetICMProfileA, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Cstring),
      hdc, lpFileName)
# hdc : HDC -> Ptr{Cvoid}
# lpFileName : LPSTR -> Cstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t SetICMProfileA(
    void* hdc,
    const char* lpFileName);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetICMProfileA(hdc, lpFileName)
-- hdc : HDC
-- lpFileName : LPSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetICMProfileA = lib.func('__stdcall', 'SetICMProfileA', 'int32_t', ['void *', 'str']);
// SetICMProfileA(hdc, lpFileName)
// hdc : HDC -> 'void *'
// lpFileName : LPSTR -> 'str'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  SetICMProfileA: { parameters: ["pointer", "buffer"], result: "i32" },
});
// lib.symbols.SetICMProfileA(hdc, lpFileName)
// hdc : HDC -> "pointer"
// lpFileName : LPSTR -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t SetICMProfileA(
    void* hdc,
    const char* lpFileName);
C, "GDI32.dll");
// $ffi->SetICMProfileA(hdc, lpFileName);
// hdc : HDC
// lpFileName : LPSTR
// 構造体/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 Gdi32 extends StdCallLibrary {
    Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class, W32APIOptions.ASCII_OPTIONS);
    boolean SetICMProfileA(
        Pointer hdc,   // HDC
        String lpFileName   // LPSTR
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun SetICMProfileA = SetICMProfileA(
    hdc : Void*,   # HDC
    lpFileName : UInt8*   # LPSTR
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef SetICMProfileANative = Int32 Function(Pointer<Void>, Pointer<Utf8>);
typedef SetICMProfileADart = int Function(Pointer<Void>, Pointer<Utf8>);
final SetICMProfileA = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<SetICMProfileANative, SetICMProfileADart>('SetICMProfileA');
// hdc : HDC -> Pointer<Void>
// lpFileName : LPSTR -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function SetICMProfileA(
  hdc: THandle;   // HDC
  lpFileName: PAnsiChar   // LPSTR
): BOOL; stdcall;
  external 'GDI32.dll' name 'SetICMProfileA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "SetICMProfileA"
  c_SetICMProfileA :: Ptr () -> CString -> IO CInt
-- hdc : HDC -> Ptr ()
-- lpFileName : LPSTR -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let seticmprofilea =
  foreign "SetICMProfileA"
    ((ptr void) @-> string @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* lpFileName : LPSTR -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("SetICMProfileA" set-icmprofile-a :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (lp-file-name :string))   ; LPSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $SetICMProfileA = Win32::API::More->new('GDI32',
    'BOOL SetICMProfileA(HANDLE hdc, LPCSTR lpFileName)');
# my $ret = $SetICMProfileA->Call($hdc, $lpFileName);
# hdc : HDC -> HANDLE
# lpFileName : LPSTR -> LPCSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い