ホーム › Graphics.Printing › AddPrintDeviceObject
AddPrintDeviceObject
関数印刷デバイスオブジェクトを追加する。
シグネチャ
// SPOOLSS.dll
#include <windows.h>
HRESULT AddPrintDeviceObject(
PRINTER_HANDLE hPrinter,
HANDLE* phDeviceObject
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hPrinter | PRINTER_HANDLE | in | OpenPrinterで取得したプリンタハンドル。 |
| phDeviceObject | HANDLE* | out | 作成された印刷デバイスオブジェクトのハンドルを受け取るポインタ。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// SPOOLSS.dll
#include <windows.h>
HRESULT AddPrintDeviceObject(
PRINTER_HANDLE hPrinter,
HANDLE* phDeviceObject
);[DllImport("SPOOLSS.dll", ExactSpelling = true)]
static extern int AddPrintDeviceObject(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
IntPtr phDeviceObject // HANDLE* out
);<DllImport("SPOOLSS.dll", ExactSpelling:=True)>
Public Shared Function AddPrintDeviceObject(
hPrinter As PRINTER_HANDLE, ' PRINTER_HANDLE
phDeviceObject As IntPtr ' HANDLE* out
) As Integer
End Function' hPrinter : PRINTER_HANDLE
' phDeviceObject : HANDLE* out
Declare PtrSafe Function AddPrintDeviceObject Lib "spoolss" ( _
ByVal hPrinter As LongPtr, _
ByVal phDeviceObject As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AddPrintDeviceObject = ctypes.windll.spoolss.AddPrintDeviceObject
AddPrintDeviceObject.restype = ctypes.c_int
AddPrintDeviceObject.argtypes = [
PRINTER_HANDLE, # hPrinter : PRINTER_HANDLE
ctypes.c_void_p, # phDeviceObject : HANDLE* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SPOOLSS.dll')
AddPrintDeviceObject = Fiddle::Function.new(
lib['AddPrintDeviceObject'],
[
Fiddle::TYPE_VOIDP, # hPrinter : PRINTER_HANDLE
Fiddle::TYPE_VOIDP, # phDeviceObject : HANDLE* out
],
Fiddle::TYPE_INT)#[link(name = "spoolss")]
extern "system" {
fn AddPrintDeviceObject(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
phDeviceObject: *mut *mut core::ffi::c_void // HANDLE* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SPOOLSS.dll")]
public static extern int AddPrintDeviceObject(PRINTER_HANDLE hPrinter, IntPtr phDeviceObject);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SPOOLSS_AddPrintDeviceObject' -Namespace Win32 -PassThru
# $api::AddPrintDeviceObject(hPrinter, phDeviceObject)#uselib "SPOOLSS.dll"
#func global AddPrintDeviceObject "AddPrintDeviceObject" sptr, sptr
; AddPrintDeviceObject hPrinter, phDeviceObject ; 戻り値は stat
; hPrinter : PRINTER_HANDLE -> "sptr"
; phDeviceObject : HANDLE* out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SPOOLSS.dll"
#cfunc global AddPrintDeviceObject "AddPrintDeviceObject" int, sptr
; res = AddPrintDeviceObject(hPrinter, phDeviceObject)
; hPrinter : PRINTER_HANDLE -> "int"
; phDeviceObject : HANDLE* out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。; HRESULT AddPrintDeviceObject(PRINTER_HANDLE hPrinter, HANDLE* phDeviceObject)
#uselib "SPOOLSS.dll"
#cfunc global AddPrintDeviceObject "AddPrintDeviceObject" int, intptr
; res = AddPrintDeviceObject(hPrinter, phDeviceObject)
; hPrinter : PRINTER_HANDLE -> "int"
; phDeviceObject : HANDLE* out -> "intptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
spoolss = windows.NewLazySystemDLL("SPOOLSS.dll")
procAddPrintDeviceObject = spoolss.NewProc("AddPrintDeviceObject")
)
// hPrinter (PRINTER_HANDLE), phDeviceObject (HANDLE* out)
r1, _, err := procAddPrintDeviceObject.Call(
uintptr(hPrinter),
uintptr(phDeviceObject),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction AddPrintDeviceObject(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
phDeviceObject: Pointer // HANDLE* out
): Integer; stdcall;
external 'SPOOLSS.dll' name 'AddPrintDeviceObject';result := DllCall("SPOOLSS\AddPrintDeviceObject"
, "Ptr", hPrinter ; PRINTER_HANDLE
, "Ptr", phDeviceObject ; HANDLE* out
, "Int") ; return: HRESULT●AddPrintDeviceObject(hPrinter, phDeviceObject) = DLL("SPOOLSS.dll", "int AddPrintDeviceObject(void*, void*)")
# 呼び出し: AddPrintDeviceObject(hPrinter, phDeviceObject)
# hPrinter : PRINTER_HANDLE -> "void*"
# phDeviceObject : HANDLE* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "spoolss" fn AddPrintDeviceObject(
hPrinter: PRINTER_HANDLE, // PRINTER_HANDLE
phDeviceObject: ?*anyopaque // HANDLE* out
) callconv(std.os.windows.WINAPI) i32;proc AddPrintDeviceObject(
hPrinter: PRINTER_HANDLE, # PRINTER_HANDLE
phDeviceObject: pointer # HANDLE* out
): int32 {.importc: "AddPrintDeviceObject", stdcall, dynlib: "SPOOLSS.dll".}pragma(lib, "spoolss");
extern(Windows)
int AddPrintDeviceObject(
PRINTER_HANDLE hPrinter, // PRINTER_HANDLE
void* phDeviceObject // HANDLE* out
);ccall((:AddPrintDeviceObject, "SPOOLSS.dll"), stdcall, Int32,
(PRINTER_HANDLE, Ptr{Cvoid}),
hPrinter, phDeviceObject)
# hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
# phDeviceObject : HANDLE* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t AddPrintDeviceObject(
PRINTER_HANDLE hPrinter,
void* phDeviceObject);
]]
local spoolss = ffi.load("spoolss")
-- spoolss.AddPrintDeviceObject(hPrinter, phDeviceObject)
-- hPrinter : PRINTER_HANDLE
-- phDeviceObject : HANDLE* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SPOOLSS.dll');
const AddPrintDeviceObject = lib.func('__stdcall', 'AddPrintDeviceObject', 'int32_t', ['PRINTER_HANDLE', 'void *']);
// AddPrintDeviceObject(hPrinter, phDeviceObject)
// hPrinter : PRINTER_HANDLE -> 'PRINTER_HANDLE'
// phDeviceObject : HANDLE* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SPOOLSS.dll", {
AddPrintDeviceObject: { parameters: ["buffer", "pointer"], result: "i32" },
});
// lib.symbols.AddPrintDeviceObject(hPrinter, phDeviceObject)
// hPrinter : PRINTER_HANDLE -> "buffer"
// phDeviceObject : HANDLE* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t AddPrintDeviceObject(
PRINTER_HANDLE hPrinter,
void* phDeviceObject);
C, "SPOOLSS.dll");
// $ffi->AddPrintDeviceObject(hPrinter, phDeviceObject);
// hPrinter : PRINTER_HANDLE
// phDeviceObject : HANDLE* 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 Spoolss extends StdCallLibrary {
Spoolss INSTANCE = Native.load("spoolss", Spoolss.class);
int AddPrintDeviceObject(
PRINTER_HANDLE /* extends Structure (by value) */ hPrinter, // PRINTER_HANDLE
Pointer phDeviceObject // HANDLE* out
);
}@[Link("spoolss")]
lib LibSPOOLSS
fun AddPrintDeviceObject = AddPrintDeviceObject(
hPrinter : PRINTER_HANDLE, # PRINTER_HANDLE
phDeviceObject : Void* # HANDLE* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AddPrintDeviceObjectNative = Int32 Function(PRINTER_HANDLE, Pointer<Void>);
typedef AddPrintDeviceObjectDart = int Function(int, Pointer<Void>);
final AddPrintDeviceObject = DynamicLibrary.open('SPOOLSS.dll')
.lookupFunction<AddPrintDeviceObjectNative, AddPrintDeviceObjectDart>('AddPrintDeviceObject');
// hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
// phDeviceObject : HANDLE* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AddPrintDeviceObject(
hPrinter: PRINTER_HANDLE; // PRINTER_HANDLE
phDeviceObject: Pointer // HANDLE* out
): Integer; stdcall;
external 'SPOOLSS.dll' name 'AddPrintDeviceObject';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AddPrintDeviceObject"
c_AddPrintDeviceObject :: PRINTER_HANDLE -> Ptr () -> IO Int32
-- hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE
-- phDeviceObject : HANDLE* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let addprintdeviceobject =
foreign "AddPrintDeviceObject"
(PRINTER_HANDLE @-> (ptr void) @-> returning int32_t)
(* hPrinter : PRINTER_HANDLE -> PRINTER_HANDLE *)
(* phDeviceObject : HANDLE* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library spoolss (t "SPOOLSS.dll"))
(cffi:use-foreign-library spoolss)
(cffi:defcfun ("AddPrintDeviceObject" add-print-device-object :convention :stdcall) :int32
(h-printer (:struct printer-handle)) ; PRINTER_HANDLE
(ph-device-object :pointer)) ; HANDLE* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AddPrintDeviceObject = Win32::API::More->new('SPOOLSS',
'int AddPrintDeviceObject(LPVOID hPrinter, HANDLE phDeviceObject)');
# my $ret = $AddPrintDeviceObject->Call($hPrinter, $phDeviceObject);
# hPrinter : PRINTER_HANDLE -> LPVOID
# phDeviceObject : HANDLE* out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型