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

AddPrintDeviceObject

関数
印刷デバイスオブジェクトを追加する。
DLLSPOOLSS.dll呼出規約winapi

シグネチャ

// SPOOLSS.dll
#include <windows.h>

HRESULT AddPrintDeviceObject(
    PRINTER_HANDLE hPrinter,
    HANDLE* phDeviceObject
);

パラメーター

名前方向
hPrinterPRINTER_HANDLEin
phDeviceObjectHANDLE*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   // HRESULT
function 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)。