Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. mailslot in mfc()

mailslot in mfc()

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++performance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mirraa
    wrote on last edited by
    #1

    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..

    D 1 Reply Last reply
    0
    • M mirraa

      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..

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups