ホーム › System.Pipes › CreateNamedPipeW
CreateNamedPipeW
関数名前付きパイプのインスタンスを作成する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE CreateNamedPipeW(
LPCWSTR lpName,
FILE_FLAGS_AND_ATTRIBUTES dwOpenMode,
NAMED_PIPE_MODE dwPipeMode,
DWORD nMaxInstances,
DWORD nOutBufferSize,
DWORD nInBufferSize,
DWORD nDefaultTimeOut,
SECURITY_ATTRIBUTES* lpSecurityAttributes // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpName | LPCWSTR | in |
| dwOpenMode | FILE_FLAGS_AND_ATTRIBUTES | in |
| dwPipeMode | NAMED_PIPE_MODE | in |
| nMaxInstances | DWORD | in |
| nOutBufferSize | DWORD | in |
| nInBufferSize | DWORD | in |
| nDefaultTimeOut | DWORD | in |
| lpSecurityAttributes | SECURITY_ATTRIBUTES* | inoptional |
戻り値の型: HANDLE
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE CreateNamedPipeW(
LPCWSTR lpName,
FILE_FLAGS_AND_ATTRIBUTES dwOpenMode,
NAMED_PIPE_MODE dwPipeMode,
DWORD nMaxInstances,
DWORD nOutBufferSize,
DWORD nInBufferSize,
DWORD nDefaultTimeOut,
SECURITY_ATTRIBUTES* lpSecurityAttributes // optional
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern IntPtr CreateNamedPipeW(
[MarshalAs(UnmanagedType.LPWStr)] string lpName, // LPCWSTR
uint dwOpenMode, // FILE_FLAGS_AND_ATTRIBUTES
uint dwPipeMode, // NAMED_PIPE_MODE
uint nMaxInstances, // DWORD
uint nOutBufferSize, // DWORD
uint nInBufferSize, // DWORD
uint nDefaultTimeOut, // DWORD
IntPtr lpSecurityAttributes // SECURITY_ATTRIBUTES* optional
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function CreateNamedPipeW(
<MarshalAs(UnmanagedType.LPWStr)> lpName As String, ' LPCWSTR
dwOpenMode As UInteger, ' FILE_FLAGS_AND_ATTRIBUTES
dwPipeMode As UInteger, ' NAMED_PIPE_MODE
nMaxInstances As UInteger, ' DWORD
nOutBufferSize As UInteger, ' DWORD
nInBufferSize As UInteger, ' DWORD
nDefaultTimeOut As UInteger, ' DWORD
lpSecurityAttributes As IntPtr ' SECURITY_ATTRIBUTES* optional
) As IntPtr
End Function' lpName : LPCWSTR
' dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES
' dwPipeMode : NAMED_PIPE_MODE
' nMaxInstances : DWORD
' nOutBufferSize : DWORD
' nInBufferSize : DWORD
' nDefaultTimeOut : DWORD
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
Declare PtrSafe Function CreateNamedPipeW Lib "kernel32" ( _
ByVal lpName As LongPtr, _
ByVal dwOpenMode As Long, _
ByVal dwPipeMode As Long, _
ByVal nMaxInstances As Long, _
ByVal nOutBufferSize As Long, _
ByVal nInBufferSize As Long, _
ByVal nDefaultTimeOut 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
CreateNamedPipeW = ctypes.windll.kernel32.CreateNamedPipeW
CreateNamedPipeW.restype = ctypes.c_void_p
CreateNamedPipeW.argtypes = [
wintypes.LPCWSTR, # lpName : LPCWSTR
wintypes.DWORD, # dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES
wintypes.DWORD, # dwPipeMode : NAMED_PIPE_MODE
wintypes.DWORD, # nMaxInstances : DWORD
wintypes.DWORD, # nOutBufferSize : DWORD
wintypes.DWORD, # nInBufferSize : DWORD
wintypes.DWORD, # nDefaultTimeOut : DWORD
ctypes.c_void_p, # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
CreateNamedPipeW = Fiddle::Function.new(
lib['CreateNamedPipeW'],
[
Fiddle::TYPE_VOIDP, # lpName : LPCWSTR
-Fiddle::TYPE_INT, # dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES
-Fiddle::TYPE_INT, # dwPipeMode : NAMED_PIPE_MODE
-Fiddle::TYPE_INT, # nMaxInstances : DWORD
-Fiddle::TYPE_INT, # nOutBufferSize : DWORD
-Fiddle::TYPE_INT, # nInBufferSize : DWORD
-Fiddle::TYPE_INT, # nDefaultTimeOut : 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 CreateNamedPipeW(
lpName: *const u16, // LPCWSTR
dwOpenMode: u32, // FILE_FLAGS_AND_ATTRIBUTES
dwPipeMode: u32, // NAMED_PIPE_MODE
nMaxInstances: u32, // DWORD
nOutBufferSize: u32, // DWORD
nInBufferSize: u32, // DWORD
nDefaultTimeOut: 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)]
public static extern IntPtr CreateNamedPipeW([MarshalAs(UnmanagedType.LPWStr)] string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateNamedPipeW' -Namespace Win32 -PassThru
# $api::CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)#uselib "KERNEL32.dll"
#func global CreateNamedPipeW "CreateNamedPipeW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CreateNamedPipeW lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, varptr(lpSecurityAttributes) ; 戻り値は stat
; lpName : LPCWSTR -> "wptr"
; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "wptr"
; dwPipeMode : NAMED_PIPE_MODE -> "wptr"
; nMaxInstances : DWORD -> "wptr"
; nOutBufferSize : DWORD -> "wptr"
; nInBufferSize : DWORD -> "wptr"
; nDefaultTimeOut : DWORD -> "wptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global CreateNamedPipeW "CreateNamedPipeW" wstr, int, int, int, int, int, int, var ; res = CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes) ; lpName : LPCWSTR -> "wstr" ; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "int" ; dwPipeMode : NAMED_PIPE_MODE -> "int" ; nMaxInstances : DWORD -> "int" ; nOutBufferSize : DWORD -> "int" ; nInBufferSize : DWORD -> "int" ; nDefaultTimeOut : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global CreateNamedPipeW "CreateNamedPipeW" wstr, int, int, int, int, int, int, sptr ; res = CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, varptr(lpSecurityAttributes)) ; lpName : LPCWSTR -> "wstr" ; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "int" ; dwPipeMode : NAMED_PIPE_MODE -> "int" ; nMaxInstances : DWORD -> "int" ; nOutBufferSize : DWORD -> "int" ; nInBufferSize : DWORD -> "int" ; nDefaultTimeOut : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE CreateNamedPipeW(LPCWSTR lpName, FILE_FLAGS_AND_ATTRIBUTES dwOpenMode, NAMED_PIPE_MODE dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, SECURITY_ATTRIBUTES* lpSecurityAttributes) #uselib "KERNEL32.dll" #cfunc global CreateNamedPipeW "CreateNamedPipeW" wstr, int, int, int, int, int, int, var ; res = CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes) ; lpName : LPCWSTR -> "wstr" ; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "int" ; dwPipeMode : NAMED_PIPE_MODE -> "int" ; nMaxInstances : DWORD -> "int" ; nOutBufferSize : DWORD -> "int" ; nInBufferSize : DWORD -> "int" ; nDefaultTimeOut : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE CreateNamedPipeW(LPCWSTR lpName, FILE_FLAGS_AND_ATTRIBUTES dwOpenMode, NAMED_PIPE_MODE dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, SECURITY_ATTRIBUTES* lpSecurityAttributes) #uselib "KERNEL32.dll" #cfunc global CreateNamedPipeW "CreateNamedPipeW" wstr, int, int, int, int, int, int, intptr ; res = CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, varptr(lpSecurityAttributes)) ; lpName : LPCWSTR -> "wstr" ; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "int" ; dwPipeMode : NAMED_PIPE_MODE -> "int" ; nMaxInstances : DWORD -> "int" ; nOutBufferSize : DWORD -> "int" ; nInBufferSize : DWORD -> "int" ; nDefaultTimeOut : DWORD -> "int" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCreateNamedPipeW = kernel32.NewProc("CreateNamedPipeW")
)
// lpName (LPCWSTR), dwOpenMode (FILE_FLAGS_AND_ATTRIBUTES), dwPipeMode (NAMED_PIPE_MODE), nMaxInstances (DWORD), nOutBufferSize (DWORD), nInBufferSize (DWORD), nDefaultTimeOut (DWORD), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional)
r1, _, err := procCreateNamedPipeW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpName))),
uintptr(dwOpenMode),
uintptr(dwPipeMode),
uintptr(nMaxInstances),
uintptr(nOutBufferSize),
uintptr(nInBufferSize),
uintptr(nDefaultTimeOut),
uintptr(lpSecurityAttributes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction CreateNamedPipeW(
lpName: PWideChar; // LPCWSTR
dwOpenMode: DWORD; // FILE_FLAGS_AND_ATTRIBUTES
dwPipeMode: DWORD; // NAMED_PIPE_MODE
nMaxInstances: DWORD; // DWORD
nOutBufferSize: DWORD; // DWORD
nInBufferSize: DWORD; // DWORD
nDefaultTimeOut: DWORD; // DWORD
lpSecurityAttributes: Pointer // SECURITY_ATTRIBUTES* optional
): THandle; stdcall;
external 'KERNEL32.dll' name 'CreateNamedPipeW';result := DllCall("KERNEL32\CreateNamedPipeW"
, "WStr", lpName ; LPCWSTR
, "UInt", dwOpenMode ; FILE_FLAGS_AND_ATTRIBUTES
, "UInt", dwPipeMode ; NAMED_PIPE_MODE
, "UInt", nMaxInstances ; DWORD
, "UInt", nOutBufferSize ; DWORD
, "UInt", nInBufferSize ; DWORD
, "UInt", nDefaultTimeOut ; DWORD
, "Ptr", lpSecurityAttributes ; SECURITY_ATTRIBUTES* optional
, "Ptr") ; return: HANDLE●CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes) = DLL("KERNEL32.dll", "void* CreateNamedPipeW(char*, dword, dword, dword, dword, dword, dword, void*)")
# 呼び出し: CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
# lpName : LPCWSTR -> "char*"
# dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "dword"
# dwPipeMode : NAMED_PIPE_MODE -> "dword"
# nMaxInstances : DWORD -> "dword"
# nOutBufferSize : DWORD -> "dword"
# nInBufferSize : DWORD -> "dword"
# nDefaultTimeOut : DWORD -> "dword"
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。