Win32 API 日本語リファレンス
ホームStorage.Xps › Escape

Escape

関数
デバイス固有の機能にアクセスするためのエスケープ命令を送る。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT Escape(
    HDC hdc,
    INT iEscape,
    INT cjIn,
    LPCSTR pvIn,   // optional
    void* pvOut   // optional
);

パラメーター

名前方向説明
hdcHDCin対象のデバイスコンテキストのハンドル。プリンター等のドライバへエスケープを送る。
iEscapeINTin実行するエスケープ機能を示す整数コード。STARTDOCやQUERYESCSUPPORTなどを指定する。
cjInINTinpvInが指す入力データのサイズをバイト単位で指定する。
pvInLPCSTRinoptionalエスケープへ渡す入力データへのポインタ。データ不要時はNULL可。
pvOutvoid*outoptionalエスケープからの出力データを受け取るバッファへのポインタ。不要時はNULL可。

戻り値の型: INT

各言語での呼び出し定義

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

INT Escape(
    HDC hdc,
    INT iEscape,
    INT cjIn,
    LPCSTR pvIn,   // optional
    void* pvOut   // optional
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int Escape(
    IntPtr hdc,   // HDC
    int iEscape,   // INT
    int cjIn,   // INT
    [MarshalAs(UnmanagedType.LPStr)] string pvIn,   // LPCSTR optional
    IntPtr pvOut   // void* optional, out
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function Escape(
    hdc As IntPtr,   ' HDC
    iEscape As Integer,   ' INT
    cjIn As Integer,   ' INT
    <MarshalAs(UnmanagedType.LPStr)> pvIn As String,   ' LPCSTR optional
    pvOut As IntPtr   ' void* optional, out
) As Integer
End Function
' hdc : HDC
' iEscape : INT
' cjIn : INT
' pvIn : LPCSTR optional
' pvOut : void* optional, out
Declare PtrSafe Function Escape Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal iEscape As Long, _
    ByVal cjIn As Long, _
    ByVal pvIn As String, _
    ByVal pvOut As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

Escape = ctypes.windll.gdi32.Escape
Escape.restype = ctypes.c_int
Escape.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iEscape : INT
    ctypes.c_int,  # cjIn : INT
    wintypes.LPCSTR,  # pvIn : LPCSTR optional
    ctypes.POINTER(None),  # pvOut : void* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procEscape = gdi32.NewProc("Escape")
)

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

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

typedef EscapeNative = Int32 Function(Pointer<Void>, Int32, Int32, Pointer<Utf8>, Pointer<Void>);
typedef EscapeDart = int Function(Pointer<Void>, int, int, Pointer<Utf8>, Pointer<Void>);
final Escape = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<EscapeNative, EscapeDart>('Escape');
// hdc : HDC -> Pointer<Void>
// iEscape : INT -> Int32
// cjIn : INT -> Int32
// pvIn : LPCSTR optional -> Pointer<Utf8>
// pvOut : void* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function Escape(
  hdc: THandle;   // HDC
  iEscape: Integer;   // INT
  cjIn: Integer;   // INT
  pvIn: PAnsiChar;   // LPCSTR optional
  pvOut: Pointer   // void* optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'Escape';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "Escape"
  c_Escape :: Ptr () -> Int32 -> Int32 -> CString -> Ptr () -> IO Int32
-- hdc : HDC -> Ptr ()
-- iEscape : INT -> Int32
-- cjIn : INT -> Int32
-- pvIn : LPCSTR optional -> CString
-- pvOut : void* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let escape =
  foreign "Escape"
    ((ptr void) @-> int32_t @-> int32_t @-> string @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* iEscape : INT -> int32_t *)
(* cjIn : INT -> int32_t *)
(* pvIn : LPCSTR optional -> string *)
(* pvOut : void* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("Escape" escape :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (i-escape :int32)   ; INT
  (cj-in :int32)   ; INT
  (pv-in :string)   ; LPCSTR optional
  (pv-out :pointer))   ; void* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $Escape = Win32::API::More->new('GDI32',
    'int Escape(HANDLE hdc, int iEscape, int cjIn, LPCSTR pvIn, LPVOID pvOut)');
# my $ret = $Escape->Call($hdc, $iEscape, $cjIn, $pvIn, $pvOut);
# hdc : HDC -> HANDLE
# iEscape : INT -> int
# cjIn : INT -> int
# pvIn : LPCSTR optional -> LPCSTR
# pvOut : void* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。