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

AddPrinterConnection2W

関数
詳細情報を指定してプリンター接続を追加する。
DLLwinspool.drv文字セットUnicode (-W)呼出規約winapi

シグネチャ

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

BOOL AddPrinterConnection2W(
    HWND hWnd,   // optional
    LPCWSTR pszName,
    DWORD dwLevel,
    void* pConnectionInfo
);

パラメーター

名前方向
hWndHWNDinoptional
pszNameLPCWSTRin
dwLevelDWORDin
pConnectionInfovoid*in

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL AddPrinterConnection2W(
    HWND hWnd,   // optional
    LPCWSTR pszName,
    DWORD dwLevel,
    void* pConnectionInfo
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool AddPrinterConnection2W(
    IntPtr hWnd,   // HWND optional
    [MarshalAs(UnmanagedType.LPWStr)] string pszName,   // LPCWSTR
    uint dwLevel,   // DWORD
    IntPtr pConnectionInfo   // void*
);
<DllImport("winspool.drv", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function AddPrinterConnection2W(
    hWnd As IntPtr,   ' HWND optional
    <MarshalAs(UnmanagedType.LPWStr)> pszName As String,   ' LPCWSTR
    dwLevel As UInteger,   ' DWORD
    pConnectionInfo As IntPtr   ' void*
) As Boolean
End Function
' hWnd : HWND optional
' pszName : LPCWSTR
' dwLevel : DWORD
' pConnectionInfo : void*
Declare PtrSafe Function AddPrinterConnection2W Lib "winspool.drv" ( _
    ByVal hWnd As LongPtr, _
    ByVal pszName As LongPtr, _
    ByVal dwLevel As Long, _
    ByVal pConnectionInfo As LongPtr) 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

AddPrinterConnection2W = ctypes.windll.LoadLibrary("winspool.drv").AddPrinterConnection2W
AddPrinterConnection2W.restype = wintypes.BOOL
AddPrinterConnection2W.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND optional
    wintypes.LPCWSTR,  # pszName : LPCWSTR
    wintypes.DWORD,  # dwLevel : DWORD
    ctypes.POINTER(None),  # pConnectionInfo : void*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('winspool.drv')
AddPrinterConnection2W = Fiddle::Function.new(
  lib['AddPrinterConnection2W'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND optional
    Fiddle::TYPE_VOIDP,  # pszName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwLevel : DWORD
    Fiddle::TYPE_VOIDP,  # pConnectionInfo : void*
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "winspool.drv")]
extern "system" {
    fn AddPrinterConnection2W(
        hWnd: *mut core::ffi::c_void,  // HWND optional
        pszName: *const u16,  // LPCWSTR
        dwLevel: u32,  // DWORD
        pConnectionInfo: *mut ()  // void*
    ) -> 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 AddPrinterConnection2W(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pszName, uint dwLevel, IntPtr pConnectionInfo);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_AddPrinterConnection2W' -Namespace Win32 -PassThru
# $api::AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
#uselib "winspool.drv"
#func global AddPrinterConnection2W "AddPrinterConnection2W" wptr, wptr, wptr, wptr
; AddPrinterConnection2W hWnd, pszName, dwLevel, pConnectionInfo   ; 戻り値は stat
; hWnd : HWND optional -> "wptr"
; pszName : LPCWSTR -> "wptr"
; dwLevel : DWORD -> "wptr"
; pConnectionInfo : void* -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "winspool.drv"
#cfunc global AddPrinterConnection2W "AddPrinterConnection2W" sptr, wstr, int, sptr
; res = AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
; hWnd : HWND optional -> "sptr"
; pszName : LPCWSTR -> "wstr"
; dwLevel : DWORD -> "int"
; pConnectionInfo : void* -> "sptr"
; BOOL AddPrinterConnection2W(HWND hWnd, LPCWSTR pszName, DWORD dwLevel, void* pConnectionInfo)
#uselib "winspool.drv"
#cfunc global AddPrinterConnection2W "AddPrinterConnection2W" intptr, wstr, int, intptr
; res = AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
; hWnd : HWND optional -> "intptr"
; pszName : LPCWSTR -> "wstr"
; dwLevel : DWORD -> "int"
; pConnectionInfo : void* -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winspool_drv = windows.NewLazySystemDLL("winspool.drv")
	procAddPrinterConnection2W = winspool_drv.NewProc("AddPrinterConnection2W")
)

// hWnd (HWND optional), pszName (LPCWSTR), dwLevel (DWORD), pConnectionInfo (void*)
r1, _, err := procAddPrinterConnection2W.Call(
	uintptr(hWnd),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszName))),
	uintptr(dwLevel),
	uintptr(pConnectionInfo),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function AddPrinterConnection2W(
  hWnd: THandle;   // HWND optional
  pszName: PWideChar;   // LPCWSTR
  dwLevel: DWORD;   // DWORD
  pConnectionInfo: Pointer   // void*
): BOOL; stdcall;
  external 'winspool.drv' name 'AddPrinterConnection2W';
result := DllCall("winspool.drv\AddPrinterConnection2W"
    , "Ptr", hWnd   ; HWND optional
    , "WStr", pszName   ; LPCWSTR
    , "UInt", dwLevel   ; DWORD
    , "Ptr", pConnectionInfo   ; void*
    , "Int")   ; return: BOOL
●AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo) = DLL("winspool.drv", "bool AddPrinterConnection2W(void*, char*, dword, void*)")
# 呼び出し: AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
# hWnd : HWND optional -> "void*"
# pszName : LPCWSTR -> "char*"
# dwLevel : DWORD -> "dword"
# pConnectionInfo : void* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。