ホーム › Graphics.Gdi › CreateEnhMetaFileW
CreateEnhMetaFileW
関数拡張メタファイル記録用のデバイスコンテキストを作成する(Unicode版)。
シグネチャ
// GDI32.dll (Unicode / -W)
#include <windows.h>
HDC CreateEnhMetaFileW(
HDC hdc, // optional
LPCWSTR lpFilename, // optional
const RECT* lprc, // optional
LPCWSTR lpDesc // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | inoptional |
| lpFilename | LPCWSTR | inoptional |
| lprc | RECT* | inoptional |
| lpDesc | LPCWSTR | inoptional |
戻り値の型: HDC
各言語での呼び出し定義
// GDI32.dll (Unicode / -W)
#include <windows.h>
HDC CreateEnhMetaFileW(
HDC hdc, // optional
LPCWSTR lpFilename, // optional
const RECT* lprc, // optional
LPCWSTR lpDesc // optional
);[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr CreateEnhMetaFileW(
IntPtr hdc, // HDC optional
[MarshalAs(UnmanagedType.LPWStr)] string lpFilename, // LPCWSTR optional
IntPtr lprc, // RECT* optional
[MarshalAs(UnmanagedType.LPWStr)] string lpDesc // LPCWSTR optional
);<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CreateEnhMetaFileW(
hdc As IntPtr, ' HDC optional
<MarshalAs(UnmanagedType.LPWStr)> lpFilename As String, ' LPCWSTR optional
lprc As IntPtr, ' RECT* optional
<MarshalAs(UnmanagedType.LPWStr)> lpDesc As String ' LPCWSTR optional
) As IntPtr
End Function' hdc : HDC optional
' lpFilename : LPCWSTR optional
' lprc : RECT* optional
' lpDesc : LPCWSTR optional
Declare PtrSafe Function CreateEnhMetaFileW Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal lpFilename As LongPtr, _
ByVal lprc As LongPtr, _
ByVal lpDesc As LongPtr) As LongPtr
' 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
CreateEnhMetaFileW = ctypes.windll.gdi32.CreateEnhMetaFileW
CreateEnhMetaFileW.restype = ctypes.c_void_p
CreateEnhMetaFileW.argtypes = [
wintypes.HANDLE, # hdc : HDC optional
wintypes.LPCWSTR, # lpFilename : LPCWSTR optional
ctypes.c_void_p, # lprc : RECT* optional
wintypes.LPCWSTR, # lpDesc : LPCWSTR optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
CreateEnhMetaFileW = Fiddle::Function.new(
lib['CreateEnhMetaFileW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC optional
Fiddle::TYPE_VOIDP, # lpFilename : LPCWSTR optional
Fiddle::TYPE_VOIDP, # lprc : RECT* optional
Fiddle::TYPE_VOIDP, # lpDesc : LPCWSTR optional
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "gdi32")]
extern "system" {
fn CreateEnhMetaFileW(
hdc: *mut core::ffi::c_void, // HDC optional
lpFilename: *const u16, // LPCWSTR optional
lprc: *const RECT, // RECT* optional
lpDesc: *const u16 // LPCWSTR optional
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr CreateEnhMetaFileW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpFilename, IntPtr lprc, [MarshalAs(UnmanagedType.LPWStr)] string lpDesc);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_CreateEnhMetaFileW' -Namespace Win32 -PassThru
# $api::CreateEnhMetaFileW(hdc, lpFilename, lprc, lpDesc)#uselib "GDI32.dll"
#func global CreateEnhMetaFileW "CreateEnhMetaFileW" wptr, wptr, wptr, wptr
; CreateEnhMetaFileW hdc, lpFilename, varptr(lprc), lpDesc ; 戻り値は stat
; hdc : HDC optional -> "wptr"
; lpFilename : LPCWSTR optional -> "wptr"
; lprc : RECT* optional -> "wptr"
; lpDesc : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global CreateEnhMetaFileW "CreateEnhMetaFileW" sptr, wstr, var, wstr ; res = CreateEnhMetaFileW(hdc, lpFilename, lprc, lpDesc) ; hdc : HDC optional -> "sptr" ; lpFilename : LPCWSTR optional -> "wstr" ; lprc : RECT* optional -> "var" ; lpDesc : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global CreateEnhMetaFileW "CreateEnhMetaFileW" sptr, wstr, sptr, wstr ; res = CreateEnhMetaFileW(hdc, lpFilename, varptr(lprc), lpDesc) ; hdc : HDC optional -> "sptr" ; lpFilename : LPCWSTR optional -> "wstr" ; lprc : RECT* optional -> "sptr" ; lpDesc : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HDC CreateEnhMetaFileW(HDC hdc, LPCWSTR lpFilename, RECT* lprc, LPCWSTR lpDesc) #uselib "GDI32.dll" #cfunc global CreateEnhMetaFileW "CreateEnhMetaFileW" intptr, wstr, var, wstr ; res = CreateEnhMetaFileW(hdc, lpFilename, lprc, lpDesc) ; hdc : HDC optional -> "intptr" ; lpFilename : LPCWSTR optional -> "wstr" ; lprc : RECT* optional -> "var" ; lpDesc : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HDC CreateEnhMetaFileW(HDC hdc, LPCWSTR lpFilename, RECT* lprc, LPCWSTR lpDesc) #uselib "GDI32.dll" #cfunc global CreateEnhMetaFileW "CreateEnhMetaFileW" intptr, wstr, intptr, wstr ; res = CreateEnhMetaFileW(hdc, lpFilename, varptr(lprc), lpDesc) ; hdc : HDC optional -> "intptr" ; lpFilename : LPCWSTR optional -> "wstr" ; lprc : RECT* optional -> "intptr" ; lpDesc : LPCWSTR optional -> "wstr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procCreateEnhMetaFileW = gdi32.NewProc("CreateEnhMetaFileW")
)
// hdc (HDC optional), lpFilename (LPCWSTR optional), lprc (RECT* optional), lpDesc (LPCWSTR optional)
r1, _, err := procCreateEnhMetaFileW.Call(
uintptr(hdc),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFilename))),
uintptr(lprc),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpDesc))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HDCfunction CreateEnhMetaFileW(
hdc: THandle; // HDC optional
lpFilename: PWideChar; // LPCWSTR optional
lprc: Pointer; // RECT* optional
lpDesc: PWideChar // LPCWSTR optional
): THandle; stdcall;
external 'GDI32.dll' name 'CreateEnhMetaFileW';result := DllCall("GDI32\CreateEnhMetaFileW"
, "Ptr", hdc ; HDC optional
, "WStr", lpFilename ; LPCWSTR optional
, "Ptr", lprc ; RECT* optional
, "WStr", lpDesc ; LPCWSTR optional
, "Ptr") ; return: HDC●CreateEnhMetaFileW(hdc, lpFilename, lprc, lpDesc) = DLL("GDI32.dll", "void* CreateEnhMetaFileW(void*, char*, void*, char*)")
# 呼び出し: CreateEnhMetaFileW(hdc, lpFilename, lprc, lpDesc)
# hdc : HDC optional -> "void*"
# lpFilename : LPCWSTR optional -> "char*"
# lprc : RECT* optional -> "void*"
# lpDesc : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。