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

ExtEscape

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

シグネチャ

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

INT ExtEscape(
    HDC hdc,
    INT iEscape,
    INT cjInput,
    LPCSTR lpInData,   // optional
    INT cjOutput,
    LPSTR lpOutData   // optional
);

パラメーター

名前方向説明
hdcHDCin対象のデバイスコンテキストのハンドル。ドライバへ拡張エスケープを送る。
iEscapeINTin実行する拡張エスケープ機能を示す整数コード。
cjInputINTinlpInDataが指す入力データのサイズをバイト単位で指定する。
lpInDataLPCSTRinoptionalエスケープへ渡す入力データへのポインタ。
cjOutputINTinlpOutDataバッファのサイズをバイト単位で指定する。
lpOutDataLPSTRoutoptionalエスケープからの出力データを受け取るバッファへのポインタ。不要時はNULL可。

戻り値の型: INT

各言語での呼び出し定義

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

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

ExtEscape = ctypes.windll.gdi32.ExtEscape
ExtEscape.restype = ctypes.c_int
ExtEscape.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # iEscape : INT
    ctypes.c_int,  # cjInput : INT
    wintypes.LPCSTR,  # lpInData : LPCSTR optional
    ctypes.c_int,  # cjOutput : INT
    wintypes.LPSTR,  # lpOutData : LPSTR optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procExtEscape = gdi32.NewProc("ExtEscape")
)

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

extern "gdi32" fn ExtEscape(
    hdc: ?*anyopaque, // HDC
    iEscape: i32, // INT
    cjInput: i32, // INT
    lpInData: [*c]const u8, // LPCSTR optional
    cjOutput: i32, // INT
    lpOutData: [*c]u8 // LPSTR optional, out
) callconv(std.os.windows.WINAPI) i32;
proc ExtEscape(
    hdc: pointer,  # HDC
    iEscape: int32,  # INT
    cjInput: int32,  # INT
    lpInData: cstring,  # LPCSTR optional
    cjOutput: int32,  # INT
    lpOutData: ptr char  # LPSTR optional, out
): int32 {.importc: "ExtEscape", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int ExtEscape(
    void* hdc,   // HDC
    int iEscape,   // INT
    int cjInput,   // INT
    const(char)* lpInData,   // LPCSTR optional
    int cjOutput,   // INT
    char* lpOutData   // LPSTR optional, out
);
ccall((:ExtEscape, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Int32, Cstring, Int32, Ptr{UInt8}),
      hdc, iEscape, cjInput, lpInData, cjOutput, lpOutData)
# hdc : HDC -> Ptr{Cvoid}
# iEscape : INT -> Int32
# cjInput : INT -> Int32
# lpInData : LPCSTR optional -> Cstring
# cjOutput : INT -> Int32
# lpOutData : LPSTR optional, out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ExtEscape(
    void* hdc,
    int32_t iEscape,
    int32_t cjInput,
    const char* lpInData,
    int32_t cjOutput,
    char* lpOutData);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.ExtEscape(hdc, iEscape, cjInput, lpInData, cjOutput, lpOutData)
-- hdc : HDC
-- iEscape : INT
-- cjInput : INT
-- lpInData : LPCSTR optional
-- cjOutput : INT
-- lpOutData : LPSTR optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const ExtEscape = lib.func('__stdcall', 'ExtEscape', 'int32_t', ['void *', 'int32_t', 'int32_t', 'str', 'int32_t', 'char *']);
// ExtEscape(hdc, iEscape, cjInput, lpInData, cjOutput, lpOutData)
// hdc : HDC -> 'void *'
// iEscape : INT -> 'int32_t'
// cjInput : INT -> 'int32_t'
// lpInData : LPCSTR optional -> 'str'
// cjOutput : INT -> 'int32_t'
// lpOutData : LPSTR optional, out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  ExtEscape: { parameters: ["pointer", "i32", "i32", "buffer", "i32", "buffer"], result: "i32" },
});
// lib.symbols.ExtEscape(hdc, iEscape, cjInput, lpInData, cjOutput, lpOutData)
// hdc : HDC -> "pointer"
// iEscape : INT -> "i32"
// cjInput : INT -> "i32"
// lpInData : LPCSTR optional -> "buffer"
// cjOutput : INT -> "i32"
// lpOutData : LPSTR optional, out -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ExtEscape(
    void* hdc,
    int32_t iEscape,
    int32_t cjInput,
    const char* lpInData,
    int32_t cjOutput,
    char* lpOutData);
C, "GDI32.dll");
// $ffi->ExtEscape(hdc, iEscape, cjInput, lpInData, cjOutput, lpOutData);
// hdc : HDC
// iEscape : INT
// cjInput : INT
// lpInData : LPCSTR optional
// cjOutput : INT
// lpOutData : LPSTR 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 ExtEscape(
        Pointer hdc,   // HDC
        int iEscape,   // INT
        int cjInput,   // INT
        String lpInData,   // LPCSTR optional
        int cjOutput,   // INT
        byte[] lpOutData   // LPSTR optional, out
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun ExtEscape = ExtEscape(
    hdc : Void*,   # HDC
    iEscape : Int32,   # INT
    cjInput : Int32,   # INT
    lpInData : UInt8*,   # LPCSTR optional
    cjOutput : Int32,   # INT
    lpOutData : UInt8*   # LPSTR 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 ExtEscapeNative = Int32 Function(Pointer<Void>, Int32, Int32, Pointer<Utf8>, Int32, Pointer<Utf8>);
typedef ExtEscapeDart = int Function(Pointer<Void>, int, int, Pointer<Utf8>, int, Pointer<Utf8>);
final ExtEscape = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<ExtEscapeNative, ExtEscapeDart>('ExtEscape');
// hdc : HDC -> Pointer<Void>
// iEscape : INT -> Int32
// cjInput : INT -> Int32
// lpInData : LPCSTR optional -> Pointer<Utf8>
// cjOutput : INT -> Int32
// lpOutData : LPSTR optional, out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ExtEscape(
  hdc: THandle;   // HDC
  iEscape: Integer;   // INT
  cjInput: Integer;   // INT
  lpInData: PAnsiChar;   // LPCSTR optional
  cjOutput: Integer;   // INT
  lpOutData: PAnsiChar   // LPSTR optional, out
): Integer; stdcall;
  external 'GDI32.dll' name 'ExtEscape';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ExtEscape"
  c_ExtEscape :: Ptr () -> Int32 -> Int32 -> CString -> Int32 -> CString -> IO Int32
-- hdc : HDC -> Ptr ()
-- iEscape : INT -> Int32
-- cjInput : INT -> Int32
-- lpInData : LPCSTR optional -> CString
-- cjOutput : INT -> Int32
-- lpOutData : LPSTR optional, out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("ExtEscape" ext-escape :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (i-escape :int32)   ; INT
  (cj-input :int32)   ; INT
  (lp-in-data :string)   ; LPCSTR optional
  (cj-output :int32)   ; INT
  (lp-out-data :pointer))   ; LPSTR optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ExtEscape = Win32::API::More->new('GDI32',
    'int ExtEscape(HANDLE hdc, int iEscape, int cjInput, LPCSTR lpInData, int cjOutput, LPSTR lpOutData)');
# my $ret = $ExtEscape->Call($hdc, $iEscape, $cjInput, $lpInData, $cjOutput, $lpOutData);
# hdc : HDC -> HANDLE
# iEscape : INT -> int
# cjInput : INT -> int
# lpInData : LPCSTR optional -> LPCSTR
# cjOutput : INT -> int
# lpOutData : LPSTR optional, out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。