ホーム › Graphics.Printing › DeletePortW
DeletePortW
関数指定したプリンターポートを削除する。
シグネチャ
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL DeletePortW(
LPCWSTR pName, // optional
HWND hWnd,
LPCWSTR pPortName
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pName | LPCWSTR | inoptional |
| hWnd | HWND | in |
| pPortName | LPCWSTR | in |
戻り値の型: BOOL
各言語での呼び出し定義
// winspool.drv (Unicode / -W)
#include <windows.h>
BOOL DeletePortW(
LPCWSTR pName, // optional
HWND hWnd,
LPCWSTR pPortName
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool DeletePortW(
[MarshalAs(UnmanagedType.LPWStr)] string pName, // LPCWSTR optional
IntPtr hWnd, // HWND
[MarshalAs(UnmanagedType.LPWStr)] string pPortName // LPCWSTR
);<DllImport("winspool.drv", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function DeletePortW(
<MarshalAs(UnmanagedType.LPWStr)> pName As String, ' LPCWSTR optional
hWnd As IntPtr, ' HWND
<MarshalAs(UnmanagedType.LPWStr)> pPortName As String ' LPCWSTR
) As Boolean
End Function' pName : LPCWSTR optional
' hWnd : HWND
' pPortName : LPCWSTR
Declare PtrSafe Function DeletePortW Lib "winspool.drv" ( _
ByVal pName As LongPtr, _
ByVal hWnd As LongPtr, _
ByVal pPortName 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
DeletePortW = ctypes.windll.LoadLibrary("winspool.drv").DeletePortW
DeletePortW.restype = wintypes.BOOL
DeletePortW.argtypes = [
wintypes.LPCWSTR, # pName : LPCWSTR optional
wintypes.HANDLE, # hWnd : HWND
wintypes.LPCWSTR, # pPortName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('winspool.drv')
DeletePortW = Fiddle::Function.new(
lib['DeletePortW'],
[
Fiddle::TYPE_VOIDP, # pName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # hWnd : HWND
Fiddle::TYPE_VOIDP, # pPortName : LPCWSTR
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "winspool.drv")]
extern "system" {
fn DeletePortW(
pName: *const u16, // LPCWSTR optional
hWnd: *mut core::ffi::c_void, // HWND
pPortName: *const u16 // LPCWSTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("winspool.drv", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool DeletePortW([MarshalAs(UnmanagedType.LPWStr)] string pName, IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pPortName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'winspool.drv_DeletePortW' -Namespace Win32 -PassThru
# $api::DeletePortW(pName, hWnd, pPortName)#uselib "winspool.drv"
#func global DeletePortW "DeletePortW" wptr, wptr, wptr
; DeletePortW pName, hWnd, pPortName ; 戻り値は stat
; pName : LPCWSTR optional -> "wptr"
; hWnd : HWND -> "wptr"
; pPortName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "winspool.drv"
#cfunc global DeletePortW "DeletePortW" wstr, sptr, wstr
; res = DeletePortW(pName, hWnd, pPortName)
; pName : LPCWSTR optional -> "wstr"
; hWnd : HWND -> "sptr"
; pPortName : LPCWSTR -> "wstr"; BOOL DeletePortW(LPCWSTR pName, HWND hWnd, LPCWSTR pPortName)
#uselib "winspool.drv"
#cfunc global DeletePortW "DeletePortW" wstr, intptr, wstr
; res = DeletePortW(pName, hWnd, pPortName)
; pName : LPCWSTR optional -> "wstr"
; hWnd : HWND -> "intptr"
; pPortName : LPCWSTR -> "wstr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
winspool_drv = windows.NewLazySystemDLL("winspool.drv")
procDeletePortW = winspool_drv.NewProc("DeletePortW")
)
// pName (LPCWSTR optional), hWnd (HWND), pPortName (LPCWSTR)
r1, _, err := procDeletePortW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pName))),
uintptr(hWnd),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pPortName))),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction DeletePortW(
pName: PWideChar; // LPCWSTR optional
hWnd: THandle; // HWND
pPortName: PWideChar // LPCWSTR
): BOOL; stdcall;
external 'winspool.drv' name 'DeletePortW';result := DllCall("winspool.drv\DeletePortW"
, "WStr", pName ; LPCWSTR optional
, "Ptr", hWnd ; HWND
, "WStr", pPortName ; LPCWSTR
, "Int") ; return: BOOL●DeletePortW(pName, hWnd, pPortName) = DLL("winspool.drv", "bool DeletePortW(char*, void*, char*)")
# 呼び出し: DeletePortW(pName, hWnd, pPortName)
# pName : LPCWSTR optional -> "char*"
# hWnd : HWND -> "void*"
# pPortName : LPCWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。