mailslot in mfc()
-
hi in my program i have to write some msgs in a mailslot in one computerand i ve to read them in another computer.. the code i'm using for writing is: handle = CreateFile("\\\\park-testbench4\\mailslot\\sample1", GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (handle == INVALID_HANDLE_VALUE) { printf("error in creating mailslot"); } err = WriteFile(handle, MyMessage, sizeof(MyMessage), &numWritten, 0); if (!err) { printf("error in writing"); } if (sizeof(MyMessage) != numWritten) printf("WriteFile did not read the correct number of bytes!\n"); park-testbench4 is my computer name..its writing fine... and i'm using the following code to read: handle = CreateMailslot("\\\\park-testbench4\\mailslot\\sample1", 0, MAILSLOT_WAIT_FOREVER, NULL); if (handle == INVALID_HANDLE_VALUE) { printf("error in creating mailslot :%d",GetLastError()); } for (;;) { DWORD msgSize; BOOL err; err = GetMailslotInfo(handle, 0, &msgSize, 0, 0); if (!err) { printf("GetMailslotInfo failed"); } if (msgSize != (DWORD)MAILSLOT_NO_MESSAGE) { char * buffer; buffer = (char*) malloc(100); if (!buffer) printf("An error getting a memory block!"); else { DWORD numRead; err = ReadFile(handle, buffer, msgSize, &numRead, 0); if (!err) printf("ReadFile error: %d", GetLastError()); else if (msgSize != numRead) printf("ReadFile did not read the correct number of bytes!"); else { printf("%s",buffer); } GlobalFree(buffer); } } Sleep(1000); } } but error is coming as Error in creating mailslot ... why i'm getting such error only during reading... any help.. thanx n advance..
-
hi in my program i have to write some msgs in a mailslot in one computerand i ve to read them in another computer.. the code i'm using for writing is: handle = CreateFile("\\\\park-testbench4\\mailslot\\sample1", GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (handle == INVALID_HANDLE_VALUE) { printf("error in creating mailslot"); } err = WriteFile(handle, MyMessage, sizeof(MyMessage), &numWritten, 0); if (!err) { printf("error in writing"); } if (sizeof(MyMessage) != numWritten) printf("WriteFile did not read the correct number of bytes!\n"); park-testbench4 is my computer name..its writing fine... and i'm using the following code to read: handle = CreateMailslot("\\\\park-testbench4\\mailslot\\sample1", 0, MAILSLOT_WAIT_FOREVER, NULL); if (handle == INVALID_HANDLE_VALUE) { printf("error in creating mailslot :%d",GetLastError()); } for (;;) { DWORD msgSize; BOOL err; err = GetMailslotInfo(handle, 0, &msgSize, 0, 0); if (!err) { printf("GetMailslotInfo failed"); } if (msgSize != (DWORD)MAILSLOT_NO_MESSAGE) { char * buffer; buffer = (char*) malloc(100); if (!buffer) printf("An error getting a memory block!"); else { DWORD numRead; err = ReadFile(handle, buffer, msgSize, &numRead, 0); if (!err) printf("ReadFile error: %d", GetLastError()); else if (msgSize != numRead) printf("ReadFile did not read the correct number of bytes!"); else { printf("%s",buffer); } GlobalFree(buffer); } } Sleep(1000); } } but error is coming as Error in creating mailslot ... why i'm getting such error only during reading... any help.. thanx n advance..
mirraa wrote:
but error is coming as Error in creating mailslot ...
What is the actual error?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne