Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c和x2B之间的通信+;和c#通过管道 < P>我想通过管道将C语言应用程序的数据发送到C++应用程序。 以下是我所做的: 这是C++客户端: #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { HANDLE hFile; BOOL flg; DWORD dwWrite; char szPipeUpdate[200]; hFile = CreateFile(L"\\\\.\\pipe\\BvrPipe", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); strcpy(szPipeUpdate,"Data from Named Pipe client for createnamedpipe"); if(hFile == INVALID_HANDLE_VALUE) { DWORD dw = GetLastError(); printf("CreateFile failed for Named Pipe client\n:" ); } else { flg = WriteFile(hFile, szPipeUpdate, strlen(szPipeUpdate), &dwWrite, NULL); if (FALSE == flg) { printf("WriteFile failed for Named Pipe client\n"); } else { printf("WriteFile succeeded for Named Pipe client\n"); } CloseHandle(hFile); } return 0;_C#_C++_Ipc - Fatal编程技术网

c和x2B之间的通信+;和c#通过管道 < P>我想通过管道将C语言应用程序的数据发送到C++应用程序。 以下是我所做的: 这是C++客户端: #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { HANDLE hFile; BOOL flg; DWORD dwWrite; char szPipeUpdate[200]; hFile = CreateFile(L"\\\\.\\pipe\\BvrPipe", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); strcpy(szPipeUpdate,"Data from Named Pipe client for createnamedpipe"); if(hFile == INVALID_HANDLE_VALUE) { DWORD dw = GetLastError(); printf("CreateFile failed for Named Pipe client\n:" ); } else { flg = WriteFile(hFile, szPipeUpdate, strlen(szPipeUpdate), &dwWrite, NULL); if (FALSE == flg) { printf("WriteFile failed for Named Pipe client\n"); } else { printf("WriteFile succeeded for Named Pipe client\n"); } CloseHandle(hFile); } return 0;

c和x2B之间的通信+;和c#通过管道 < P>我想通过管道将C语言应用程序的数据发送到C++应用程序。 以下是我所做的: 这是C++客户端: #include "stdafx.h" #include <windows.h> #include <stdio.h> int _tmain(int argc, _TCHAR* argv[]) { HANDLE hFile; BOOL flg; DWORD dwWrite; char szPipeUpdate[200]; hFile = CreateFile(L"\\\\.\\pipe\\BvrPipe", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); strcpy(szPipeUpdate,"Data from Named Pipe client for createnamedpipe"); if(hFile == INVALID_HANDLE_VALUE) { DWORD dw = GetLastError(); printf("CreateFile failed for Named Pipe client\n:" ); } else { flg = WriteFile(hFile, szPipeUpdate, strlen(szPipeUpdate), &dwWrite, NULL); if (FALSE == flg) { printf("WriteFile failed for Named Pipe client\n"); } else { printf("WriteFile succeeded for Named Pipe client\n"); } CloseHandle(hFile); } return 0;,c#,c++,ipc,C#,C++,Ipc,} 当我启动服务器,然后客户端GetLastError从客户端返回2时(系统找不到指定的文件) 有什么想法吗。 谢谢请阅读了解管道是如何实现的。为什么不使用CreateNamedPipes API调用?您将C++中的文件句柄作为普通文件而不是管道来处理。因此,C++代码在查找管道时失败,实际上它试图从文件中读取。 < P>猜测,我认为在服务器中创建管道时不需要“\\Boobe”前缀。我看到的调用NamedPipeServerStream构造函数的方法只是传入管道名称。例如 using (Name

}

当我启动服务器,然后客户端GetLastError从客户端返回2时(系统找不到指定的文件)

有什么想法吗。
谢谢

请阅读了解管道是如何实现的。为什么不使用CreateNamedPipes API调用?您将C++中的文件句柄作为普通文件而不是管道来处理。因此,C++代码在查找管道时失败,实际上它试图从文件中读取。

< P>猜测,我认为在服务器中创建管道时不需要“\\Boobe”前缀。我看到的调用NamedPipeServerStream构造函数的方法只是传入管道名称。例如

using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("BvrPipe"))

您可以使用SysInternals process explorer列出打开的管道及其名称。这将帮助您验证管道的名称是否正确。有关详细信息,请参见问题。

使用CreateFile()打开管道的客户端是完全有效的。请参阅CreateFile函数()的备注部分。@andyjohnson:我不知道您可以这样做……我的错……很抱歉,这是一个误导性的陈述……:(我可以确认,我在C和C++之间使用了管道,在创建NAMEDPIPER流时,我没有在管道名称上使用管道\前缀。在上面的代码中,直到我们从C++代码中调用Cube句柄上的CeleHealt,数据才被传递给C server。有没有办法可以通过而不关闭句柄?我尝试过“FrHulfFieldBuffes”。功能也一样。它的力量work@Raveendra无法刷新套接字。有关信息,请参阅。另请参阅。
using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("BvrPipe"))