ホーム › Graphics.Printing › GetJobA
GetJobA
関数指定した印刷ジョブの情報を取得する(ANSI版)。
シグネチャ
// winspool.drv (ANSI / -A)
#include <windows.h>
BOOL GetJobA(
PRINTER_HANDLE hPrinter,
DWORD JobId,
DWORD Level,
BYTE* pJob, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hPrinter | PRINTER_HANDLE | in | OpenPrinterで取得したプリンタのハンドル。 |
| JobId | DWORD | in | 情報を取得する印刷ジョブの識別子。 |
| Level | DWORD | in | 受け取るJOB_INFO構造体のレベル(1,2,3,4)。 |
| pJob | BYTE* | outoptional | ジョブ情報を受け取るバッファ(ANSI)へのポインタ。 |
| cbBuf | DWORD | in | pJobバッファのサイズ(バイト)。 |
| pcbNeeded | DWORD* | out | 必要または格納されたバイト数を受け取る出力。 |
戻り値の型: BOOL
各言語での呼び出し定義
// winspool.drv (ANSI / -A)
#include <windows.h>
BOOL GetJobA(
PRINTER_HANDLE hPrinter,
DWORD JobId,
DWORD Level,
BYTE* pJob, // optional
DWORD cbBuf,
DWORD* pcbNeeded
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool GetJobA(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
uint JobId, // DWORD
uint Level, // DWORD
IntPtr pJob, // BYTE* optional, out
uint cbBuf, // DWORD
out uint pcbNeeded // DWORD* out
);<DllImport("winspool.drv", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetJobA(
hPrinter As PRINTER_HANDLE, ' PRINTER_HANDLE
JobId As UInteger, ' DWORD
Level As UInteger, ' DWORD
pJob 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
' JobId : DWORD
' Level : DWORD
' pJob : BYTE* optional, out
' cbBuf : DWORD
' pcbNeeded : DWORD* out
Declare PtrSafe Function GetJobA Lib "winspool.drv" ( _
ByVal hPrinter As LongPtr, _
ByVal JobId As Long, _
ByVal Level As Long, _
ByVal pJob As LongPtr, _
ByVal cbBuf As Long, _
ByRef pcbNeeded As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetJobA = ctypes.windll.LoadLibrary("winspool.drv").GetJobA
GetJobA.restype = wintypes.BOOL
GetJobA.argtypes = [
PRINTER_HANDLE, # hPrinter : PRINTER_HANDLE
wintypes.DWORD, # JobId : DWORD
wintypes.DWORD, # Level : DWORD
ctypes.POINTER(ctypes.c_ubyte), # pJob : BYTE* optional, out
wintypes.DWORD, # cbBuf : DWORD
ctypes.POINTER(wintypes.DWORD), # pcbNeeded : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winspool.drv')
GetJobA = Fiddle::Function.new(
lib['GetJobA'],
[
Fiddle::TYPE_VOIDP, # hPrinter : PRINTER_HANDLE
-Fiddle::TYPE_INT, # JobId : DWORD
-Fiddle::TYPE_INT, # Level : DWORD
Fiddle::TYPE_VOIDP, # pJob : BYTE* optional, out
-Fiddle::TYPE_INT, # cbBuf : DWORD
Fiddle::TYPE_VOIDP, # pcbNeeded : DWORD* out
],
Fiddle::TYPE_INT)#[link(name = "winspool.drv")]
extern "system" {
fn GetJobA(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
JobId: u32, // DWORD
Level: u32, // DWORD
pJob: *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.Ansi)]
public static extern bool GetJobA(PRINTER_HANDLE hPrinter, uint JobId, uint Level, IntPtr pJob, uint cbBuf, out uint pcbNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_GetJobA' -Namespace Win32 -PassThru
# $api::GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)#uselib "winspool.drv"
#func global GetJobA "GetJobA" sptr, sptr, sptr, sptr, sptr, sptr
; GetJobA hPrinter, JobId, Level, varptr(pJob), cbBuf, varptr(pcbNeeded) ; 戻り値は stat
; hPrinter : PRINTER_HANDLE -> "sptr"
; JobId : DWORD -> "sptr"
; Level : DWORD -> "sptr"
; pJob : BYTE* optional, out -> "sptr"
; cbBuf : DWORD -> "sptr"
; pcbNeeded : DWORD* out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "winspool.drv" #cfunc global GetJobA "GetJobA" int, int, int, var, int, var ; res = GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded) ; hPrinter : PRINTER_HANDLE -> "int" ; JobId : DWORD -> "int" ; Level : DWORD -> "int" ; pJob : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "winspool.drv" #cfunc global GetJobA "GetJobA" int, int, int, sptr, int, sptr ; res = GetJobA(hPrinter, JobId, Level, varptr(pJob), cbBuf, varptr(pcbNeeded)) ; hPrinter : PRINTER_HANDLE -> "int" ; JobId : DWORD -> "int" ; Level : DWORD -> "int" ; pJob : BYTE* optional, out -> "sptr" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "sptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetJobA(PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetJobA "GetJobA" int, int, int, var, int, var ; res = GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded) ; hPrinter : PRINTER_HANDLE -> "int" ; JobId : DWORD -> "int" ; Level : DWORD -> "int" ; pJob : BYTE* optional, out -> "var" ; cbBuf : DWORD -> "int" ; pcbNeeded : DWORD* out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetJobA(PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded) #uselib "winspool.drv" #cfunc global GetJobA "GetJobA" int, int, int, intptr, int, intptr ; res = GetJobA(hPrinter, JobId, Level, varptr(pJob), cbBuf, varptr(pcbNeeded)) ; hPrinter : PRINTER_HANDLE -> "int" ; JobId : DWORD -> "int" ; Level : DWORD -> "int" ; pJob : 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")
procGetJobA = winspool_drv.NewProc("GetJobA")
)
// hPrinter (PRINTER_HANDLE), JobId (DWORD), Level (DWORD), pJob (BYTE* optional, out), cbBuf (DWORD), pcbNeeded (DWORD* out)
r1, _, err := procGetJobA.Call(
uintptr(hPrinter),
uintptr(JobId),
uintptr(Level),
uintptr(pJob),
uintptr(cbBuf),
uintptr(pcbNeeded),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetJobA(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
JobId: DWORD; // DWORD
Level: DWORD; // DWORD
pJob: Pointer; // BYTE* optional, out
cbBuf: DWORD; // DWORD
pcbNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'winspool.drv' name 'GetJobA';result := DllCall("winspool.drv\GetJobA"
, "Ptr", hPrinter ; PRINTER_HANDLE
, "UInt", JobId ; DWORD
, "UInt", Level ; DWORD
, "Ptr", pJob ; BYTE* optional, out
, "UInt", cbBuf ; DWORD
, "Ptr", pcbNeeded ; DWORD* out
, "Int") ; return: BOOL●GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded) = DLL("winspool.drv", "bool GetJobA(void*, dword, dword, void*, dword, void*)")
# 呼び出し: GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
# hPrinter : PRINTER_HANDLE -> "void*"
# JobId : DWORD -> "dword"
# Level : DWORD -> "dword"
# pJob : BYTE* optional, out -> "void*"
# cbBuf : DWORD -> "dword"
# pcbNeeded : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winspool.drv" fn GetJobA(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
JobId: u32, // DWORD
Level: u32, // DWORD
pJob: [*c]u8, // BYTE* optional, out
cbBuf: u32, // DWORD
pcbNeeded: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) i32;proc GetJobA(
hPrinter: PRINTER_HANDLE, # PRINTER_HANDLE
JobId: uint32, # DWORD
Level: uint32, # DWORD
pJob: ptr uint8, # BYTE* optional, out
cbBuf: uint32, # DWORD
pcbNeeded: ptr uint32 # DWORD* out
): int32 {.importc: "GetJobA", stdcall, dynlib: "winspool.drv".}pragma(lib, "winspool.drv");
extern(Windows)
int GetJobA(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
uint JobId, // DWORD
uint Level, // DWORD
ubyte* pJob, // BYTE* optional, out
uint cbBuf, // DWORD
uint* pcbNeeded // DWORD* out
);ccall((:GetJobA, "winspool.drv"), stdcall, Int32,
(PRINTER_HANDLE, UInt32, UInt32, Ptr{UInt8}, UInt32, Ptr{UInt32}),
hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
# hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
# JobId : DWORD -> UInt32
# Level : DWORD -> UInt32
# pJob : BYTE* optional, out -> Ptr{UInt8}
# cbBuf : DWORD -> UInt32
# pcbNeeded : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetJobA(
PRINTER_HANDLE hPrinter,
uint32_t JobId,
uint32_t Level,
uint8_t* pJob,
uint32_t cbBuf,
uint32_t* pcbNeeded);
]]
local winspool.drv = ffi.load("winspool.drv")
-- winspool.drv.GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
-- hPrinter : PRINTER_HANDLE
-- JobId : DWORD
-- Level : DWORD
-- pJob : BYTE* optional, out
-- cbBuf : DWORD
-- pcbNeeded : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('winspool.drv');
const GetJobA = lib.func('__stdcall', 'GetJobA', 'int32_t', ['PRINTER_HANDLE', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *']);
// GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
// hPrinter : PRINTER_HANDLE -> 'PRINTER_HANDLE'
// JobId : DWORD -> 'uint32_t'
// Level : DWORD -> 'uint32_t'
// pJob : BYTE* optional, out -> 'uint8_t *'
// cbBuf : DWORD -> 'uint32_t'
// pcbNeeded : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winspool.drv", {
GetJobA: { parameters: ["buffer", "u32", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
// hPrinter : PRINTER_HANDLE -> "buffer"
// JobId : DWORD -> "u32"
// Level : DWORD -> "u32"
// pJob : BYTE* optional, out -> "pointer"
// cbBuf : DWORD -> "u32"
// pcbNeeded : DWORD* out -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetJobA(
PRINTER_HANDLE hPrinter,
uint32_t JobId,
uint32_t Level,
uint8_t* pJob,
uint32_t cbBuf,
uint32_t* pcbNeeded);
C, "winspool.drv");
// $ffi->GetJobA(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded);
// hPrinter : PRINTER_HANDLE
// JobId : DWORD
// Level : DWORD
// pJob : 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.ASCII_OPTIONS);
boolean GetJobA(
PRINTER_HANDLE /* extends Structure (by value) */ hPrinter, // PRINTER_HANDLE
int JobId, // DWORD
int Level, // DWORD
byte[] pJob, // BYTE* optional, out
int cbBuf, // DWORD
IntByReference pcbNeeded // DWORD* out
);
}@[Link("winspool.drv")]
lib Libwinspool.drv
fun GetJobA = GetJobA(
hPrinter : PRINTER_HANDLE, # PRINTER_HANDLE
JobId : UInt32, # DWORD
Level : UInt32, # DWORD
pJob : 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 GetJobANative = Int32 Function(PRINTER_HANDLE, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>);
typedef GetJobADart = int Function(int, int, int, Pointer<Uint8>, int, Pointer<Uint32>);
final GetJobA = DynamicLibrary.open('winspool.drv')
.lookupFunction<GetJobANative, GetJobADart>('GetJobA');
// hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
// JobId : DWORD -> Uint32
// Level : DWORD -> Uint32
// pJob : BYTE* optional, out -> Pointer<Uint8>
// cbBuf : DWORD -> Uint32
// pcbNeeded : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetJobA(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
JobId: DWORD; // DWORD
Level: DWORD; // DWORD
pJob: Pointer; // BYTE* optional, out
cbBuf: DWORD; // DWORD
pcbNeeded: Pointer // DWORD* out
): BOOL; stdcall;
external 'winspool.drv' name 'GetJobA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetJobA"
c_GetJobA :: PRINTER_HANDLE -> Word32 -> Word32 -> Ptr Word8 -> Word32 -> Ptr Word32 -> IO CInt
-- hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
-- JobId : DWORD -> Word32
-- Level : DWORD -> Word32
-- pJob : 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 getjoba =
foreign "GetJobA"
(PRINTER_HANDLE @-> uint32_t @-> uint32_t @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> returning int32_t)
(* hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE *)
(* JobId : DWORD -> uint32_t *)
(* Level : DWORD -> uint32_t *)
(* pJob : 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 ("GetJobA" get-job-a :convention :stdcall) :int32
(h-printer (:struct printer-handle)) ; PRINTER_HANDLE
(job-id :uint32) ; DWORD
(level :uint32) ; DWORD
(p-job :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 $GetJobA = Win32::API::More->new('winspool.drv',
'BOOL GetJobA(LPVOID hPrinter, DWORD JobId, DWORD Level, LPVOID pJob, DWORD cbBuf, LPVOID pcbNeeded)');
# my $ret = $GetJobA->Call($hPrinter, $JobId, $Level, $pJob, $cbBuf, $pcbNeeded);
# hPrinter : PRINTER_HANDLE -> LPVOID
# JobId : DWORD -> DWORD
# Level : DWORD -> DWORD
# pJob : BYTE* optional, out -> LPVOID
# cbBuf : DWORD -> DWORD
# pcbNeeded : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
文字セット違い
- f GetJobW (Unicode版) — 指定した印刷ジョブの情報を取得する(Unicode版)。
使用する型