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

ShellMessageBoxW

関数可変長引数
リソース文字列を用いてメッセージボックスを表示する。
DLLSHLWAPI.dll文字セットUnicode (-W)呼出規約cdeclSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// 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)。上記の固定引数の後に、書式に応じた引数を追加で渡します。

パラメーター

名前方向説明
hAppInstHINSTANCEinoptionalpszTitle で指定された文字列リソースを読み込むモジュールのハンドル。pszTitle が文字列リソースを指定していない場合、このパラメーターは無視されます。pszMsg または pszTitle がリソース ID である場合、この値は有効でなければなりません。
hWndHWNDinoptional作成するメッセージボックスの所有者ウィンドウへのハンドル。この変数が NULL でない場合、所有者ウィンドウのタイトルがメッセージボックスのタイトルとして使用されます。
lpcTextLPCWSTRin表示するメッセージ、またはメッセージの取得元を指定するリソース ID のいずれかを含む、null 終端文字列へのポインター。
lpcTitleLPCWSTRinoptionalダイアログボックスのタイトル、またはタイトルの取得元を指定するリソース ID を含む、null 終端文字列へのポインター。このパラメーターと hWnd の両方が NULL の場合、タイトルは表示されません。このパラメーターが MAKEINTRESOURCE マクロで作成された読み込み可能なリソースを指している場合、タイトルとして hWnd よりも優先されます。
fuStyleMESSAGEBOX_STYLEinダイアログボックスの内容と動作を指定します。指定可能な値については、MessageBox を参照してください。

戻り値の型: INT

公式ドキュメント

ShellMessageBox は変更される、または利用できなくなる可能性があります。(Unicode)

戻り値

型: int

メッセージボックスで押されたボタンを示す整数値。具体的な値については、MessageBox を参照してください。

関数が失敗した場合、戻り値は 0 です。詳細なエラー情報を取得するには、GetLastError を呼び出してください。

解説(Remarks)

メモ

shellapi.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして ShellMessageBox を定義します。エンコーディング非依存のエイリアスを、エンコーディング非依存でないコードと混在して使用すると、不一致が生じ、コンパイルエラーまたは実行時エラーが発生する可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
const std = @import("std");

extern "shlwapi" fn ShellMessageBoxW(
    hAppInst: ?*anyopaque, // HINSTANCE optional
    hWnd: ?*anyopaque, // HWND optional
    lpcText: [*c]const u16, // LPCWSTR
    lpcTitle: [*c]const u16, // LPCWSTR optional
    fuStyle: u32, // MESSAGEBOX_STYLE
    ...
) callconv(.c) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
proc ShellMessageBoxW(
    hAppInst: pointer,  # HINSTANCE optional
    hWnd: pointer,  # HWND optional
    lpcText: WideCString,  # LPCWSTR
    lpcTitle: WideCString,  # LPCWSTR optional
    fuStyle: uint32  # MESSAGEBOX_STYLE
): int32 {.importc: "ShellMessageBoxW", cdecl, varargs, dynlib: "SHLWAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
pragma(lib, "shlwapi");
extern(C)
int ShellMessageBoxW(
    void* hAppInst,   // HINSTANCE optional
    void* hWnd,   // HWND optional
    const(wchar)* lpcText,   // LPCWSTR
    const(wchar)* lpcTitle,   // LPCWSTR optional
    uint fuStyle,   // MESSAGEBOX_STYLE
    ...
);
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
ccall((:ShellMessageBoxW, "SHLWAPI.dll"), Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Cwstring, Cwstring, UInt32),
      hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
# hAppInst : HINSTANCE optional -> Ptr{Cvoid}
# hWnd : HWND optional -> Ptr{Cvoid}
# lpcText : LPCWSTR -> Cwstring
# lpcTitle : LPCWSTR optional -> Cwstring
# fuStyle : MESSAGEBOX_STYLE -> UInt32
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
local ffi = require("ffi")
ffi.cdef[[
int32_t ShellMessageBoxW(
    void* hAppInst,
    void* hWnd,
    const uint16_t* lpcText,
    const uint16_t* lpcTitle,
    uint32_t fuStyle,
    ...);
]]
local shlwapi = ffi.load("shlwapi")
-- shlwapi.ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
-- hAppInst : HINSTANCE optional
-- hWnd : HWND optional
-- lpcText : LPCWSTR
-- lpcTitle : LPCWSTR optional
-- fuStyle : MESSAGEBOX_STYLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
-- ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
const koffi = require('koffi');
const lib = koffi.load('SHLWAPI.dll');
const ShellMessageBoxW = lib.func('__cdecl', 'ShellMessageBoxW', 'int32_t', ['void *', 'void *', 'str16', 'str16', 'uint32_t', '...']);
// ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
// hAppInst : HINSTANCE optional -> 'void *'
// hWnd : HWND optional -> 'void *'
// lpcText : LPCWSTR -> 'str16'
// lpcTitle : LPCWSTR optional -> 'str16'
// fuStyle : MESSAGEBOX_STYLE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
const lib = Deno.dlopen("SHLWAPI.dll", {
  ShellMessageBoxW: { parameters: ["pointer", "pointer", "buffer", "buffer", "u32"], result: "i32" },
});
// lib.symbols.ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle)
// hAppInst : HINSTANCE optional -> "pointer"
// hWnd : HWND optional -> "pointer"
// lpcText : LPCWSTR -> "buffer"
// lpcTitle : LPCWSTR optional -> "buffer"
// fuStyle : MESSAGEBOX_STYLE -> "u32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
<?php
$ffi = FFI::cdef(<<<C
int32_t ShellMessageBoxW(
    void* hAppInst,
    void* hWnd,
    const uint16_t* lpcText,
    const uint16_t* lpcTitle,
    uint32_t fuStyle,
    ...);
C, "SHLWAPI.dll");
// $ffi->ShellMessageBoxW(hAppInst, hWnd, lpcText, lpcTitle, fuStyle);
// hAppInst : HINSTANCE optional
// hWnd : HWND optional
// lpcText : LPCWSTR
// lpcTitle : LPCWSTR optional
// fuStyle : MESSAGEBOX_STYLE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Shlwapi extends Library {
    Shlwapi INSTANCE = Native.load("shlwapi", Shlwapi.class, W32APIOptions.UNICODE_OPTIONS);
    int ShellMessageBoxW(
        Pointer hAppInst,   // HINSTANCE optional
        Pointer hWnd,   // HWND optional
        WString lpcText,   // LPCWSTR
        WString lpcTitle,   // LPCWSTR optional
        int fuStyle,   // MESSAGEBOX_STYLE
        Object... args   // 可変長引数(printf形式)
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
@[Link("shlwapi")]
lib LibSHLWAPI
  fun ShellMessageBoxW = ShellMessageBoxW(
    hAppInst : Void*,   # HINSTANCE optional
    hWnd : Void*,   # HWND optional
    lpcText : UInt16*,   # LPCWSTR
    lpcTitle : UInt16*,   # LPCWSTR optional
    fuStyle : UInt32,   # MESSAGEBOX_STYLE
    ...
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ShellMessageBoxWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, Uint32);
typedef ShellMessageBoxWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Utf16>, Pointer<Utf16>, int);
final ShellMessageBoxW = DynamicLibrary.open('SHLWAPI.dll')
    .lookupFunction<ShellMessageBoxWNative, ShellMessageBoxWDart>('ShellMessageBoxW');
// hAppInst : HINSTANCE optional -> Pointer<Void>
// hWnd : HWND optional -> Pointer<Void>
// lpcText : LPCWSTR -> Pointer<Utf16>
// lpcTitle : LPCWSTR optional -> Pointer<Utf16>
// fuStyle : MESSAGEBOX_STYLE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
// ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
{$mode objfpc}{$H+}
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)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import ccall safe "ShellMessageBoxW"
  c_ShellMessageBoxW :: Ptr () -> Ptr () -> CWString -> CWString -> Word32 -> IO Int32
-- hAppInst : HINSTANCE optional -> Ptr ()
-- hWnd : HWND optional -> Ptr ()
-- lpcText : LPCWSTR -> CWString
-- lpcTitle : LPCWSTR optional -> CWString
-- fuStyle : MESSAGEBOX_STYLE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
open Ctypes
open Foreign

let shellmessageboxw =
  foreign "ShellMessageBoxW"
    ((ptr void) @-> (ptr void) @-> (ptr uint16_t) @-> (ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* hAppInst : HINSTANCE optional -> (ptr void) *)
(* hWnd : HWND optional -> (ptr void) *)
(* lpcText : LPCWSTR -> (ptr uint16_t) *)
(* lpcTitle : LPCWSTR optional -> (ptr uint16_t) *)
(* fuStyle : MESSAGEBOX_STYLE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(* ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
(cffi:define-foreign-library shlwapi (t "SHLWAPI.dll"))
(cffi:use-foreign-library shlwapi)

(cffi:defcfun ("ShellMessageBoxW" shell-message-box-w :convention :cdecl) :int32
  (h-app-inst :pointer)   ; HINSTANCE optional
  (h-wnd :pointer)   ; HWND optional
  (lpc-text (:string :encoding :utf-16le))   ; LPCWSTR
  (lpc-title (:string :encoding :utf-16le))   ; LPCWSTR optional
  (fu-style :uint32)   ; MESSAGEBOX_STYLE
  &rest)   ; 可変長引数(printf形式)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
; ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。
use Win32::API;
my $ShellMessageBoxW = Win32::API::More->new('SHLWAPI',
    'int ShellMessageBoxW(HANDLE hAppInst, HANDLE hWnd, LPCWSTR lpcText, LPCWSTR lpcTitle, DWORD fuStyle)');
# my $ret = $ShellMessageBoxW->Call($hAppInst, $hWnd, $lpcText, $lpcTitle, $fuStyle);
# hAppInst : HINSTANCE optional -> HANDLE
# hWnd : HWND optional -> HANDLE
# lpcText : LPCWSTR -> LPCWSTR
# lpcTitle : LPCWSTR optional -> LPCWSTR
# fuStyle : MESSAGEBOX_STYLE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。
# ※可変長引数(printf形式・cdecl)。上記の固定引数の後に、書式に応じた引数を追加で渡します。

関連項目

文字セット違い
使用する型