SHInvokePrinterCommandA
関数プリンターの追加や接続などのコマンドを実行する。
シグネチャ
// SHELL32.dll (ANSI / -A)
#include <windows.h>
BOOL SHInvokePrinterCommandA(
HWND hwnd, // optional
DWORD uAction,
LPCSTR lpBuf1,
LPCSTR lpBuf2, // optional
BOOL fModal
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hwnd | HWND | inoptional |
| uAction | DWORD | in |
| lpBuf1 | LPCSTR | in |
| lpBuf2 | LPCSTR | inoptional |
| fModal | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// SHELL32.dll (ANSI / -A)
#include <windows.h>
BOOL SHInvokePrinterCommandA(
HWND hwnd, // optional
DWORD uAction,
LPCSTR lpBuf1,
LPCSTR lpBuf2, // optional
BOOL fModal
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("SHELL32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool SHInvokePrinterCommandA(
IntPtr hwnd, // HWND optional
uint uAction, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string lpBuf1, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpBuf2, // LPCSTR optional
bool fModal // BOOL
);<DllImport("SHELL32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function SHInvokePrinterCommandA(
hwnd As IntPtr, ' HWND optional
uAction As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> lpBuf1 As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpBuf2 As String, ' LPCSTR optional
fModal As Boolean ' BOOL
) As Boolean
End Function' hwnd : HWND optional
' uAction : DWORD
' lpBuf1 : LPCSTR
' lpBuf2 : LPCSTR optional
' fModal : BOOL
Declare PtrSafe Function SHInvokePrinterCommandA Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal uAction As Long, _
ByVal lpBuf1 As String, _
ByVal lpBuf2 As String, _
ByVal fModal As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHInvokePrinterCommandA = ctypes.windll.shell32.SHInvokePrinterCommandA
SHInvokePrinterCommandA.restype = wintypes.BOOL
SHInvokePrinterCommandA.argtypes = [
wintypes.HANDLE, # hwnd : HWND optional
wintypes.DWORD, # uAction : DWORD
wintypes.LPCSTR, # lpBuf1 : LPCSTR
wintypes.LPCSTR, # lpBuf2 : LPCSTR optional
wintypes.BOOL, # fModal : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHInvokePrinterCommandA = Fiddle::Function.new(
lib['SHInvokePrinterCommandA'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND optional
-Fiddle::TYPE_INT, # uAction : DWORD
Fiddle::TYPE_VOIDP, # lpBuf1 : LPCSTR
Fiddle::TYPE_VOIDP, # lpBuf2 : LPCSTR optional
Fiddle::TYPE_INT, # fModal : BOOL
],
Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHInvokePrinterCommandA(
hwnd: *mut core::ffi::c_void, // HWND optional
uAction: u32, // DWORD
lpBuf1: *const u8, // LPCSTR
lpBuf2: *const u8, // LPCSTR 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.Ansi)]
public static extern bool SHInvokePrinterCommandA(IntPtr hwnd, uint uAction, [MarshalAs(UnmanagedType.LPStr)] string lpBuf1, [MarshalAs(UnmanagedType.LPStr)] string lpBuf2, bool fModal);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHInvokePrinterCommandA' -Namespace Win32 -PassThru
# $api::SHInvokePrinterCommandA(hwnd, uAction, lpBuf1, lpBuf2, fModal)#uselib "SHELL32.dll"
#func global SHInvokePrinterCommandA "SHInvokePrinterCommandA" sptr, sptr, sptr, sptr, sptr
; SHInvokePrinterCommandA hwnd, uAction, lpBuf1, lpBuf2, fModal ; 戻り値は stat
; hwnd : HWND optional -> "sptr"
; uAction : DWORD -> "sptr"
; lpBuf1 : LPCSTR -> "sptr"
; lpBuf2 : LPCSTR optional -> "sptr"
; fModal : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll"
#cfunc global SHInvokePrinterCommandA "SHInvokePrinterCommandA" sptr, int, str, str, int
; res = SHInvokePrinterCommandA(hwnd, uAction, lpBuf1, lpBuf2, fModal)
; hwnd : HWND optional -> "sptr"
; uAction : DWORD -> "int"
; lpBuf1 : LPCSTR -> "str"
; lpBuf2 : LPCSTR optional -> "str"
; fModal : BOOL -> "int"; BOOL SHInvokePrinterCommandA(HWND hwnd, DWORD uAction, LPCSTR lpBuf1, LPCSTR lpBuf2, BOOL fModal)
#uselib "SHELL32.dll"
#cfunc global SHInvokePrinterCommandA "SHInvokePrinterCommandA" intptr, int, str, str, int
; res = SHInvokePrinterCommandA(hwnd, uAction, lpBuf1, lpBuf2, fModal)
; hwnd : HWND optional -> "intptr"
; uAction : DWORD -> "int"
; lpBuf1 : LPCSTR -> "str"
; lpBuf2 : LPCSTR optional -> "str"
; fModal : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHInvokePrinterCommandA = shell32.NewProc("SHInvokePrinterCommandA")
)
// hwnd (HWND optional), uAction (DWORD), lpBuf1 (LPCSTR), lpBuf2 (LPCSTR optional), fModal (BOOL)
r1, _, err := procSHInvokePrinterCommandA.Call(
uintptr(hwnd),
uintptr(uAction),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpBuf1))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpBuf2))),
uintptr(fModal),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SHInvokePrinterCommandA(
hwnd: THandle; // HWND optional
uAction: DWORD; // DWORD
lpBuf1: PAnsiChar; // LPCSTR
lpBuf2: PAnsiChar; // LPCSTR optional
fModal: BOOL // BOOL
): BOOL; stdcall;
external 'SHELL32.dll' name 'SHInvokePrinterCommandA';result := DllCall("SHELL32\SHInvokePrinterCommandA"
, "Ptr", hwnd ; HWND optional
, "UInt", uAction ; DWORD
, "AStr", lpBuf1 ; LPCSTR
, "AStr", lpBuf2 ; LPCSTR optional
, "Int", fModal ; BOOL
, "Int") ; return: BOOL●SHInvokePrinterCommandA(hwnd, uAction, lpBuf1, lpBuf2, fModal) = DLL("SHELL32.dll", "bool SHInvokePrinterCommandA(void*, dword, char*, char*, bool)")
# 呼び出し: SHInvokePrinterCommandA(hwnd, uAction, lpBuf1, lpBuf2, fModal)
# hwnd : HWND optional -> "void*"
# uAction : DWORD -> "dword"
# lpBuf1 : LPCSTR -> "char*"
# lpBuf2 : LPCSTR optional -> "char*"
# fModal : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。