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

CreateNamedPipeA

関数
名前付きパイプのインスタンスを作成する(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HANDLE CreateNamedPipeA(
    LPCSTR lpName,
    FILE_FLAGS_AND_ATTRIBUTES dwOpenMode,
    NAMED_PIPE_MODE dwPipeMode,
    DWORD nMaxInstances,
    DWORD nOutBufferSize,
    DWORD nInBufferSize,
    DWORD nDefaultTimeOut,
    SECURITY_ATTRIBUTES* lpSecurityAttributes   // optional
);

パラメーター

名前方向
lpNameLPCSTRin
dwOpenModeFILE_FLAGS_AND_ATTRIBUTESin
dwPipeModeNAMED_PIPE_MODEin
nMaxInstancesDWORDin
nOutBufferSizeDWORDin
nInBufferSizeDWORDin
nDefaultTimeOutDWORDin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE CreateNamedPipeA(
    LPCSTR 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.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateNamedPipeA(
    [MarshalAs(UnmanagedType.LPStr)] string lpName,   // LPCSTR
    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.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateNamedPipeA(
    <MarshalAs(UnmanagedType.LPStr)> lpName As String,   ' LPCSTR
    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 : LPCSTR
' dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES
' dwPipeMode : NAMED_PIPE_MODE
' nMaxInstances : DWORD
' nOutBufferSize : DWORD
' nInBufferSize : DWORD
' nDefaultTimeOut : DWORD
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
Declare PtrSafe Function CreateNamedPipeA Lib "kernel32" ( _
    ByVal lpName As String, _
    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
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateNamedPipeA = ctypes.windll.kernel32.CreateNamedPipeA
CreateNamedPipeA.restype = ctypes.c_void_p
CreateNamedPipeA.argtypes = [
    wintypes.LPCSTR,  # lpName : LPCSTR
    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
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CreateNamedPipeA = Fiddle::Function.new(
  lib['CreateNamedPipeA'],
  [
    Fiddle::TYPE_VOIDP,  # lpName : LPCSTR
    -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)
#[link(name = "kernel32")]
extern "system" {
    fn CreateNamedPipeA(
        lpName: *const u8,  // LPCSTR
        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.Ansi, SetLastError = true)]
public static extern IntPtr CreateNamedPipeA([MarshalAs(UnmanagedType.LPStr)] string lpName, uint dwOpenMode, uint dwPipeMode, uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut, IntPtr lpSecurityAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateNamedPipeA' -Namespace Win32 -PassThru
# $api::CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
#uselib "KERNEL32.dll"
#func global CreateNamedPipeA "CreateNamedPipeA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateNamedPipeA lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, varptr(lpSecurityAttributes)   ; 戻り値は stat
; lpName : LPCSTR -> "sptr"
; dwOpenMode : FILE_FLAGS_AND_ATTRIBUTES -> "sptr"
; dwPipeMode : NAMED_PIPE_MODE -> "sptr"
; nMaxInstances : DWORD -> "sptr"
; nOutBufferSize : DWORD -> "sptr"
; nInBufferSize : DWORD -> "sptr"
; nDefaultTimeOut : DWORD -> "sptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateNamedPipeA "CreateNamedPipeA" str, int, int, int, int, int, int, var
; res = CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
; lpName : LPCSTR -> "str"
; 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 CreateNamedPipeA(LPCSTR 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 CreateNamedPipeA "CreateNamedPipeA" str, int, int, int, int, int, int, var
; res = CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
; lpName : LPCSTR -> "str"
; 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 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateNamedPipeA = kernel32.NewProc("CreateNamedPipeA")
)

// lpName (LPCSTR), dwOpenMode (FILE_FLAGS_AND_ATTRIBUTES), dwPipeMode (NAMED_PIPE_MODE), nMaxInstances (DWORD), nOutBufferSize (DWORD), nInBufferSize (DWORD), nDefaultTimeOut (DWORD), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional)
r1, _, err := procCreateNamedPipeA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(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   // HANDLE
function CreateNamedPipeA(
  lpName: PAnsiChar;   // LPCSTR
  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 'CreateNamedPipeA';
result := DllCall("KERNEL32\CreateNamedPipeA"
    , "AStr", lpName   ; LPCSTR
    , "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
●CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes) = DLL("KERNEL32.dll", "void* CreateNamedPipeA(char*, dword, dword, dword, dword, dword, dword, void*)")
# 呼び出し: CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
# lpName : LPCSTR -> "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)。