ホーム › Graphics.Printing › GetPrintOutputInfo
GetPrintOutputInfo
関数印刷出力先ファイルの情報を取得する。
シグネチャ
// winspool.drv
#include <windows.h>
HRESULT GetPrintOutputInfo(
HWND hWnd,
LPCWSTR pszPrinter,
HANDLE* phFile,
LPWSTR* ppszOutputFile
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | in | ファイル選択ダイアログの親となるウィンドウハンドル。 |
| pszPrinter | LPCWSTR | in | 対象プリンタ名を示す文字列(Unicode)。 |
| phFile | HANDLE* | out | 出力先ファイルのハンドルを受け取るポインタ。 |
| ppszOutputFile | LPWSTR* | out | 出力ファイルのパス文字列を受け取るポインタ(Unicode)。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// winspool.drv
#include <windows.h>
HRESULT GetPrintOutputInfo(
HWND hWnd,
LPCWSTR pszPrinter,
HANDLE* phFile,
LPWSTR* ppszOutputFile
);[DllImport("winspool.drv", ExactSpelling = true)]
static extern int GetPrintOutputInfo(
IntPtr hWnd, // HWND
[MarshalAs(UnmanagedType.LPWStr)] string pszPrinter, // LPCWSTR
IntPtr phFile, // HANDLE* out
IntPtr ppszOutputFile // LPWSTR* out
);<DllImport("winspool.drv", ExactSpelling:=True)>
Public Shared Function GetPrintOutputInfo(
hWnd As IntPtr, ' HWND
<MarshalAs(UnmanagedType.LPWStr)> pszPrinter As String, ' LPCWSTR
phFile As IntPtr, ' HANDLE* out
ppszOutputFile As IntPtr ' LPWSTR* out
) As Integer
End Function' hWnd : HWND
' pszPrinter : LPCWSTR
' phFile : HANDLE* out
' ppszOutputFile : LPWSTR* out
Declare PtrSafe Function GetPrintOutputInfo Lib "winspool.drv" ( _
ByVal hWnd As LongPtr, _
ByVal pszPrinter As LongPtr, _
ByVal phFile As LongPtr, _
ByVal ppszOutputFile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetPrintOutputInfo = ctypes.windll.LoadLibrary("winspool.drv").GetPrintOutputInfo
GetPrintOutputInfo.restype = ctypes.c_int
GetPrintOutputInfo.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.LPCWSTR, # pszPrinter : LPCWSTR
ctypes.c_void_p, # phFile : HANDLE* out
ctypes.c_void_p, # ppszOutputFile : LPWSTR* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winspool.drv')
GetPrintOutputInfo = Fiddle::Function.new(
lib['GetPrintOutputInfo'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # pszPrinter : LPCWSTR
Fiddle::TYPE_VOIDP, # phFile : HANDLE* out
Fiddle::TYPE_VOIDP, # ppszOutputFile : LPWSTR* out
],
Fiddle::TYPE_INT)#[link(name = "winspool.drv")]
extern "system" {
fn GetPrintOutputInfo(
hWnd: *mut core::ffi::c_void, // HWND
pszPrinter: *const u16, // LPCWSTR
phFile: *mut *mut core::ffi::c_void, // HANDLE* out
ppszOutputFile: *mut *mut u16 // LPWSTR* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("winspool.drv")]
public static extern int GetPrintOutputInfo(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pszPrinter, IntPtr phFile, IntPtr ppszOutputFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_GetPrintOutputInfo' -Namespace Win32 -PassThru
# $api::GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile)#uselib "winspool.drv"
#func global GetPrintOutputInfo "GetPrintOutputInfo" sptr, sptr, sptr, sptr
; GetPrintOutputInfo hWnd, pszPrinter, phFile, varptr(ppszOutputFile) ; 戻り値は stat
; hWnd : HWND -> "sptr"
; pszPrinter : LPCWSTR -> "sptr"
; phFile : HANDLE* out -> "sptr"
; ppszOutputFile : LPWSTR* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "winspool.drv" #cfunc global GetPrintOutputInfo "GetPrintOutputInfo" sptr, wstr, sptr, var ; res = GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile) ; hWnd : HWND -> "sptr" ; pszPrinter : LPCWSTR -> "wstr" ; phFile : HANDLE* out -> "sptr" ; ppszOutputFile : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "winspool.drv" #cfunc global GetPrintOutputInfo "GetPrintOutputInfo" sptr, wstr, sptr, sptr ; res = GetPrintOutputInfo(hWnd, pszPrinter, phFile, varptr(ppszOutputFile)) ; hWnd : HWND -> "sptr" ; pszPrinter : LPCWSTR -> "wstr" ; phFile : HANDLE* out -> "sptr" ; ppszOutputFile : LPWSTR* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT GetPrintOutputInfo(HWND hWnd, LPCWSTR pszPrinter, HANDLE* phFile, LPWSTR* ppszOutputFile) #uselib "winspool.drv" #cfunc global GetPrintOutputInfo "GetPrintOutputInfo" intptr, wstr, intptr, var ; res = GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile) ; hWnd : HWND -> "intptr" ; pszPrinter : LPCWSTR -> "wstr" ; phFile : HANDLE* out -> "intptr" ; ppszOutputFile : LPWSTR* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT GetPrintOutputInfo(HWND hWnd, LPCWSTR pszPrinter, HANDLE* phFile, LPWSTR* ppszOutputFile) #uselib "winspool.drv" #cfunc global GetPrintOutputInfo "GetPrintOutputInfo" intptr, wstr, intptr, intptr ; res = GetPrintOutputInfo(hWnd, pszPrinter, phFile, varptr(ppszOutputFile)) ; hWnd : HWND -> "intptr" ; pszPrinter : LPCWSTR -> "wstr" ; phFile : HANDLE* out -> "intptr" ; ppszOutputFile : LPWSTR* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winspool_drv = windows.NewLazySystemDLL("winspool.drv")
procGetPrintOutputInfo = winspool_drv.NewProc("GetPrintOutputInfo")
)
// hWnd (HWND), pszPrinter (LPCWSTR), phFile (HANDLE* out), ppszOutputFile (LPWSTR* out)
r1, _, err := procGetPrintOutputInfo.Call(
uintptr(hWnd),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszPrinter))),
uintptr(phFile),
uintptr(ppszOutputFile),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction GetPrintOutputInfo(
hWnd: THandle; // HWND
pszPrinter: PWideChar; // LPCWSTR
phFile: Pointer; // HANDLE* out
ppszOutputFile: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'winspool.drv' name 'GetPrintOutputInfo';result := DllCall("winspool.drv\GetPrintOutputInfo"
, "Ptr", hWnd ; HWND
, "WStr", pszPrinter ; LPCWSTR
, "Ptr", phFile ; HANDLE* out
, "Ptr", ppszOutputFile ; LPWSTR* out
, "Int") ; return: HRESULT●GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile) = DLL("winspool.drv", "int GetPrintOutputInfo(void*, char*, void*, void*)")
# 呼び出し: GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile)
# hWnd : HWND -> "void*"
# pszPrinter : LPCWSTR -> "char*"
# phFile : HANDLE* out -> "void*"
# ppszOutputFile : LPWSTR* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "winspool.drv" fn GetPrintOutputInfo(
hWnd: ?*anyopaque, // HWND
pszPrinter: [*c]const u16, // LPCWSTR
phFile: ?*anyopaque, // HANDLE* out
ppszOutputFile: [*c][*c]u16 // LPWSTR* out
) callconv(std.os.windows.WINAPI) i32;proc GetPrintOutputInfo(
hWnd: pointer, # HWND
pszPrinter: WideCString, # LPCWSTR
phFile: pointer, # HANDLE* out
ppszOutputFile: ptr WideCString # LPWSTR* out
): int32 {.importc: "GetPrintOutputInfo", stdcall, dynlib: "winspool.drv".}pragma(lib, "winspool.drv");
extern(Windows)
int GetPrintOutputInfo(
void* hWnd, // HWND
const(wchar)* pszPrinter, // LPCWSTR
void* phFile, // HANDLE* out
wchar** ppszOutputFile // LPWSTR* out
);ccall((:GetPrintOutputInfo, "winspool.drv"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, Ptr{Cvoid}, Ptr{Ptr{UInt16}}),
hWnd, pszPrinter, phFile, ppszOutputFile)
# hWnd : HWND -> Ptr{Cvoid}
# pszPrinter : LPCWSTR -> Cwstring
# phFile : HANDLE* out -> Ptr{Cvoid}
# ppszOutputFile : LPWSTR* out -> Ptr{Ptr{UInt16}}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GetPrintOutputInfo(
void* hWnd,
const uint16_t* pszPrinter,
void* phFile,
uint16_t** ppszOutputFile);
]]
local winspool.drv = ffi.load("winspool.drv")
-- winspool.drv.GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile)
-- hWnd : HWND
-- pszPrinter : LPCWSTR
-- phFile : HANDLE* out
-- ppszOutputFile : LPWSTR* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('winspool.drv');
const GetPrintOutputInfo = lib.func('__stdcall', 'GetPrintOutputInfo', 'int32_t', ['void *', 'str16', 'void *', 'void *']);
// GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile)
// hWnd : HWND -> 'void *'
// pszPrinter : LPCWSTR -> 'str16'
// phFile : HANDLE* out -> 'void *'
// ppszOutputFile : LPWSTR* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winspool.drv", {
GetPrintOutputInfo: { parameters: ["pointer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile)
// hWnd : HWND -> "pointer"
// pszPrinter : LPCWSTR -> "buffer"
// phFile : HANDLE* out -> "pointer"
// ppszOutputFile : LPWSTR* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetPrintOutputInfo(
void* hWnd,
const uint16_t* pszPrinter,
void* phFile,
uint16_t** ppszOutputFile);
C, "winspool.drv");
// $ffi->GetPrintOutputInfo(hWnd, pszPrinter, phFile, ppszOutputFile);
// hWnd : HWND
// pszPrinter : LPCWSTR
// phFile : HANDLE* out
// ppszOutputFile : LPWSTR* 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);
int GetPrintOutputInfo(
Pointer hWnd, // HWND
WString pszPrinter, // LPCWSTR
Pointer phFile, // HANDLE* out
PointerByReference ppszOutputFile // LPWSTR* out
);
}@[Link("winspool.drv")]
lib Libwinspool.drv
fun GetPrintOutputInfo = GetPrintOutputInfo(
hWnd : Void*, # HWND
pszPrinter : UInt16*, # LPCWSTR
phFile : Void*, # HANDLE* out
ppszOutputFile : UInt16** # LPWSTR* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetPrintOutputInfoNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Pointer<Utf16>>);
typedef GetPrintOutputInfoDart = int Function(Pointer<Void>, Pointer<Utf16>, Pointer<Void>, Pointer<Pointer<Utf16>>);
final GetPrintOutputInfo = DynamicLibrary.open('winspool.drv')
.lookupFunction<GetPrintOutputInfoNative, GetPrintOutputInfoDart>('GetPrintOutputInfo');
// hWnd : HWND -> Pointer<Void>
// pszPrinter : LPCWSTR -> Pointer<Utf16>
// phFile : HANDLE* out -> Pointer<Void>
// ppszOutputFile : LPWSTR* out -> Pointer<Pointer<Utf16>>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetPrintOutputInfo(
hWnd: THandle; // HWND
pszPrinter: PWideChar; // LPCWSTR
phFile: Pointer; // HANDLE* out
ppszOutputFile: PPWideChar // LPWSTR* out
): Integer; stdcall;
external 'winspool.drv' name 'GetPrintOutputInfo';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetPrintOutputInfo"
c_GetPrintOutputInfo :: Ptr () -> CWString -> Ptr () -> Ptr CWString -> IO Int32
-- hWnd : HWND -> Ptr ()
-- pszPrinter : LPCWSTR -> CWString
-- phFile : HANDLE* out -> Ptr ()
-- ppszOutputFile : LPWSTR* out -> Ptr CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getprintoutputinfo =
foreign "GetPrintOutputInfo"
((ptr void) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr (ptr uint16_t)) @-> returning int32_t)
(* hWnd : HWND -> (ptr void) *)
(* pszPrinter : LPCWSTR -> (ptr uint16_t) *)
(* phFile : HANDLE* out -> (ptr void) *)
(* ppszOutputFile : LPWSTR* out -> (ptr (ptr uint16_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 ("GetPrintOutputInfo" get-print-output-info :convention :stdcall) :int32
(h-wnd :pointer) ; HWND
(psz-printer (:string :encoding :utf-16le)) ; LPCWSTR
(ph-file :pointer) ; HANDLE* out
(ppsz-output-file :pointer)) ; LPWSTR* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetPrintOutputInfo = Win32::API::More->new('winspool.drv',
'int GetPrintOutputInfo(HANDLE hWnd, LPCWSTR pszPrinter, HANDLE phFile, LPVOID ppszOutputFile)');
# my $ret = $GetPrintOutputInfo->Call($hWnd, $pszPrinter, $phFile, $ppszOutputFile);
# hWnd : HWND -> HANDLE
# pszPrinter : LPCWSTR -> LPCWSTR
# phFile : HANDLE* out -> HANDLE
# ppszOutputFile : LPWSTR* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。