[英]c++ / c# Problem in named pipe
This is my c++ code 这是我的C ++代码
HANDLE hPipe = ::CreateNamedPipe(_T("\\\\.\\pipe\\FirstPipe"),
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
PIPE_UNLIMITED_INSTANCES,
4096,
4096,
0,
NULL);
ConnectNamedPipe(hPipe, NULL);
DWORD bytesWritten = 0;
WriteFile(hPipe, lpBuffers, sizeof(LPWSABUF), &bytesWritten, NULL);//LPWSABUF is structure and lpBuffers is a variable of this structure
This is my C# code 这是我的C#代码
uint dataLen = (uint)(br.ReadInt32());
string len = (dataLen).ToString();
listBox1.Items.Add(len);
IntPtr dataAdd = IntPtr.Zero;
string data = "";
if (IntPtr.Size == 4) dataAdd = (IntPtr)br.ReadInt32(); //ERROR
else dataAdd = (IntPtr)br.ReadInt64();
byte[] b = new byte[(int)dataLen];
Marshal.Copy(b, 0, dataAdd, (int)dataLen);
data = Encoding.Unicode.GetString(b);
listBox2.Items.Add(data);
In sixth line of C# code giving error. 在C#代码的第六行给出错误。 That End of the stream. 流的那一端。 I dont have any idea why it is giving error. 我不知道为什么它给错误。
Here is the structure 这是结构
typedef struct _WSABUF {
ULONG len; /* the length of the buffer */
__field_bcount(len) CHAR FAR *buf; /* the pointer to the buffer */
} WSABUF, FAR * LPWSABUF;
LPWSABUF is pointer, its size is 32 or 64 bit. LPWSABUF是指针,其大小为32或64位。 Possibly you mean this: 您可能的意思是:
WriteFile(hPipe, lpBuffers, sizeof(WSABUF), &bytesWritten, NULL);
simply you have reached end of stream so end of stream exception is thrown. 只是您已经到达流的末尾,所以抛出了流的末尾异常。 If it's the first read command from file then your file is empty 如果这是从文件中读取的第一个命令,则文件为空
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.