Win32 API 日本語リファレンス
ホームGraphics.Gdi › CreateEnhMetaFileA

CreateEnhMetaFileA

関数
拡張メタファイル記録用のデバイスコンテキストを作成する(ANSI版)。
DLLGDI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HDC CreateEnhMetaFileA(
    HDC hdc,   // optional
    LPCSTR lpFilename,   // optional
    const RECT* lprc,   // optional
    LPCSTR lpDesc   // optional
);

パラメーター

名前方向
hdcHDCinoptional
lpFilenameLPCSTRinoptional
lprcRECT*inoptional
lpDescLPCSTRinoptional

戻り値の型: HDC

各言語での呼び出し定義

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

HDC CreateEnhMetaFileA(
    HDC hdc,   // optional
    LPCSTR lpFilename,   // optional
    const RECT* lprc,   // optional
    LPCSTR lpDesc   // optional
);
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern IntPtr CreateEnhMetaFileA(
    IntPtr hdc,   // HDC optional
    [MarshalAs(UnmanagedType.LPStr)] string lpFilename,   // LPCSTR optional
    IntPtr lprc,   // RECT* optional
    [MarshalAs(UnmanagedType.LPStr)] string lpDesc   // LPCSTR optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function CreateEnhMetaFileA(
    hdc As IntPtr,   ' HDC optional
    <MarshalAs(UnmanagedType.LPStr)> lpFilename As String,   ' LPCSTR optional
    lprc As IntPtr,   ' RECT* optional
    <MarshalAs(UnmanagedType.LPStr)> lpDesc As String   ' LPCSTR optional
) As IntPtr
End Function
' hdc : HDC optional
' lpFilename : LPCSTR optional
' lprc : RECT* optional
' lpDesc : LPCSTR optional
Declare PtrSafe Function CreateEnhMetaFileA Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpFilename As String, _
    ByVal lprc As LongPtr, _
    ByVal lpDesc As String) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateEnhMetaFileA = ctypes.windll.gdi32.CreateEnhMetaFileA
CreateEnhMetaFileA.restype = ctypes.c_void_p
CreateEnhMetaFileA.argtypes = [
    wintypes.HANDLE,  # hdc : HDC optional
    wintypes.LPCSTR,  # lpFilename : LPCSTR optional
    ctypes.c_void_p,  # lprc : RECT* optional
    wintypes.LPCSTR,  # lpDesc : LPCSTR optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
CreateEnhMetaFileA = Fiddle::Function.new(
  lib['CreateEnhMetaFileA'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC optional
    Fiddle::TYPE_VOIDP,  # lpFilename : LPCSTR optional
    Fiddle::TYPE_VOIDP,  # lprc : RECT* optional
    Fiddle::TYPE_VOIDP,  # lpDesc : LPCSTR optional
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "gdi32")]
extern "system" {
    fn CreateEnhMetaFileA(
        hdc: *mut core::ffi::c_void,  // HDC optional
        lpFilename: *const u8,  // LPCSTR optional
        lprc: *const RECT,  // RECT* optional
        lpDesc: *const u8  // LPCSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr CreateEnhMetaFileA(IntPtr hdc, [MarshalAs(UnmanagedType.LPStr)] string lpFilename, IntPtr lprc, [MarshalAs(UnmanagedType.LPStr)] string lpDesc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateEnhMetaFileA' -Namespace Win32 -PassThru
# $api::CreateEnhMetaFileA(hdc, lpFilename, lprc, lpDesc)
#uselib "GDI32.dll"
#func global CreateEnhMetaFileA "CreateEnhMetaFileA" sptr, sptr, sptr, sptr
; CreateEnhMetaFileA hdc, lpFilename, varptr(lprc), lpDesc   ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; lpFilename : LPCSTR optional -> "sptr"
; lprc : RECT* optional -> "sptr"
; lpDesc : LPCSTR optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global CreateEnhMetaFileA "CreateEnhMetaFileA" sptr, str, var, str
; res = CreateEnhMetaFileA(hdc, lpFilename, lprc, lpDesc)
; hdc : HDC optional -> "sptr"
; lpFilename : LPCSTR optional -> "str"
; lprc : RECT* optional -> "var"
; lpDesc : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HDC CreateEnhMetaFileA(HDC hdc, LPCSTR lpFilename, RECT* lprc, LPCSTR lpDesc)
#uselib "GDI32.dll"
#cfunc global CreateEnhMetaFileA "CreateEnhMetaFileA" intptr, str, var, str
; res = CreateEnhMetaFileA(hdc, lpFilename, lprc, lpDesc)
; hdc : HDC optional -> "intptr"
; lpFilename : LPCSTR optional -> "str"
; lprc : RECT* optional -> "var"
; lpDesc : LPCSTR optional -> "str"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateEnhMetaFileA = gdi32.NewProc("CreateEnhMetaFileA")
)

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