[英]Using C#, how do you connect to a C++ Named Pipe that is mono-directional?
我在C ++程序Server
創建了一個命名管道,我想在C#應用程序Client
連接到它。 我用C ++編寫了一些測試代碼,並且可以將其寫到管道中。 我遇到的問題是獲取C#代碼寫入命名管道。 現在,它引發了System.UnauthorizedAccessException' occurred in System.Core.dll
異常中System.UnauthorizedAccessException' occurred in System.Core.dll
的System.UnauthorizedAccessException' occurred in System.Core.dll
。 這兩個程序都以admin身份在Visual Studio中運行,我的設置是否錯誤?
C ++服務器
pipe_handle = CreateNamedPipe("\\\\.\\pipe\\StackPipe", // Name of Pipe
PIPE_ACCESS_INBOUND, // Direction of Pipe
PIPE_TYPE_MESSAGE |PIPE_READMODE_MESSAGE | PIPE_WAIT, // Pipe Mode
1, // Maximum instances
0, // Output Buffer Size
(BUFFER_MAX*sizeof(_TCHAR)), // Input Buffer Size
NMPWAIT_USE_DEFAULT_WAIT, // Default Time Out
NULL); // Security Attributes - Admin and System
C ++測試客戶端
WaitNamedPipe(L"\\\\.\\pipe\\StackPipe", NMPWAIT_WAIT_FOREVER);
HANDLE hpipe = CreateFile( L"\\\\.\\pipe\\StackPipe", //Formatting is different
GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
C#客戶端
NamedPipeClientStream pipeClient =
new NamedPipeClientStream( ".",
"StackPipe",
PipeDirection.In,
PipeOptions.Asynchronous, TokenImpersonationLevel.Identification);
pipeClient.Connect(); //Fails Here
感謝@Harry Johnston,我誤讀了方向:
NamedPipeClientStream pipeClient =
new NamedPipeClientStream( ".",
"StackPipe",
PipeDirection.Out, // Change Direction
PipeOptions.Asynchronous);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.