Win32 API 日本語リファレンス
ホームUI.Shell › SHInvokePrinterCommandW

SHInvokePrinterCommandW

関数
プリンターの追加や接続などのコマンドを実行する。
DLLSHELL32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// SHELL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SHInvokePrinterCommandW(
    HWND hwnd,   // optional
    DWORD uAction,
    LPCWSTR lpBuf1,
    LPCWSTR lpBuf2,   // optional
    BOOL fModal
);

パラメーター

名前方向
hwndHWNDinoptional
uActionDWORDin
lpBuf1LPCWSTRin
lpBuf2LPCWSTRinoptional
fModalBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

// SHELL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SHInvokePrinterCommandW(
    HWND hwnd,   // optional
    DWORD uAction,
    LPCWSTR lpBuf1,
    LPCWSTR lpBuf2,   // optional
    BOOL fModal
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool SHInvokePrinterCommandW(
    IntPtr hwnd,   // HWND optional
    uint uAction,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpBuf1,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpBuf2,   // LPCWSTR optional
    bool fModal   // BOOL
);
<DllImport("SHELL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function SHInvokePrinterCommandW(
    hwnd As IntPtr,   ' HWND optional
    uAction As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpBuf1 As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpBuf2 As String,   ' LPCWSTR optional
    fModal As Boolean   ' BOOL
) As Boolean
End Function
' hwnd : HWND optional
' uAction : DWORD
' lpBuf1 : LPCWSTR
' lpBuf2 : LPCWSTR optional
' fModal : BOOL
Declare PtrSafe Function SHInvokePrinterCommandW Lib "shell32" ( _
    ByVal hwnd As LongPtr, _
    ByVal uAction As Long, _
    ByVal lpBuf1 As LongPtr, _
    ByVal lpBuf2 As LongPtr, _
    ByVal fModal As Long) 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

SHInvokePrinterCommandW = ctypes.windll.shell32.SHInvokePrinterCommandW
SHInvokePrinterCommandW.restype = wintypes.BOOL
SHInvokePrinterCommandW.argtypes = [
    wintypes.HANDLE,  # hwnd : HWND optional
    wintypes.DWORD,  # uAction : DWORD
    wintypes.LPCWSTR,  # lpBuf1 : LPCWSTR
    wintypes.LPCWSTR,  # lpBuf2 : LPCWSTR optional
    wintypes.BOOL,  # fModal : BOOL
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('SHELL32.dll')
SHInvokePrinterCommandW = Fiddle::Function.new(
  lib['SHInvokePrinterCommandW'],
  [
    Fiddle::TYPE_VOIDP,  # hwnd : HWND optional
    -Fiddle::TYPE_INT,  # uAction : DWORD
    Fiddle::TYPE_VOIDP,  # lpBuf1 : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpBuf2 : LPCWSTR optional
    Fiddle::TYPE_INT,  # fModal : BOOL
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "shell32")]
extern "system" {
    fn SHInvokePrinterCommandW(
        hwnd: *mut core::ffi::c_void,  // HWND optional
        uAction: u32,  // DWORD
        lpBuf1: *const u16,  // LPCWSTR
        lpBuf2: *const u16,  // LPCWSTR optional
        fModal: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", CharSet = CharSet.Unicode)]
public static extern bool SHInvokePrinterCommandW(IntPtr hwnd, uint uAction, [MarshalAs(UnmanagedType.LPWStr)] string lpBuf1, [MarshalAs(UnmanagedType.LPWStr)] string lpBuf2, bool fModal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHInvokePrinterCommandW' -Namespace Win32 -PassThru
# $api::SHInvokePrinterCommandW(hwnd, uAction, lpBuf1, lpBuf2, fModal)
#uselib "SHELL32.dll"
#func global SHInvokePrinterCommandW "SHInvokePrinterCommandW" wptr, wptr, wptr, wptr, wptr
; SHInvokePrinterCommandW hwnd, uAction, lpBuf1, lpBuf2, fModal   ; 戻り値は stat
; hwnd : HWND optional -> "wptr"
; uAction : DWORD -> "wptr"
; lpBuf1 : LPCWSTR -> "wptr"
; lpBuf2 : LPCWSTR optional -> "wptr"
; fModal : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "SHELL32.dll"
#cfunc global SHInvokePrinterCommandW "SHInvokePrinterCommandW" sptr, int, wstr, wstr, int
; res = SHInvokePrinterCommandW(hwnd, uAction, lpBuf1, lpBuf2, fModal)
; hwnd : HWND optional -> "sptr"
; uAction : DWORD -> "int"
; lpBuf1 : LPCWSTR -> "wstr"
; lpBuf2 : LPCWSTR optional -> "wstr"
; fModal : BOOL -> "int"
; BOOL SHInvokePrinterCommandW(HWND hwnd, DWORD uAction, LPCWSTR lpBuf1, LPCWSTR lpBuf2, BOOL fModal)
#uselib "SHELL32.dll"
#cfunc global SHInvokePrinterCommandW "SHInvokePrinterCommandW" intptr, int, wstr, wstr, int
; res = SHInvokePrinterCommandW(hwnd, uAction, lpBuf1, lpBuf2, fModal)
; hwnd : HWND optional -> "intptr"
; uAction : DWORD -> "int"
; lpBuf1 : LPCWSTR -> "wstr"
; lpBuf2 : LPCWSTR optional -> "wstr"
; fModal : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	shell32 = windows.NewLazySystemDLL("SHELL32.dll")
	procSHInvokePrinterCommandW = shell32.NewProc("SHInvokePrinterCommandW")
)

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