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

CreateMailslotW

関数
Unicode名でメールスロットを作成する。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateMailslotW(
    LPCWSTR lpName,
    DWORD nMaxMessageSize,
    DWORD lReadTimeout,
    SECURITY_ATTRIBUTES* lpSecurityAttributes   // optional
);

パラメーター

名前方向
lpNameLPCWSTRin
nMaxMessageSizeDWORDin
lReadTimeoutDWORDin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional

戻り値の型: HANDLE

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateMailslotW(
    LPCWSTR lpName,
    DWORD nMaxMessageSize,
    DWORD lReadTimeout,
    SECURITY_ATTRIBUTES* lpSecurityAttributes   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateMailslotW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpName,   // LPCWSTR
    uint nMaxMessageSize,   // DWORD
    uint lReadTimeout,   // DWORD
    IntPtr lpSecurityAttributes   // SECURITY_ATTRIBUTES* optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateMailslotW(
    <MarshalAs(UnmanagedType.LPWStr)> lpName As String,   ' LPCWSTR
    nMaxMessageSize As UInteger,   ' DWORD
    lReadTimeout As UInteger,   ' DWORD
    lpSecurityAttributes As IntPtr   ' SECURITY_ATTRIBUTES* optional
) As IntPtr
End Function
' lpName : LPCWSTR
' nMaxMessageSize : DWORD
' lReadTimeout : DWORD
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
Declare PtrSafe Function CreateMailslotW Lib "kernel32" ( _
    ByVal lpName As LongPtr, _
    ByVal nMaxMessageSize As Long, _
    ByVal lReadTimeout As Long, _
    ByVal lpSecurityAttributes As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateMailslotW = ctypes.windll.kernel32.CreateMailslotW
CreateMailslotW.restype = ctypes.c_void_p
CreateMailslotW.argtypes = [
    wintypes.LPCWSTR,  # lpName : LPCWSTR
    wintypes.DWORD,  # nMaxMessageSize : DWORD
    wintypes.DWORD,  # lReadTimeout : DWORD
    ctypes.c_void_p,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CreateMailslotW = Fiddle::Function.new(
  lib['CreateMailslotW'],
  [
    Fiddle::TYPE_VOIDP,  # lpName : LPCWSTR
    -Fiddle::TYPE_INT,  # nMaxMessageSize : DWORD
    -Fiddle::TYPE_INT,  # lReadTimeout : DWORD
    Fiddle::TYPE_VOIDP,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn CreateMailslotW(
        lpName: *const u16,  // LPCWSTR
        nMaxMessageSize: u32,  // DWORD
        lReadTimeout: u32,  // DWORD
        lpSecurityAttributes: *mut SECURITY_ATTRIBUTES  // SECURITY_ATTRIBUTES* optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateMailslotW([MarshalAs(UnmanagedType.LPWStr)] string lpName, uint nMaxMessageSize, uint lReadTimeout, IntPtr lpSecurityAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateMailslotW' -Namespace Win32 -PassThru
# $api::CreateMailslotW(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes)
#uselib "KERNEL32.dll"
#func global CreateMailslotW "CreateMailslotW" wptr, wptr, wptr, wptr
; CreateMailslotW lpName, nMaxMessageSize, lReadTimeout, varptr(lpSecurityAttributes)   ; 戻り値は stat
; lpName : LPCWSTR -> "wptr"
; nMaxMessageSize : DWORD -> "wptr"
; lReadTimeout : DWORD -> "wptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateMailslotW "CreateMailslotW" wstr, int, int, var
; res = CreateMailslotW(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes)
; lpName : LPCWSTR -> "wstr"
; nMaxMessageSize : DWORD -> "int"
; lReadTimeout : DWORD -> "int"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateMailslotW(LPCWSTR lpName, DWORD nMaxMessageSize, DWORD lReadTimeout, SECURITY_ATTRIBUTES* lpSecurityAttributes)
#uselib "KERNEL32.dll"
#cfunc global CreateMailslotW "CreateMailslotW" wstr, int, int, var
; res = CreateMailslotW(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes)
; lpName : LPCWSTR -> "wstr"
; nMaxMessageSize : DWORD -> "int"
; lReadTimeout : DWORD -> "int"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateMailslotW = kernel32.NewProc("CreateMailslotW")
)

// lpName (LPCWSTR), nMaxMessageSize (DWORD), lReadTimeout (DWORD), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional)
r1, _, err := procCreateMailslotW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
	uintptr(nMaxMessageSize),
	uintptr(lReadTimeout),
	uintptr(lpSecurityAttributes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateMailslotW(
  lpName: PWideChar;   // LPCWSTR
  nMaxMessageSize: DWORD;   // DWORD
  lReadTimeout: DWORD;   // DWORD
  lpSecurityAttributes: Pointer   // SECURITY_ATTRIBUTES* optional
): THandle; stdcall;
  external 'KERNEL32.dll' name 'CreateMailslotW';
result := DllCall("KERNEL32\CreateMailslotW"
    , "WStr", lpName   ; LPCWSTR
    , "UInt", nMaxMessageSize   ; DWORD
    , "UInt", lReadTimeout   ; DWORD
    , "Ptr", lpSecurityAttributes   ; SECURITY_ATTRIBUTES* optional
    , "Ptr")   ; return: HANDLE
●CreateMailslotW(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes) = DLL("KERNEL32.dll", "void* CreateMailslotW(char*, dword, dword, void*)")
# 呼び出し: CreateMailslotW(lpName, nMaxMessageSize, lReadTimeout, lpSecurityAttributes)
# lpName : LPCWSTR -> "char*"
# nMaxMessageSize : DWORD -> "dword"
# lReadTimeout : DWORD -> "dword"
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。