Win32 API 日本語リファレンス
ホーム › System.RemoteDesktop › WTSSendMessageA

WTSSendMessageA

関数
指定セッションにメッセージボックスを表示して応答を取得する。
DLLWTSAPI32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// WTSAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL WTSSendMessageA(
    HANDLE hServer,   // optional
    DWORD SessionId,
    LPSTR pTitle,
    DWORD TitleLength,
    LPSTR pMessage,
    DWORD MessageLength,
    MESSAGEBOX_STYLE Style,
    DWORD Timeout,
    MESSAGEBOX_RESULT* pResponse,
    BOOL bWait
);

パラメーター

名前型方向説明
hServerHANDLEoptionalRD Session Host サーバーへのハンドルです。 WTSOpenServer 関数で開いたハンドルを指定するか、 アプリケーションが実行されている RD Session Host サーバーを示す WTS_CURRENT_SERVER_HANDLE を指定します。
SessionIdDWORDin

Remote Desktop Services のセッション識別子です。現在のセッションを示すには WTS_CURRENT_SESSION を指定します。 WTSEnumerateSessions 関数を使用すると、 指定した RD Session Host サーバー上のすべてのセッションの識別子を取得できます。

他のユーザーのセッションにメッセージを送信するには、Message 権限が必要です。詳細については、 Remote Desktop Services
のアクセス許可
を参照してください。セッションのアクセス許可を変更するには、Remote Desktop Services 構成の管理ツールを使用します。

pTitleLPSTRinメッセージボックスのタイトルバーに表示する、null で終わる文字列へのポインターです。
TitleLengthDWORDinタイトルバーの文字列の長さ (バイト単位) です。
pMessageLPSTRin表示するメッセージを格納した、null で終わる文字列へのポインターです。
MessageLengthDWORDinメッセージ文字列の長さ (バイト単位) です。
StyleMESSAGEBOX_STYLEinメッセージボックスの内容と動作です。通常、この値は MB_OK です。値の完全な一覧については、MessageBox 関数の uType パラメーターを参照してください。
TimeoutDWORDinWTSSendMessage 関数がユーザーの応答を待機する時間 (秒単位) です。 タイムアウト間隔内にユーザーが応答しない場合、 pResponse パラメーターは IDTIMEOUT を返します。 Timeout パラメーターが 0 の場合、WTSSendMessage はユーザーが応答するまで 無期限に待機します。
pResponseMESSAGEBOX_RESULT*out

ユーザーの応答を受け取る変数へのポインターです。次のいずれかの値になります。

IDABORT (3)

中止

IDCANCEL (2)

キャンセル

IDCONTINUE (11)

続行

IDIGNORE (5)

無視

IDNO (7)

いいえ

IDOK (1)

OK

IDRETRY (4)

再試行

IDTRYAGAIN (10)

やり直し

IDYES (6)

はい

IDASYNC (32001 (0x7D01))

bWait パラメーターが FALSE であったため、関数は応答を待たずに 戻りました。

IDTIMEOUT (32000 (0x7D00))

bWait パラメーターが TRUE で、タイムアウト間隔が経過しました。

bWaitBOOLin

TRUE の場合、WTSSendMessage はユーザーが応答するか タイムアウト間隔が経過するまで戻りません。Timeout パラメーターが 0 の場合、 関数はユーザーが応答するまで戻りません。

FALSE の場合、関数は直ちに戻り、 pResponse パラメーターは IDASYNC を返します。 ユーザーの応答を呼び出し元のプログラムに返す必要がない単純な情報メッセージ (印刷ジョブの通知メッセージなど) では、この方法を使用します。

戻り値の型: BOOL

公式ドキュメント

指定した Remote Desktop Services セッションのクライアントデスクトップにメッセージボックスを表示します。(ANSI)

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、 GetLastError を呼び出します。

解説(Remarks)

メモ

wtsapi32.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして WTSSendMessage を定義します。エンコーディング中立なエイリアスの使用と、エンコーディング中立でないコードを混在させると、不一致が生じてコンパイルエラーや実行時エラーの原因となる場合があります。詳細については、関数プロトタイプの規則を参照してください。

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

各言語での呼び出し定義

// WTSAPI32.dll  (ANSI / -A)
#include <windows.h>

BOOL WTSSendMessageA(
    HANDLE hServer,   // optional
    DWORD SessionId,
    LPSTR pTitle,
    DWORD TitleLength,
    LPSTR pMessage,
    DWORD MessageLength,
    MESSAGEBOX_STYLE Style,
    DWORD Timeout,
    MESSAGEBOX_RESULT* pResponse,
    BOOL bWait
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool WTSSendMessageA(
    IntPtr hServer,   // HANDLE optional
    uint SessionId,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string pTitle,   // LPSTR
    uint TitleLength,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] string pMessage,   // LPSTR
    uint MessageLength,   // DWORD
    uint Style,   // MESSAGEBOX_STYLE
    uint Timeout,   // DWORD
    out int pResponse,   // MESSAGEBOX_RESULT* out
    bool bWait   // BOOL
);
<DllImport("WTSAPI32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WTSSendMessageA(
    hServer As IntPtr,   ' HANDLE optional
    SessionId As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pTitle As String,   ' LPSTR
    TitleLength As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> pMessage As String,   ' LPSTR
    MessageLength As UInteger,   ' DWORD
    Style As UInteger,   ' MESSAGEBOX_STYLE
    Timeout As UInteger,   ' DWORD
    <Out> ByRef pResponse As Integer,   ' MESSAGEBOX_RESULT* out
    bWait As Boolean   ' BOOL
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hServer : HANDLE optional
' SessionId : DWORD
' pTitle : LPSTR
' TitleLength : DWORD
' pMessage : LPSTR
' MessageLength : DWORD
' Style : MESSAGEBOX_STYLE
' Timeout : DWORD
' pResponse : MESSAGEBOX_RESULT* out
' bWait : BOOL
Declare PtrSafe Function WTSSendMessageA Lib "wtsapi32" ( _
    ByVal hServer As LongPtr, _
    ByVal SessionId As Long, _
    ByVal pTitle As String, _
    ByVal TitleLength As Long, _
    ByVal pMessage As String, _
    ByVal MessageLength As Long, _
    ByVal Style As Long, _
    ByVal Timeout As Long, _
    ByRef pResponse As Long, _
    ByVal bWait As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WTSSendMessageA = ctypes.windll.wtsapi32.WTSSendMessageA
WTSSendMessageA.restype = wintypes.BOOL
WTSSendMessageA.argtypes = [
    wintypes.HANDLE,  # hServer : HANDLE optional
    wintypes.DWORD,  # SessionId : DWORD
    wintypes.LPCSTR,  # pTitle : LPSTR
    wintypes.DWORD,  # TitleLength : DWORD
    wintypes.LPCSTR,  # pMessage : LPSTR
    wintypes.DWORD,  # MessageLength : DWORD
    wintypes.DWORD,  # Style : MESSAGEBOX_STYLE
    wintypes.DWORD,  # Timeout : DWORD
    ctypes.c_void_p,  # pResponse : MESSAGEBOX_RESULT* out
    wintypes.BOOL,  # bWait : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WTSAPI32.dll')
WTSSendMessageA = Fiddle::Function.new(
  lib['WTSSendMessageA'],
  [
    Fiddle::TYPE_VOIDP,  # hServer : HANDLE optional
    -Fiddle::TYPE_INT,  # SessionId : DWORD
    Fiddle::TYPE_VOIDP,  # pTitle : LPSTR
    -Fiddle::TYPE_INT,  # TitleLength : DWORD
    Fiddle::TYPE_VOIDP,  # pMessage : LPSTR
    -Fiddle::TYPE_INT,  # MessageLength : DWORD
    -Fiddle::TYPE_INT,  # Style : MESSAGEBOX_STYLE
    -Fiddle::TYPE_INT,  # Timeout : DWORD
    Fiddle::TYPE_VOIDP,  # pResponse : MESSAGEBOX_RESULT* out
    Fiddle::TYPE_INT,  # bWait : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "wtsapi32")]
extern "system" {
    fn WTSSendMessageA(
        hServer: *mut core::ffi::c_void,  // HANDLE optional
        SessionId: u32,  // DWORD
        pTitle: *mut u8,  // LPSTR
        TitleLength: u32,  // DWORD
        pMessage: *mut u8,  // LPSTR
        MessageLength: u32,  // DWORD
        Style: u32,  // MESSAGEBOX_STYLE
        Timeout: u32,  // DWORD
        pResponse: *mut i32,  // MESSAGEBOX_RESULT* out
        bWait: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WTSAPI32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool WTSSendMessageA(IntPtr hServer, uint SessionId, [MarshalAs(UnmanagedType.LPStr)] string pTitle, uint TitleLength, [MarshalAs(UnmanagedType.LPStr)] string pMessage, uint MessageLength, uint Style, uint Timeout, out int pResponse, bool bWait);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WTSAPI32_WTSSendMessageA' -Namespace Win32 -PassThru
# $api::WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
#uselib "WTSAPI32.dll"
#func global WTSSendMessageA "WTSSendMessageA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WTSSendMessageA hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, varptr(pResponse), bWait   ; 戻り値は stat
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "sptr"
; pTitle : LPSTR -> "sptr"
; TitleLength : DWORD -> "sptr"
; pMessage : LPSTR -> "sptr"
; MessageLength : DWORD -> "sptr"
; Style : MESSAGEBOX_STYLE -> "sptr"
; Timeout : DWORD -> "sptr"
; pResponse : MESSAGEBOX_RESULT* out -> "sptr"
; bWait : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageA "WTSSendMessageA" sptr, int, str, int, str, int, int, int, var, int
; res = WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "sptr"
; SessionId : DWORD -> "int"
; pTitle : LPSTR -> "str"
; TitleLength : DWORD -> "int"
; pMessage : LPSTR -> "str"
; MessageLength : DWORD -> "int"
; Style : MESSAGEBOX_STYLE -> "int"
; Timeout : DWORD -> "int"
; pResponse : MESSAGEBOX_RESULT* out -> "var"
; bWait : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPSTR pTitle, DWORD TitleLength, LPSTR pMessage, DWORD MessageLength, MESSAGEBOX_STYLE Style, DWORD Timeout, MESSAGEBOX_RESULT* pResponse, BOOL bWait)
#uselib "WTSAPI32.dll"
#cfunc global WTSSendMessageA "WTSSendMessageA" intptr, int, str, int, str, int, int, int, var, int
; res = WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
; hServer : HANDLE optional -> "intptr"
; SessionId : DWORD -> "int"
; pTitle : LPSTR -> "str"
; TitleLength : DWORD -> "int"
; pMessage : LPSTR -> "str"
; MessageLength : DWORD -> "int"
; Style : MESSAGEBOX_STYLE -> "int"
; Timeout : DWORD -> "int"
; pResponse : MESSAGEBOX_RESULT* out -> "var"
; bWait : BOOL -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wtsapi32 = windows.NewLazySystemDLL("WTSAPI32.dll")
	procWTSSendMessageA = wtsapi32.NewProc("WTSSendMessageA")
)

// hServer (HANDLE optional), SessionId (DWORD), pTitle (LPSTR), TitleLength (DWORD), pMessage (LPSTR), MessageLength (DWORD), Style (MESSAGEBOX_STYLE), Timeout (DWORD), pResponse (MESSAGEBOX_RESULT* out), bWait (BOOL)
r1, _, err := procWTSSendMessageA.Call(
	uintptr(hServer),
	uintptr(SessionId),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pTitle))),
	uintptr(TitleLength),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(pMessage))),
	uintptr(MessageLength),
	uintptr(Style),
	uintptr(Timeout),
	uintptr(pResponse),
	uintptr(bWait),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WTSSendMessageA(
  hServer: THandle;   // HANDLE optional
  SessionId: DWORD;   // DWORD
  pTitle: PAnsiChar;   // LPSTR
  TitleLength: DWORD;   // DWORD
  pMessage: PAnsiChar;   // LPSTR
  MessageLength: DWORD;   // DWORD
  Style: DWORD;   // MESSAGEBOX_STYLE
  Timeout: DWORD;   // DWORD
  pResponse: Pointer;   // MESSAGEBOX_RESULT* out
  bWait: BOOL   // BOOL
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSSendMessageA';
result := DllCall("WTSAPI32\WTSSendMessageA"
    , "Ptr", hServer   ; HANDLE optional
    , "UInt", SessionId   ; DWORD
    , "AStr", pTitle   ; LPSTR
    , "UInt", TitleLength   ; DWORD
    , "AStr", pMessage   ; LPSTR
    , "UInt", MessageLength   ; DWORD
    , "UInt", Style   ; MESSAGEBOX_STYLE
    , "UInt", Timeout   ; DWORD
    , "Ptr", pResponse   ; MESSAGEBOX_RESULT* out
    , "Int", bWait   ; BOOL
    , "Int")   ; return: BOOL
●WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait) = DLL("WTSAPI32.dll", "bool WTSSendMessageA(void*, dword, char*, dword, char*, dword, dword, dword, void*, bool)")
# 呼び出し: WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
# hServer : HANDLE optional -> "void*"
# SessionId : DWORD -> "dword"
# pTitle : LPSTR -> "char*"
# TitleLength : DWORD -> "dword"
# pMessage : LPSTR -> "char*"
# MessageLength : DWORD -> "dword"
# Style : MESSAGEBOX_STYLE -> "dword"
# Timeout : DWORD -> "dword"
# pResponse : MESSAGEBOX_RESULT* out -> "void*"
# bWait : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "wtsapi32" fn WTSSendMessageA(
    hServer: ?*anyopaque, // HANDLE optional
    SessionId: u32, // DWORD
    pTitle: [*c]const u8, // LPSTR
    TitleLength: u32, // DWORD
    pMessage: [*c]const u8, // LPSTR
    MessageLength: u32, // DWORD
    Style: u32, // MESSAGEBOX_STYLE
    Timeout: u32, // DWORD
    pResponse: [*c]i32, // MESSAGEBOX_RESULT* out
    bWait: i32 // BOOL
) callconv(std.os.windows.WINAPI) i32;
proc WTSSendMessageA(
    hServer: pointer,  # HANDLE optional
    SessionId: uint32,  # DWORD
    pTitle: cstring,  # LPSTR
    TitleLength: uint32,  # DWORD
    pMessage: cstring,  # LPSTR
    MessageLength: uint32,  # DWORD
    Style: uint32,  # MESSAGEBOX_STYLE
    Timeout: uint32,  # DWORD
    pResponse: ptr int32,  # MESSAGEBOX_RESULT* out
    bWait: int32  # BOOL
): int32 {.importc: "WTSSendMessageA", stdcall, dynlib: "WTSAPI32.dll".}
pragma(lib, "wtsapi32");
extern(Windows)
int WTSSendMessageA(
    void* hServer,   // HANDLE optional
    uint SessionId,   // DWORD
    const(char)* pTitle,   // LPSTR
    uint TitleLength,   // DWORD
    const(char)* pMessage,   // LPSTR
    uint MessageLength,   // DWORD
    uint Style,   // MESSAGEBOX_STYLE
    uint Timeout,   // DWORD
    int* pResponse,   // MESSAGEBOX_RESULT* out
    int bWait   // BOOL
);
ccall((:WTSSendMessageA, "WTSAPI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, UInt32, Cstring, UInt32, Cstring, UInt32, UInt32, UInt32, Ptr{Int32}, Int32),
      hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
# hServer : HANDLE optional -> Ptr{Cvoid}
# SessionId : DWORD -> UInt32
# pTitle : LPSTR -> Cstring
# TitleLength : DWORD -> UInt32
# pMessage : LPSTR -> Cstring
# MessageLength : DWORD -> UInt32
# Style : MESSAGEBOX_STYLE -> UInt32
# Timeout : DWORD -> UInt32
# pResponse : MESSAGEBOX_RESULT* out -> Ptr{Int32}
# bWait : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WTSSendMessageA(
    void* hServer,
    uint32_t SessionId,
    const char* pTitle,
    uint32_t TitleLength,
    const char* pMessage,
    uint32_t MessageLength,
    uint32_t Style,
    uint32_t Timeout,
    int32_t* pResponse,
    int32_t bWait);
]]
local wtsapi32 = ffi.load("wtsapi32")
-- wtsapi32.WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
-- hServer : HANDLE optional
-- SessionId : DWORD
-- pTitle : LPSTR
-- TitleLength : DWORD
-- pMessage : LPSTR
-- MessageLength : DWORD
-- Style : MESSAGEBOX_STYLE
-- Timeout : DWORD
-- pResponse : MESSAGEBOX_RESULT* out
-- bWait : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WTSAPI32.dll');
const WTSSendMessageA = lib.func('__stdcall', 'WTSSendMessageA', 'int32_t', ['void *', 'uint32_t', 'str', 'uint32_t', 'str', 'uint32_t', 'uint32_t', 'uint32_t', 'int32_t *', 'int32_t']);
// WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
// hServer : HANDLE optional -> 'void *'
// SessionId : DWORD -> 'uint32_t'
// pTitle : LPSTR -> 'str'
// TitleLength : DWORD -> 'uint32_t'
// pMessage : LPSTR -> 'str'
// MessageLength : DWORD -> 'uint32_t'
// Style : MESSAGEBOX_STYLE -> 'uint32_t'
// Timeout : DWORD -> 'uint32_t'
// pResponse : MESSAGEBOX_RESULT* out -> 'int32_t *'
// bWait : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WTSAPI32.dll", {
  WTSSendMessageA: { parameters: ["pointer", "u32", "buffer", "u32", "buffer", "u32", "u32", "u32", "pointer", "i32"], result: "i32" },
});
// lib.symbols.WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait)
// hServer : HANDLE optional -> "pointer"
// SessionId : DWORD -> "u32"
// pTitle : LPSTR -> "buffer"
// TitleLength : DWORD -> "u32"
// pMessage : LPSTR -> "buffer"
// MessageLength : DWORD -> "u32"
// Style : MESSAGEBOX_STYLE -> "u32"
// Timeout : DWORD -> "u32"
// pResponse : MESSAGEBOX_RESULT* out -> "pointer"
// bWait : BOOL -> "i32"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WTSSendMessageA(
    void* hServer,
    uint32_t SessionId,
    const char* pTitle,
    uint32_t TitleLength,
    const char* pMessage,
    uint32_t MessageLength,
    uint32_t Style,
    uint32_t Timeout,
    int32_t* pResponse,
    int32_t bWait);
C, "WTSAPI32.dll");
// $ffi->WTSSendMessageA(hServer, SessionId, pTitle, TitleLength, pMessage, MessageLength, Style, Timeout, pResponse, bWait);
// hServer : HANDLE optional
// SessionId : DWORD
// pTitle : LPSTR
// TitleLength : DWORD
// pMessage : LPSTR
// MessageLength : DWORD
// Style : MESSAGEBOX_STYLE
// Timeout : DWORD
// pResponse : MESSAGEBOX_RESULT* out
// bWait : BOOL
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Wtsapi32 extends StdCallLibrary {
    Wtsapi32 INSTANCE = Native.load("wtsapi32", Wtsapi32.class, W32APIOptions.ASCII_OPTIONS);
    boolean WTSSendMessageA(
        Pointer hServer,   // HANDLE optional
        int SessionId,   // DWORD
        String pTitle,   // LPSTR
        int TitleLength,   // DWORD
        String pMessage,   // LPSTR
        int MessageLength,   // DWORD
        int Style,   // MESSAGEBOX_STYLE
        int Timeout,   // DWORD
        IntByReference pResponse,   // MESSAGEBOX_RESULT* out
        boolean bWait   // BOOL
    );
}
@[Link("wtsapi32")]
lib LibWTSAPI32
  fun WTSSendMessageA = WTSSendMessageA(
    hServer : Void*,   # HANDLE optional
    SessionId : UInt32,   # DWORD
    pTitle : UInt8*,   # LPSTR
    TitleLength : UInt32,   # DWORD
    pMessage : UInt8*,   # LPSTR
    MessageLength : UInt32,   # DWORD
    Style : UInt32,   # MESSAGEBOX_STYLE
    Timeout : UInt32,   # DWORD
    pResponse : Int32*,   # MESSAGEBOX_RESULT* out
    bWait : Int32   # BOOL
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WTSSendMessageANative = Int32 Function(Pointer<Void>, Uint32, Pointer<Utf8>, Uint32, Pointer<Utf8>, Uint32, Uint32, Uint32, Pointer<Int32>, Int32);
typedef WTSSendMessageADart = int Function(Pointer<Void>, int, Pointer<Utf8>, int, Pointer<Utf8>, int, int, int, Pointer<Int32>, int);
final WTSSendMessageA = DynamicLibrary.open('WTSAPI32.dll')
    .lookupFunction<WTSSendMessageANative, WTSSendMessageADart>('WTSSendMessageA');
// hServer : HANDLE optional -> Pointer<Void>
// SessionId : DWORD -> Uint32
// pTitle : LPSTR -> Pointer<Utf8>
// TitleLength : DWORD -> Uint32
// pMessage : LPSTR -> Pointer<Utf8>
// MessageLength : DWORD -> Uint32
// Style : MESSAGEBOX_STYLE -> Uint32
// Timeout : DWORD -> Uint32
// pResponse : MESSAGEBOX_RESULT* out -> Pointer<Int32>
// bWait : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WTSSendMessageA(
  hServer: THandle;   // HANDLE optional
  SessionId: DWORD;   // DWORD
  pTitle: PAnsiChar;   // LPSTR
  TitleLength: DWORD;   // DWORD
  pMessage: PAnsiChar;   // LPSTR
  MessageLength: DWORD;   // DWORD
  Style: DWORD;   // MESSAGEBOX_STYLE
  Timeout: DWORD;   // DWORD
  pResponse: Pointer;   // MESSAGEBOX_RESULT* out
  bWait: BOOL   // BOOL
): BOOL; stdcall;
  external 'WTSAPI32.dll' name 'WTSSendMessageA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WTSSendMessageA"
  c_WTSSendMessageA :: Ptr () -> Word32 -> CString -> Word32 -> CString -> Word32 -> Word32 -> Word32 -> Ptr Int32 -> CInt -> IO CInt
-- hServer : HANDLE optional -> Ptr ()
-- SessionId : DWORD -> Word32
-- pTitle : LPSTR -> CString
-- TitleLength : DWORD -> Word32
-- pMessage : LPSTR -> CString
-- MessageLength : DWORD -> Word32
-- Style : MESSAGEBOX_STYLE -> Word32
-- Timeout : DWORD -> Word32
-- pResponse : MESSAGEBOX_RESULT* out -> Ptr Int32
-- bWait : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let wtssendmessagea =
  foreign "WTSSendMessageA"
    ((ptr void) @-> uint32_t @-> string @-> uint32_t @-> string @-> uint32_t @-> uint32_t @-> uint32_t @-> (ptr int32_t) @-> int32_t @-> returning int32_t)
(* hServer : HANDLE optional -> (ptr void) *)
(* SessionId : DWORD -> uint32_t *)
(* pTitle : LPSTR -> string *)
(* TitleLength : DWORD -> uint32_t *)
(* pMessage : LPSTR -> string *)
(* MessageLength : DWORD -> uint32_t *)
(* Style : MESSAGEBOX_STYLE -> uint32_t *)
(* Timeout : DWORD -> uint32_t *)
(* pResponse : MESSAGEBOX_RESULT* out -> (ptr int32_t) *)
(* bWait : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library wtsapi32 (t "WTSAPI32.dll"))
(cffi:use-foreign-library wtsapi32)

(cffi:defcfun ("WTSSendMessageA" wtssend-message-a :convention :stdcall) :int32
  (h-server :pointer)   ; HANDLE optional
  (session-id :uint32)   ; DWORD
  (p-title :string)   ; LPSTR
  (title-length :uint32)   ; DWORD
  (p-message :string)   ; LPSTR
  (message-length :uint32)   ; DWORD
  (style :uint32)   ; MESSAGEBOX_STYLE
  (timeout :uint32)   ; DWORD
  (p-response :pointer)   ; MESSAGEBOX_RESULT* out
  (b-wait :int32))   ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WTSSendMessageA = Win32::API::More->new('WTSAPI32',
    'BOOL WTSSendMessageA(HANDLE hServer, DWORD SessionId, LPCSTR pTitle, DWORD TitleLength, LPCSTR pMessage, DWORD MessageLength, DWORD Style, DWORD Timeout, LPVOID pResponse, BOOL bWait)');
# my $ret = $WTSSendMessageA->Call($hServer, $SessionId, $pTitle, $TitleLength, $pMessage, $MessageLength, $Style, $Timeout, $pResponse, $bWait);
# hServer : HANDLE optional -> HANDLE
# SessionId : DWORD -> DWORD
# pTitle : LPSTR -> LPCSTR
# TitleLength : DWORD -> DWORD
# pMessage : LPSTR -> LPCSTR
# MessageLength : DWORD -> DWORD
# Style : MESSAGEBOX_STYLE -> DWORD
# Timeout : DWORD -> DWORD
# pResponse : MESSAGEBOX_RESULT* out -> LPVOID
# bWait : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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