ホーム › Graphics.Printing › GetFormW
GetFormW
関数指定した用紙フォームの情報を取得する。
シグネチャ
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL GetFormW(
PRINTER_HANDLE hPrinter,
LPCWSTR pFormName,
DWORD Level,
BYTE* pForm, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hPrinter | PRINTER_HANDLE | in | フォーム情報を取得する対象プリンターのハンドル。 |
| pFormName | LPCWSTR | in | 取得するフォームの名前を指すポインタ。 |
| Level | DWORD | in | 取得するFORM_INFO構造体のレベル。1または2を指定する。 |
| pForm | BYTE* | outoptional | フォーム情報を受け取るバッファへのポインタ。 |
| cbBuf | DWORD | in | pFormバッファのサイズ(バイト単位)。 |
| pcbNeeded | DWORD* | out | 必要なバイト数を受け取る変数へのポインタ。 |
戻り値の型: BOOL
各言語での呼び出し定義
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL GetFormW(
PRINTER_HANDLE hPrinter,
LPCWSTR pFormName,
DWORD Level,
BYTE* pForm, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetFormW(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
[MarshalAs(UnmanagedType.LPWStr)] string pFormName, // LPCWSTR
uint Level, // DWORD
IntPtr pForm, // BYTE* optional, out
uint cbBuf, // DWORD
out uint pcbNeeded // DWORD* out
);<DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetFormW(
hPrinter As PRINTER_HANDLE, ' PRINTER_HANDLE
<MarshalAs(UnmanagedType.LPWStr)> pFormName As String, ' LPCWSTR
Level As UInteger, ' DWORD
pForm As IntPtr, ' BYTE* optional, out
cbBuf As UInteger, ' DWORD
<Out> ByRef pcbNeeded As UInteger ' DWORD* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hPrinter : PRINTER_HANDLE
' pFormName : LPCWSTR
' Level : DWORD
' pForm : BYTE* optional, out
' cbBuf : DWORD
' pcbNeeded : DWORD* out
Declare PtrSafe Function GetFormW Lib "winspool.drv" ( _
ByVal hPrinter As LongPtr, _
ByVal pFormName As LongPtr, _
ByVal Level As Long, _
ByVal pForm As LongPtr, _
ByVal cbBuf As Long, _
ByRef pcbNeeded As Long) As Long
' 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
GetFormW = ctypes.windll.LoadLibrary("winspool.drv").GetFormW
GetFormW.restype = wintypes.BOOL
GetFormW.argtypes = [
PRINTER_HANDLE, # hPrinter : PRINTER_HANDLE
wintypes.LPCWSTR, # pFormName : LPCWSTR
wintypes.DWORD, # Level : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pForm : BYTE* optional, out
wintypes.DWORD, # cbBuf : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbNeeded : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winspool.drv')
GetFormW = Fiddle::Function.new(
lib['GetFormW'],
[
Fiddle::TYPE_VOIDP, # hPrinter : PRINTER_HANDLE
Fiddle::TYPE_VOIDP, # pFormName : LPCWSTR
-Fiddle::TYPE_INT, # Level : DWORD
Fiddle::TYPE_VOIDP, # pForm : BYTE* optional, out
-Fiddle::TYPE_INT, # cbBuf : DWORD
Fiddle::TYPE_VOIDP, # pcbNeeded : DWORD* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winspool.drv")]
extern "system" {
fn GetFormW(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
pFormName: *const u16, // LPCWSTR
Level: u32, // DWORD
pForm: *mut u8, // BYTE* optional, out
cbBuf: u32, // DWORD
pcbNeeded: *mut u32 // DWORD* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode)]
public static extern bool GetFormW(PRINTER_HANDLE hPrinter, [MarshalAs(UnmanagedType.LPWStr)] string pFormName, uint Level, IntPtr pForm, uint cbBuf, out uint pcbNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_GetFormW' -Namespace Win32 -PassThru
# $api::GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)#uselib "winspool.drv"
#func global GetFormW "GetFormW" wptr, wptr, wptr, wptr, wptr, wptr
; GetFormW hPrinter, pFormName, Level, varptr(pForm), cbBuf, varptr(pcbNeeded) ; 戻り値は stat
; hPrinter : PRINTER_HANDLE -> "wptr"
; pFormName : LPCWSTR -> "wptr"
; Level : DWORD -> "wptr"
; pForm : BYTE* optional, out -> "wptr"
; cbBuf : DWORD -> "wptr"
; pcbNeeded : DWORD* out -> "wptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "winspool.drv" #cfunc global GetFormW "GetFormW" int, wstr, int, var, int, var ; res = GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded) ; hPrinter : PRINTER_HANDLE -> "int" ; pFormName : LPCWSTR -> "wstr" ; Level : DWORD -> "int" ; pForm : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "winspool.drv" #cfunc global GetFormW "GetFormW" int, wstr, int, sptr, int, sptr ; res = GetFormW(hPrinter, pFormName, Level, varptr(pForm), cbBuf, varptr(pcbNeeded)) ; hPrinter : PRINTER_HANDLE -> "int" ; pFormName : LPCWSTR -> "wstr" ; Level : DWORD -> "int" ; pForm : BYTE* optional, out -> "sptr" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "sptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetFormW(PRINTER_HANDLE hPrinter, LPCWSTR pFormName, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetFormW "GetFormW" int, wstr, int, var, int, var ; res = GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded) ; hPrinter : PRINTER_HANDLE -> "int" ; pFormName : LPCWSTR -> "wstr" ; Level : DWORD -> "int" ; pForm : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetFormW(PRINTER_HANDLE hPrinter, LPCWSTR pFormName, DWORD Level, BYTE* pForm, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetFormW "GetFormW" int, wstr, int, intptr, int, intptr ; res = GetFormW(hPrinter, pFormName, Level, varptr(pForm), cbBuf, varptr(pcbNeeded)) ; hPrinter : PRINTER_HANDLE -> "int" ; pFormName : LPCWSTR -> "wstr" ; Level : DWORD -> "int" ; pForm : BYTE* optional, out -> "intptr" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "intptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winspool_drv = windows.NewLazySystemDLL("winspool.drv")
procGetFormW = winspool_drv.NewProc("GetFormW")
)
// hPrinter (PRINTER_HANDLE), pFormName (LPCWSTR), Level (DWORD), pForm (BYTE* optional, out), cbBuf (DWORD), pcbNeeded (DWORD* out)
r1, _, err := procGetFormW.Call(
uintptr(hPrinter),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pFormName))),
uintptr(Level),
uintptr(pForm),
uintptr(cbBuf),
uintptr(pcbNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetFormW(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
pFormName: PWideChar; // LPCWSTR
Level: DWORD; // DWORD
pForm: Pointer; // BYTE* optional, out
cbBuf: DWORD; // DWORD
pcbNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'winspool.drv' name 'GetFormW';result := DllCall("winspool.drv\GetFormW"
, "Ptr", hPrinter ; PRINTER_HANDLE
, "WStr", pFormName ; LPCWSTR
, "UInt", Level ; DWORD
, "Ptr", pForm ; BYTE* optional, out
, "UInt", cbBuf ; DWORD
, "Ptr", pcbNeeded ; DWORD* out
, "Int") ; return: BOOL●GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded) = DLL("winspool.drv", "bool GetFormW(void*, char*, dword, void*, dword, void*)")
# 呼び出し: GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)
# hPrinter : PRINTER_HANDLE -> "void*"
# pFormName : LPCWSTR -> "char*"
# Level : DWORD -> "dword"
# pForm : BYTE* optional, out -> "void*"
# cbBuf : DWORD -> "dword"
# pcbNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "winspool.drv" fn GetFormW(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
pFormName: [*c]const u16, // LPCWSTR
Level: u32, // DWORD
pForm: [*c]u8, // BYTE* optional, out
cbBuf: u32, // DWORD
pcbNeeded: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetFormW(
hPrinter: PRINTER_HANDLE, # PRINTER_HANDLE
pFormName: WideCString, # LPCWSTR
Level: uint32, # DWORD
pForm: ptr uint8, # BYTE* optional, out
cbBuf: uint32, # DWORD
pcbNeeded: ptr uint32 # DWORD* out
): int32 {.importc: "GetFormW", stdcall, dynlib: "winspool.drv".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "winspool.drv");
extern(Windows)
int GetFormW(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
const(wchar)* pFormName, // LPCWSTR
uint Level, // DWORD
ubyte* pForm, // BYTE* optional, out
uint cbBuf, // DWORD
uint* pcbNeeded // DWORD* out
);ccall((:GetFormW, "winspool.drv"), stdcall, Int32,
(PRINTER_HANDLE, Cwstring, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)
# hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
# pFormName : LPCWSTR -> Cwstring
# Level : DWORD -> UInt32
# pForm : BYTE* optional, out -> Ptr{UInt8}
# cbBuf : DWORD -> UInt32
# pcbNeeded : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GetFormW(
PRINTER_HANDLE hPrinter,
const uint16_t* pFormName,
uint32_t Level,
uint8_t* pForm,
uint32_t cbBuf,
uint32_t* pcbNeeded);
]]
local winspool.drv = ffi.load("winspool.drv")
-- winspool.drv.GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)
-- hPrinter : PRINTER_HANDLE
-- pFormName : LPCWSTR
-- Level : DWORD
-- pForm : BYTE* optional, out
-- cbBuf : DWORD
-- pcbNeeded : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('winspool.drv');
const GetFormW = lib.func('__stdcall', 'GetFormW', 'int32_t', ['PRINTER_HANDLE', 'str16', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *']);
// GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)
// hPrinter : PRINTER_HANDLE -> 'PRINTER_HANDLE'
// pFormName : LPCWSTR -> 'str16'
// Level : DWORD -> 'uint32_t'
// pForm : BYTE* optional, out -> 'uint8_t *'
// cbBuf : DWORD -> 'uint32_t'
// pcbNeeded : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winspool.drv", {
GetFormW: { parameters: ["buffer", "buffer", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded)
// hPrinter : PRINTER_HANDLE -> "buffer"
// pFormName : LPCWSTR -> "buffer"
// Level : DWORD -> "u32"
// pForm : BYTE* optional, out -> "pointer"
// cbBuf : DWORD -> "u32"
// pcbNeeded : DWORD* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetFormW(
PRINTER_HANDLE hPrinter,
const uint16_t* pFormName,
uint32_t Level,
uint8_t* pForm,
uint32_t cbBuf,
uint32_t* pcbNeeded);
C, "winspool.drv");
// $ffi->GetFormW(hPrinter, pFormName, Level, pForm, cbBuf, pcbNeeded);
// hPrinter : PRINTER_HANDLE
// pFormName : LPCWSTR
// Level : DWORD
// pForm : BYTE* optional, out
// cbBuf : DWORD
// pcbNeeded : DWORD* 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 Winspool.drv extends StdCallLibrary {
Winspool.drv INSTANCE = Native.load("winspool.drv", Winspool.drv.class, W32APIOptions.UNICODE_OPTIONS);
boolean GetFormW(
PRINTER_HANDLE /* extends Structure (by value) */ hPrinter, // PRINTER_HANDLE
WString pFormName, // LPCWSTR
int Level, // DWORD
byte[] pForm, // BYTE* optional, out
int cbBuf, // DWORD
IntByReference pcbNeeded // DWORD* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("winspool.drv")]
lib Libwinspool.drv
fun GetFormW = GetFormW(
hPrinter : PRINTER_HANDLE, # PRINTER_HANDLE
pFormName : UInt16*, # LPCWSTR
Level : UInt32, # DWORD
pForm : UInt8*, # BYTE* optional, out
cbBuf : UInt32, # DWORD
pcbNeeded : UInt32* # DWORD* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetFormWNative = Int32 Function(PRINTER_HANDLE, Pointer<Utf16>, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>);
typedef GetFormWDart = int Function(int, Pointer<Utf16>, int, Pointer<Uint8>, int, Pointer<Uint32>);
final GetFormW = DynamicLibrary.open('winspool.drv')
.lookupFunction<GetFormWNative, GetFormWDart>('GetFormW');
// hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
// pFormName : LPCWSTR -> Pointer<Utf16>
// Level : DWORD -> Uint32
// pForm : BYTE* optional, out -> Pointer<Uint8>
// cbBuf : DWORD -> Uint32
// pcbNeeded : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetFormW(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
pFormName: PWideChar; // LPCWSTR
Level: DWORD; // DWORD
pForm: Pointer; // BYTE* optional, out
cbBuf: DWORD; // DWORD
pcbNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'winspool.drv' name 'GetFormW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetFormW"
c_GetFormW :: PRINTER_HANDLE -> CWString -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> IO CInt
-- hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
-- pFormName : LPCWSTR -> CWString
-- Level : DWORD -> Word32
-- pForm : BYTE* optional, out -> Ptr Word8
-- cbBuf : DWORD -> Word32
-- pcbNeeded : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let getformw =
foreign "GetFormW"
(PRINTER_HANDLE @-> (ptr uint16_t) @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE *)
(* pFormName : LPCWSTR -> (ptr uint16_t) *)
(* Level : DWORD -> uint32_t *)
(* pForm : BYTE* optional, out -> (ptr uint8_t) *)
(* cbBuf : DWORD -> uint32_t *)
(* pcbNeeded : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winspool.drv (t "winspool.drv"))
(cffi:use-foreign-library winspool.drv)
(cffi:defcfun ("GetFormW" get-form-w :convention :stdcall) :int32
(h-printer (:struct printer-handle)) ; PRINTER_HANDLE
(p-form-name (:string :encoding :utf-16le)) ; LPCWSTR
(level :uint32) ; DWORD
(p-form :pointer) ; BYTE* optional, out
(cb-buf :uint32) ; DWORD
(pcb-needed :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetFormW = Win32::API::More->new('winspool.drv',
'BOOL GetFormW(LPVOID hPrinter, LPCWSTR pFormName, DWORD Level, LPVOID pForm, DWORD cbBuf, LPVOID pcbNeeded)');
# my $ret = $GetFormW->Call($hPrinter, $pFormName, $Level, $pForm, $cbBuf, $pcbNeeded);
# hPrinter : PRINTER_HANDLE -> LPVOID
# pFormName : LPCWSTR -> LPCWSTR
# Level : DWORD -> DWORD
# pForm : BYTE* optional, out -> LPVOID
# cbBuf : DWORD -> DWORD
# pcbNeeded : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GetFormA (ANSI版) — 指定した用紙フォームの情報を取得する。
使用する型