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
cjInputINTin
lpInDataLPCSTRinoptional
cjOutputINTin
lpOutDataLPSTRoutoptional

戻り値の型: 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)。