Win32 API 日本語リファレンス
ホームNetworkManagement.Rras › MprAdminSendUserMessage

MprAdminSendUserMessage

関数
RASサーバーから接続中のユーザーにメッセージを送信する。
DLLMPRAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// MPRAPI.dll
#include <windows.h>

DWORD MprAdminSendUserMessage(
    INT_PTR hMprServer,
    HANDLE hConnection,
    LPWSTR lpwszMessage
);

パラメーター

名前方向説明
hMprServerINT_PTRinMprAdminServerConnectで取得したMPRサーバーハンドル(INT_PTR)。
hConnectionHANDLEinメッセージ送信先のRAS接続ハンドル。
lpwszMessageLPWSTRin接続中のユーザーへ送信するメッセージ文字列。

戻り値の型: DWORD

各言語での呼び出し定義

// MPRAPI.dll
#include <windows.h>

DWORD MprAdminSendUserMessage(
    INT_PTR hMprServer,
    HANDLE hConnection,
    LPWSTR lpwszMessage
);
[DllImport("MPRAPI.dll", ExactSpelling = true)]
static extern uint MprAdminSendUserMessage(
    IntPtr hMprServer,   // INT_PTR
    IntPtr hConnection,   // HANDLE
    [MarshalAs(UnmanagedType.LPWStr)] string lpwszMessage   // LPWSTR
);
<DllImport("MPRAPI.dll", ExactSpelling:=True)>
Public Shared Function MprAdminSendUserMessage(
    hMprServer As IntPtr,   ' INT_PTR
    hConnection As IntPtr,   ' HANDLE
    <MarshalAs(UnmanagedType.LPWStr)> lpwszMessage As String   ' LPWSTR
) As UInteger
End Function
' hMprServer : INT_PTR
' hConnection : HANDLE
' lpwszMessage : LPWSTR
Declare PtrSafe Function MprAdminSendUserMessage Lib "mprapi" ( _
    ByVal hMprServer As LongPtr, _
    ByVal hConnection As LongPtr, _
    ByVal lpwszMessage As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MprAdminSendUserMessage = ctypes.windll.mprapi.MprAdminSendUserMessage
MprAdminSendUserMessage.restype = wintypes.DWORD
MprAdminSendUserMessage.argtypes = [
    ctypes.c_ssize_t,  # hMprServer : INT_PTR
    wintypes.HANDLE,  # hConnection : HANDLE
    wintypes.LPCWSTR,  # lpwszMessage : LPWSTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('MPRAPI.dll')
MprAdminSendUserMessage = Fiddle::Function.new(
  lib['MprAdminSendUserMessage'],
  [
    Fiddle::TYPE_INTPTR_T,  # hMprServer : INT_PTR
    Fiddle::TYPE_VOIDP,  # hConnection : HANDLE
    Fiddle::TYPE_VOIDP,  # lpwszMessage : LPWSTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "mprapi")]
extern "system" {
    fn MprAdminSendUserMessage(
        hMprServer: isize,  // INT_PTR
        hConnection: *mut core::ffi::c_void,  // HANDLE
        lpwszMessage: *mut u16  // LPWSTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("MPRAPI.dll")]
public static extern uint MprAdminSendUserMessage(IntPtr hMprServer, IntPtr hConnection, [MarshalAs(UnmanagedType.LPWStr)] string lpwszMessage);
"@
$api = Add-Type -MemberDefinition $sig -Name 'MPRAPI_MprAdminSendUserMessage' -Namespace Win32 -PassThru
# $api::MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
#uselib "MPRAPI.dll"
#func global MprAdminSendUserMessage "MprAdminSendUserMessage" sptr, sptr, sptr
; MprAdminSendUserMessage hMprServer, hConnection, lpwszMessage   ; 戻り値は stat
; hMprServer : INT_PTR -> "sptr"
; hConnection : HANDLE -> "sptr"
; lpwszMessage : LPWSTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "MPRAPI.dll"
#cfunc global MprAdminSendUserMessage "MprAdminSendUserMessage" sptr, sptr, wstr
; res = MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
; hMprServer : INT_PTR -> "sptr"
; hConnection : HANDLE -> "sptr"
; lpwszMessage : LPWSTR -> "wstr"
; DWORD MprAdminSendUserMessage(INT_PTR hMprServer, HANDLE hConnection, LPWSTR lpwszMessage)
#uselib "MPRAPI.dll"
#cfunc global MprAdminSendUserMessage "MprAdminSendUserMessage" intptr, intptr, wstr
; res = MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
; hMprServer : INT_PTR -> "intptr"
; hConnection : HANDLE -> "intptr"
; lpwszMessage : LPWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mprapi = windows.NewLazySystemDLL("MPRAPI.dll")
	procMprAdminSendUserMessage = mprapi.NewProc("MprAdminSendUserMessage")
)

// hMprServer (INT_PTR), hConnection (HANDLE), lpwszMessage (LPWSTR)
r1, _, err := procMprAdminSendUserMessage.Call(
	uintptr(hMprServer),
	uintptr(hConnection),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpwszMessage))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MprAdminSendUserMessage(
  hMprServer: NativeInt;   // INT_PTR
  hConnection: THandle;   // HANDLE
  lpwszMessage: PWideChar   // LPWSTR
): DWORD; stdcall;
  external 'MPRAPI.dll' name 'MprAdminSendUserMessage';
result := DllCall("MPRAPI\MprAdminSendUserMessage"
    , "Ptr", hMprServer   ; INT_PTR
    , "Ptr", hConnection   ; HANDLE
    , "WStr", lpwszMessage   ; LPWSTR
    , "UInt")   ; return: DWORD
●MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage) = DLL("MPRAPI.dll", "dword MprAdminSendUserMessage(int, void*, char*)")
# 呼び出し: MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
# hMprServer : INT_PTR -> "int"
# hConnection : HANDLE -> "void*"
# lpwszMessage : LPWSTR -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mprapi" fn MprAdminSendUserMessage(
    hMprServer: isize, // INT_PTR
    hConnection: ?*anyopaque, // HANDLE
    lpwszMessage: [*c]const u16 // LPWSTR
) callconv(std.os.windows.WINAPI) u32;
proc MprAdminSendUserMessage(
    hMprServer: int,  # INT_PTR
    hConnection: pointer,  # HANDLE
    lpwszMessage: WideCString  # LPWSTR
): uint32 {.importc: "MprAdminSendUserMessage", stdcall, dynlib: "MPRAPI.dll".}
pragma(lib, "mprapi");
extern(Windows)
uint MprAdminSendUserMessage(
    ptrdiff_t hMprServer,   // INT_PTR
    void* hConnection,   // HANDLE
    const(wchar)* lpwszMessage   // LPWSTR
);
ccall((:MprAdminSendUserMessage, "MPRAPI.dll"), stdcall, UInt32,
      (Int, Ptr{Cvoid}, Cwstring),
      hMprServer, hConnection, lpwszMessage)
# hMprServer : INT_PTR -> Int
# hConnection : HANDLE -> Ptr{Cvoid}
# lpwszMessage : LPWSTR -> Cwstring
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t MprAdminSendUserMessage(
    intptr_t hMprServer,
    void* hConnection,
    const uint16_t* lpwszMessage);
]]
local mprapi = ffi.load("mprapi")
-- mprapi.MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
-- hMprServer : INT_PTR
-- hConnection : HANDLE
-- lpwszMessage : LPWSTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('MPRAPI.dll');
const MprAdminSendUserMessage = lib.func('__stdcall', 'MprAdminSendUserMessage', 'uint32_t', ['intptr_t', 'void *', 'str16']);
// MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
// hMprServer : INT_PTR -> 'intptr_t'
// hConnection : HANDLE -> 'void *'
// lpwszMessage : LPWSTR -> 'str16'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("MPRAPI.dll", {
  MprAdminSendUserMessage: { parameters: ["isize", "pointer", "buffer"], result: "u32" },
});
// lib.symbols.MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage)
// hMprServer : INT_PTR -> "isize"
// hConnection : HANDLE -> "pointer"
// lpwszMessage : LPWSTR -> "buffer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t MprAdminSendUserMessage(
    intptr_t hMprServer,
    void* hConnection,
    const uint16_t* lpwszMessage);
C, "MPRAPI.dll");
// $ffi->MprAdminSendUserMessage(hMprServer, hConnection, lpwszMessage);
// hMprServer : INT_PTR
// hConnection : HANDLE
// lpwszMessage : LPWSTR
// 構造体/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 Mprapi extends StdCallLibrary {
    Mprapi INSTANCE = Native.load("mprapi", Mprapi.class);
    int MprAdminSendUserMessage(
        long hMprServer,   // INT_PTR
        Pointer hConnection,   // HANDLE
        WString lpwszMessage   // LPWSTR
    );
}
@[Link("mprapi")]
lib LibMPRAPI
  fun MprAdminSendUserMessage = MprAdminSendUserMessage(
    hMprServer : LibC::SSizeT,   # INT_PTR
    hConnection : Void*,   # HANDLE
    lpwszMessage : UInt16*   # LPWSTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef MprAdminSendUserMessageNative = Uint32 Function(IntPtr, Pointer<Void>, Pointer<Utf16>);
typedef MprAdminSendUserMessageDart = int Function(int, Pointer<Void>, Pointer<Utf16>);
final MprAdminSendUserMessage = DynamicLibrary.open('MPRAPI.dll')
    .lookupFunction<MprAdminSendUserMessageNative, MprAdminSendUserMessageDart>('MprAdminSendUserMessage');
// hMprServer : INT_PTR -> IntPtr
// hConnection : HANDLE -> Pointer<Void>
// lpwszMessage : LPWSTR -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function MprAdminSendUserMessage(
  hMprServer: NativeInt;   // INT_PTR
  hConnection: THandle;   // HANDLE
  lpwszMessage: PWideChar   // LPWSTR
): DWORD; stdcall;
  external 'MPRAPI.dll' name 'MprAdminSendUserMessage';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "MprAdminSendUserMessage"
  c_MprAdminSendUserMessage :: CIntPtr -> Ptr () -> CWString -> IO Word32
-- hMprServer : INT_PTR -> CIntPtr
-- hConnection : HANDLE -> Ptr ()
-- lpwszMessage : LPWSTR -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let mpradminsendusermessage =
  foreign "MprAdminSendUserMessage"
    (intptr_t @-> (ptr void) @-> (ptr uint16_t) @-> returning uint32_t)
(* hMprServer : INT_PTR -> intptr_t *)
(* hConnection : HANDLE -> (ptr void) *)
(* lpwszMessage : LPWSTR -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mprapi (t "MPRAPI.dll"))
(cffi:use-foreign-library mprapi)

(cffi:defcfun ("MprAdminSendUserMessage" mpr-admin-send-user-message :convention :stdcall) :uint32
  (h-mpr-server :int64)   ; INT_PTR
  (h-connection :pointer)   ; HANDLE
  (lpwsz-message (:string :encoding :utf-16le)))   ; LPWSTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $MprAdminSendUserMessage = Win32::API::More->new('MPRAPI',
    'DWORD MprAdminSendUserMessage(LPARAM hMprServer, HANDLE hConnection, LPCWSTR lpwszMessage)');
# my $ret = $MprAdminSendUserMessage->Call($hMprServer, $hConnection, $lpwszMessage);
# hMprServer : INT_PTR -> LPARAM
# hConnection : HANDLE -> HANDLE
# lpwszMessage : LPWSTR -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。