ShellMessageBoxW
関数可変長引数リソース文字列を用いてメッセージボックスを表示する。
シグネチャ
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT ShellMessageBoxW(
HINSTANCE hAppInst, // optional
HWND hWnd, // optional
LPCWSTR lpcText,
LPCWSTR lpcTitle, // optional
MESSAGEBOX_STYLE fuStyle,
...
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hAppInst | HINSTANCE | inoptional |
| hWnd | HWND | inoptional |
| lpcText | LPCWSTR | in |
| lpcTitle | LPCWSTR | inoptional |
| fuStyle | MESSAGEBOX_STYLE | in |
戻り値の型: INT
各言語での呼び出し定義
// SHLWAPI.dll (Unicode / -W)
#include <windows.h>
INT ShellMessageBoxW(
HINSTANCE hAppInst, // optional
HWND hWnd, // optional
LPCWSTR lpcText,
LPCWSTR lpcTitle, // optional
MESSAGEBOX_STYLE fuStyle,
...
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.Cdecl)]
static extern int ShellMessageBoxW(
IntPtr hAppInst, // HINSTANCE optional
IntPtr hWnd, // HWND optional
[MarshalAs(UnmanagedType.LPWStr)] string lpcText, // LPCWSTR
[MarshalAs(UnmanagedType.LPWStr)] string lpcTitle, // LPCWSTR optional
uint fuStyle, // MESSAGEBOX_STYLE
__arglist
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。<DllImport("SHLWAPI.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)>
Public Shared Function ShellMessageBoxW(
hAppInst As IntPtr, ' HINSTANCE optional
hWnd As IntPtr, ' HWND optional
<MarshalAs(UnmanagedType.LPWStr)> lpcText As String, ' LPCWSTR
<MarshalAs(UnmanagedType.LPWStr)> lpcTitle As String, ' LPCWSTR optional
fuStyle As UInteger ' MESSAGEBOX_STYLE
) As Integer
End Function
' ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。' hAppInst : HINSTANCE optional
' hWnd : HWND optional
' lpcText : LPCWSTR
' lpcTitle : LPCWSTR optional
' fuStyle : MESSAGEBOX_STYLE
Declare PtrSafe Function ShellMessageBoxW Lib "shlwapi" ( _
ByVal hAppInst As LongPtr, _
ByVal hWnd As LongPtr, _
ByVal lpcText As LongPtr, _
ByVal lpcTitle As LongPtr, _
ByVal fuStyle As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
' ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。import ctypes
from ctypes import wintypes
ShellMessageBoxW = ctypes.cdll.shlwapi.ShellMessageBoxW
ShellMessageBoxW.restype = ctypes.c_int
ShellMessageBoxW.argtypes = [
wintypes.HANDLE, # hAppInst : HINSTANCE optional
wintypes.HANDLE, # hWnd : HWND optional
wintypes.LPCWSTR, # lpcText : LPCWSTR
wintypes.LPCWSTR, # lpcTitle : LPCWSTR optional
wintypes.DWORD, # fuStyle : MESSAGEBOX_STYLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHLWAPI.dll')
ShellMessageBoxW = Fiddle::Function.new(
lib['ShellMessageBoxW'],
[
Fiddle::TYPE_VOIDP, # hAppInst : HINSTANCE optional
Fiddle::TYPE_VOIDP, # hWnd : HWND optional
Fiddle::TYPE_VOIDP, # lpcText : LPCWSTR
Fiddle::TYPE_VOIDP, # lpcTitle : LPCWSTR optional
-Fiddle::TYPE_INT, # fuStyle : MESSAGEBOX_STYLE
],
Fiddle::TYPE_INT, Fiddle::Function::CDECL)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。#[link(name = "shlwapi")]
extern "C" {
fn ShellMessageBoxW(
hAppInst: *mut core::ffi::c_void, // HINSTANCE optional
hWnd: *mut core::ffi::c_void, // HWND optional
lpcText: *const u16, // LPCWSTR
lpcTitle: *const u16, // LPCWSTR optional
fuStyle: u32, // MESSAGEBOX_STYLE
...
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。$sig = @"
[DllImport("SHLWAPI.dll", CharSet = CharSet.Unicode, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]
public static extern int ShellMessageBoxW(IntPtr hAppInst, IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string lpcText, [MarshalAs(UnmanagedType.LPWStr)] string lpcTitle, uint fuStyle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHLWAPI_ShellMessageBoxW' -Namespace Win32 -PassThru
# $api::ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。#uselib "SHLWAPI.dll"
#func global ShellMessageBoxW "ShellMessageBoxW" wptr, wptr, wptr, wptr, wptr
; ShellMessageBoxW hAppInst, hWnd, lpcText, lpcTitle, fuStyle ; 戻り値は stat
; hAppInst : HINSTANCE optional -> "wptr"
; hWnd : HWND optional -> "wptr"
; lpcText : LPCWSTR -> "wptr"
; lpcTitle : LPCWSTR optional -> "wptr"
; fuStyle : MESSAGEBOX_STYLE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。#uselib "SHLWAPI.dll"
#cfunc global ShellMessageBoxW "ShellMessageBoxW" sptr, sptr, wstr, wstr, int
; res = ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
; hAppInst : HINSTANCE optional -> "sptr"
; hWnd : HWND optional -> "sptr"
; lpcText : LPCWSTR -> "wstr"
; lpcTitle : LPCWSTR optional -> "wstr"
; fuStyle : MESSAGEBOX_STYLE -> "int"
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。; INT ShellMessageBoxW(HINSTANCE hAppInst, HWND hWnd, LPCWSTR lpcText, LPCWSTR lpcTitle, MESSAGEBOX_STYLE fuStyle)
#uselib "SHLWAPI.dll"
#cfunc global ShellMessageBoxW "ShellMessageBoxW" intptr, intptr, wstr, wstr, int
; res = ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
; hAppInst : HINSTANCE optional -> "intptr"
; hWnd : HWND optional -> "intptr"
; lpcText : LPCWSTR -> "wstr"
; lpcTitle : LPCWSTR optional -> "wstr"
; fuStyle : MESSAGEBOX_STYLE -> "int"
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shlwapi = windows.NewLazySystemDLL("SHLWAPI.dll")
procShellMessageBoxW = shlwapi.NewProc("ShellMessageBoxW")
)
// hAppInst (HINSTANCE optional), hWnd (HWND optional), lpcText (LPCWSTR), lpcTitle (LPCWSTR optional), fuStyle (MESSAGEBOX_STYLE)
r1, _, err := procShellMessageBoxW.Call(
uintptr(hAppInst),
uintptr(hWnd),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpcText))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpcTitle))),
uintptr(fuStyle),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INT
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。function ShellMessageBoxW(
hAppInst: THandle; // HINSTANCE optional
hWnd: THandle; // HWND optional
lpcText: PWideChar; // LPCWSTR
lpcTitle: PWideChar; // LPCWSTR optional
fuStyle: DWORD // MESSAGEBOX_STYLE
): Integer; cdecl; varargs;
external 'SHLWAPI.dll' name 'ShellMessageBoxW';
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。result := DllCall("SHLWAPI\ShellMessageBoxW"
, "Ptr", hAppInst ; HINSTANCE optional
, "Ptr", hWnd ; HWND optional
, "WStr", lpcText ; LPCWSTR
, "WStr", lpcTitle ; LPCWSTR optional
, "UInt", fuStyle ; MESSAGEBOX_STYLE
, "Cdecl Int") ; return: INT
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。●ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle) = DLL("SHLWAPI.dll", "int ShellMessageBoxW(void*, void*, char*, char*, dword)")
# 呼び出し: ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
# hAppInst : HINSTANCE optional -> "void*"
# hWnd : HWND optional -> "void*"
# lpcText : LPCWSTR -> "char*"
# lpcTitle : LPCWSTR optional -> "char*"
# fuStyle : MESSAGEBOX_STYLE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。
# ※cdecl関数。DLL()宣言はstdcall前提。cdeclは EXEC_PTR(`cdecl`,…) を使用。
# ※可変長引数。DLL()は固定引数のみ。追加引数は EXEC_PTR で渡してください。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。