Win32 API 日本語リファレンス
ホームGraphics.Printing › GetJobW

GetJobW

関数
指定した印刷ジョブの情報を取得する(Unicode版)。
DLLwinspool.drv文字セットUnicode (-W)呼出規約winapi

シグネチャ

// winspool.drv  (Unicode / -W)
#include <windows.h>

BOOL GetJobW(
    PRINTER_HANDLE hPrinter,
    DWORD JobId,
    DWORD Level,
    BYTE* pJob,   // optional
    DWORD cbBuf,
    DWORD* pcbNeeded
);

パラメーター

名前方向説明
hPrinterPRINTER_HANDLEinOpenPrinterで取得したプリンタのハンドル。
JobIdDWORDin情報を取得する印刷ジョブの識別子。
LevelDWORDin受け取るJOB_INFO構造体のレベル(1,2,3,4)。
pJobBYTE*outoptionalジョブ情報を受け取るバッファ(Unicode)へのポインタ。
cbBufDWORDinpJobバッファのサイズ(バイト)。
pcbNeededDWORD*out必要または格納されたバイト数を受け取る出力。

戻り値の型: BOOL

各言語での呼び出し定義

// winspool.drv  (Unicode / -W)
#include <windows.h>

BOOL GetJobW(
    PRINTER_HANDLE hPrinter,
    DWORD JobId,
    DWORD Level,
    BYTE* pJob,   // optional
    DWORD cbBuf,
    DWORD* pcbNeeded
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetJobW(
    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.Unicode, ExactSpelling:=True)>
Public Shared Function GetJobW(
    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 GetJobW 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
' 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

GetJobW = ctypes.windll.LoadLibrary("winspool.drv").GetJobW
GetJobW.restype = wintypes.BOOL
GetJobW.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')
GetJobW = Fiddle::Function.new(
  lib['GetJobW'],
  [
    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)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "winspool.drv")]
extern "system" {
    fn GetJobW(
        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.Unicode)]
public static extern bool GetJobW(PRINTER_HANDLE hPrinter, uint JobId, uint Level, IntPtr pJob, uint cbBuf, out uint pcbNeeded);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_GetJobW' -Namespace Win32 -PassThru
# $api::GetJobW(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded)
#uselib "winspool.drv"
#func global GetJobW "GetJobW" wptr, wptr, wptr, wptr, wptr, wptr
; GetJobW hPrinter, JobId, Level, varptr(pJob), cbBuf, varptr(pcbNeeded)   ; 戻り値は stat
; hPrinter : PRINTER_HANDLE -> "wptr"
; JobId : DWORD -> "wptr"
; Level : DWORD -> "wptr"
; pJob : BYTE* optional, out -> "wptr"
; cbBuf : DWORD -> "wptr"
; pcbNeeded : DWORD* out -> "wptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "winspool.drv"
#cfunc global GetJobW "GetJobW" int, int, int, var, int, var
; res = GetJobW(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 GetJobW(PRINTER_HANDLE hPrinter, DWORD JobId, DWORD Level, BYTE* pJob, DWORD cbBuf, DWORD* pcbNeeded)
#uselib "winspool.drv"
#cfunc global GetJobW "GetJobW" int, int, int, var, int, var
; res = GetJobW(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 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winspool_drv = windows.NewLazySystemDLL("winspool.drv")
	procGetJobW = winspool_drv.NewProc("GetJobW")
)

// hPrinter (PRINTER_HANDLE), JobId (DWORD), Level (DWORD), pJob (BYTE* optional, out), cbBuf (DWORD), pcbNeeded (DWORD* out)
r1, _, err := procGetJobW.Call(
	uintptr(hPrinter),
	uintptr(JobId),
	uintptr(Level),
	uintptr(pJob),
	uintptr(cbBuf),
	uintptr(pcbNeeded),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetJobW(
  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 'GetJobW';
result := DllCall("winspool.drv\GetJobW"
    , "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
●GetJobW(hPrinter, JobId, Level, pJob, cbBuf, pcbNeeded) = DLL("winspool.drv", "bool GetJobW(void*, dword, dword, void*, dword, void*)")
# 呼び出し: GetJobW(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)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
const std = @import("std");

extern "winspool.drv" fn GetJobW(
    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;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc GetJobW(
    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: "GetJobW", stdcall, dynlib: "winspool.drv".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "winspool.drv");
extern(Windows)
int GetJobW(
    PRINTER_HANDLE hPrinter,   // PRINTER_HANDLE
    uint JobId,   // DWORD
    uint Level,   // DWORD
    ubyte* pJob,   // BYTE* optional, out
    uint cbBuf,   // DWORD
    uint* pcbNeeded   // DWORD* out
);
ccall((:GetJobW, "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 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetJobW(
    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.GetJobW(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 に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('winspool.drv');
const GetJobW = lib.func('__stdcall', 'GetJobW', 'int32_t', ['PRINTER_HANDLE', 'uint32_t', 'uint32_t', 'uint8_t *', 'uint32_t', 'uint32_t *']);
// GetJobW(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", {
  GetJobW: { parameters: ["buffer", "u32", "u32", "pointer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetJobW(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"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetJobW(
    PRINTER_HANDLE hPrinter,
    uint32_t JobId,
    uint32_t Level,
    uint8_t* pJob,
    uint32_t cbBuf,
    uint32_t* pcbNeeded);
C, "winspool.drv");
// $ffi->GetJobW(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.UNICODE_OPTIONS);
    boolean GetJobW(
        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
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("winspool.drv")]
lib Libwinspool.drv
  fun GetJobW = GetJobW(
    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 GetJobWNative = Int32 Function(PRINTER_HANDLE, Uint32, Uint32, Pointer<Uint8>, Uint32, Pointer<Uint32>);
typedef GetJobWDart = int Function(int, int, int, Pointer<Uint8>, int, Pointer<Uint32>);
final GetJobW = DynamicLibrary.open('winspool.drv')
    .lookupFunction<GetJobWNative, GetJobWDart>('GetJobW');
// 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 GetJobW(
  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 'GetJobW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetJobW"
  c_GetJobW :: 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 getjobw =
  foreign "GetJobW"
    (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 ("GetJobW" get-job-w :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 $GetJobW = Win32::API::More->new('winspool.drv',
    'BOOL GetJobW(LPVOID hPrinter, DWORD JobId, DWORD Level, LPVOID pJob, DWORD cbBuf, LPVOID pcbNeeded)');
# my $ret = $GetJobW->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 を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
使用する型