ホーム › Graphics.Printing › AddPrinterConnection2W
AddPrinterConnection2W
関数詳細情報を指定してプリンター接続を追加する。
シグネチャ
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL AddPrinterConnection2W(
HWND hWnd, // optional
LPCWSTR pszName,
DWORD dwLevel,
void* pConnectionInfo
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hWnd | HWND | inoptional | UI表示の親となるウィンドウハンドル。プロンプトを抑止する場合はNULL可。 |
| pszName | LPCWSTR | in | 接続するプリンタ名を指す文字列(Unicode)。共有プリンタのUNC名などを指定する。 |
| dwLevel | DWORD | in | pConnectionInfoが指す構造体のバージョンレベル。現在は1を指定する。 |
| pConnectionInfo | void* | in | 接続情報を格納したPRINTER_CONNECTION_INFO_1構造体へのポインタ。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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 版の利用を推奨。const std = @import("std");
extern "winspool.drv" fn AddPrinterConnection2W(
hWnd: ?*anyopaque, // HWND optional
pszName: [*c]const u16, // LPCWSTR
dwLevel: u32, // DWORD
pConnectionInfo: ?*anyopaque // void*
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc AddPrinterConnection2W(
hWnd: pointer, # HWND optional
pszName: WideCString, # LPCWSTR
dwLevel: uint32, # DWORD
pConnectionInfo: pointer # void*
): int32 {.importc: "AddPrinterConnection2W", stdcall, dynlib: "winspool.drv".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "winspool.drv");
extern(Windows)
int AddPrinterConnection2W(
void* hWnd, // HWND optional
const(wchar)* pszName, // LPCWSTR
uint dwLevel, // DWORD
void* pConnectionInfo // void*
);ccall((:AddPrinterConnection2W, "winspool.drv"), stdcall, Int32,
(Ptr{Cvoid}, Cwstring, UInt32, Ptr{Cvoid}),
hWnd, pszName, dwLevel, pConnectionInfo)
# hWnd : HWND optional -> Ptr{Cvoid}
# pszName : LPCWSTR -> Cwstring
# dwLevel : DWORD -> UInt32
# pConnectionInfo : void* -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t AddPrinterConnection2W(
void* hWnd,
const uint16_t* pszName,
uint32_t dwLevel,
void* pConnectionInfo);
]]
local winspool.drv = ffi.load("winspool.drv")
-- winspool.drv.AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
-- hWnd : HWND optional
-- pszName : LPCWSTR
-- dwLevel : DWORD
-- pConnectionInfo : void*
-- 構造体/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 AddPrinterConnection2W = lib.func('__stdcall', 'AddPrinterConnection2W', 'int32_t', ['void *', 'str16', 'uint32_t', 'void *']);
// AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
// hWnd : HWND optional -> 'void *'
// pszName : LPCWSTR -> 'str16'
// dwLevel : DWORD -> 'uint32_t'
// pConnectionInfo : void* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("winspool.drv", {
AddPrinterConnection2W: { parameters: ["pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo)
// hWnd : HWND optional -> "pointer"
// pszName : LPCWSTR -> "buffer"
// dwLevel : DWORD -> "u32"
// pConnectionInfo : void* -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t AddPrinterConnection2W(
void* hWnd,
const uint16_t* pszName,
uint32_t dwLevel,
void* pConnectionInfo);
C, "winspool.drv");
// $ffi->AddPrinterConnection2W(hWnd, pszName, dwLevel, pConnectionInfo);
// hWnd : HWND optional
// pszName : LPCWSTR
// dwLevel : DWORD
// pConnectionInfo : void*
// 構造体/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 AddPrinterConnection2W(
Pointer hWnd, // HWND optional
WString pszName, // LPCWSTR
int dwLevel, // DWORD
Pointer pConnectionInfo // void*
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("winspool.drv")]
lib Libwinspool.drv
fun AddPrinterConnection2W = AddPrinterConnection2W(
hWnd : Void*, # HWND optional
pszName : UInt16*, # LPCWSTR
dwLevel : UInt32, # DWORD
pConnectionInfo : Void* # void*
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AddPrinterConnection2WNative = Int32 Function(Pointer<Void>, Pointer<Utf16>, Uint32, Pointer<Void>);
typedef AddPrinterConnection2WDart = int Function(Pointer<Void>, Pointer<Utf16>, int, Pointer<Void>);
final AddPrinterConnection2W = DynamicLibrary.open('winspool.drv')
.lookupFunction<AddPrinterConnection2WNative, AddPrinterConnection2WDart>('AddPrinterConnection2W');
// hWnd : HWND optional -> Pointer<Void>
// pszName : LPCWSTR -> Pointer<Utf16>
// dwLevel : DWORD -> Uint32
// pConnectionInfo : void* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AddPrinterConnection2W(
hWnd: THandle; // HWND optional
pszName: PWideChar; // LPCWSTR
dwLevel: DWORD; // DWORD
pConnectionInfo: Pointer // void*
): BOOL; stdcall;
external 'winspool.drv' name 'AddPrinterConnection2W';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AddPrinterConnection2W"
c_AddPrinterConnection2W :: Ptr () -> CWString -> Word32 -> Ptr () -> IO CInt
-- hWnd : HWND optional -> Ptr ()
-- pszName : LPCWSTR -> CWString
-- dwLevel : DWORD -> Word32
-- pConnectionInfo : void* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let addprinterconnection2w =
foreign "AddPrinterConnection2W"
((ptr void) @-> (ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* hWnd : HWND optional -> (ptr void) *)
(* pszName : LPCWSTR -> (ptr uint16_t) *)
(* dwLevel : DWORD -> uint32_t *)
(* pConnectionInfo : void* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library winspool.drv (t "winspool.drv"))
(cffi:use-foreign-library winspool.drv)
(cffi:defcfun ("AddPrinterConnection2W" add-printer-connection2-w :convention :stdcall) :int32
(h-wnd :pointer) ; HWND optional
(psz-name (:string :encoding :utf-16le)) ; LPCWSTR
(dw-level :uint32) ; DWORD
(p-connection-info :pointer)) ; void*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AddPrinterConnection2W = Win32::API::More->new('winspool.drv',
'BOOL AddPrinterConnection2W(HANDLE hWnd, LPCWSTR pszName, DWORD dwLevel, LPVOID pConnectionInfo)');
# my $ret = $AddPrinterConnection2W->Call($hWnd, $pszName, $dwLevel, $pConnectionInfo);
# hWnd : HWND optional -> HANDLE
# pszName : LPCWSTR -> LPCWSTR
# dwLevel : DWORD -> DWORD
# pConnectionInfo : void* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f AddPrinterConnection2A (ANSI版) — 詳細情報を指定してプリンター接続を追加する。
類似 API
- f AddPrinterConnectionW — ネットワークプリンターへの接続を追加する。