简体   繁体   中英

getting error code 998 Invalid access to memory location when trying to read from named pipe

I created a named pipe using WCF and C#, and a client to connect to it so that I know that it is working correctly. Now I'm trying to create a c++ client. So far I have been able to get the name of the pipe, connect to it, and write some data to it. When I try to read from it I'm getting error code 998 Invalid access to memory location . Here is the code I'm using:

HANDLE hPipe = CreateFile(pipeName.c_str(), GENERIC_WRITE | GENERIC_READ, 2, NULL, OPEN_EXISTING, NULL, NULL);
BOOL bWrite = WriteFile(hPipe, &message, size, &bytesWritten, NULL);
LPVOID buffer = 0;
DWORD bytesRead;
BOOL bRead = ReadFile(hPipe, buffer, 10, &bytesRead, NULL);

I'm not sure what I'm doing wrong.

No memory has been allocated for buffer , it is currently a null pointer, and the code is requesting that 10 bytes of data be read into an array that does not exist. From ReadFile() :

lpBuffer [out]

A pointer to the buffer that receives the data read from a file or device.

To rectify:

char buffer[10];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM