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. GetMailslotInfo returns incorrect lpMessageCount

GetMailslotInfo returns incorrect lpMessageCount

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
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
    mwilliamson
    wrote on last edited by
    #1

    I've got a program that uses mail slots. My problem is that when I send a mail message to the local machine the message is recieved twice. I have narrowed this down to my sending code by changing it to send to the microsoft messenger service. The messeneger service recieves the message twice too. However, it I use net send to send the message it is only recieved once. I think net send uses the NetMessageBufferSend function, but I should still only recieve once. If I send to a remote machine with the same code, it is only recieved once. I have tested it on two machines and both have the problem. My code to send is as follows: { int nResult; HANDLE pHandle; DWORD dwBytesSent; CString strMailslotName; strMailslotName = _T("\\\\"); strMailslotName += m_sComputerName; strMailslotName += _T("\\mailslot\\messngr"); pHandle = CreateFile( strMailslotName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( pHandle == INVALID_HANDLE_VALUE ) { AfxMessageBox("Error accessing mail slot \"" + strMailslotName + "\""); CloseHandle( pHandle ); return; } else { nResult = WriteFile( pHandle, strMsgText, ( DWORD )strMsgText.GetLength(), &dwBytesSent, NULL ); if( nResult == 0 || ( DWORD )strMsgText.GetLength() != dwBytesSent ) { CString Error; LPVOID lpMsgBuf; if (!::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL )) { AfxMessageBox("An unknown error occured."); } else { Error = "Error writing to mailslot: "; Error += (LPCTSTR)lpMsgBuf; AfxMessageBox(Error); } LocalFree( lpMsgBuf ); } } CloseHandle( pHandle ); } Any ideas whats wrong with this? I don't see how it could be sending two messages. m_sComputerName is the local computer's name. Thanks for you help!

    J 1 Reply Last reply
    0
    • M mwilliamson

      I've got a program that uses mail slots. My problem is that when I send a mail message to the local machine the message is recieved twice. I have narrowed this down to my sending code by changing it to send to the microsoft messenger service. The messeneger service recieves the message twice too. However, it I use net send to send the message it is only recieved once. I think net send uses the NetMessageBufferSend function, but I should still only recieve once. If I send to a remote machine with the same code, it is only recieved once. I have tested it on two machines and both have the problem. My code to send is as follows: { int nResult; HANDLE pHandle; DWORD dwBytesSent; CString strMailslotName; strMailslotName = _T("\\\\"); strMailslotName += m_sComputerName; strMailslotName += _T("\\mailslot\\messngr"); pHandle = CreateFile( strMailslotName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( pHandle == INVALID_HANDLE_VALUE ) { AfxMessageBox("Error accessing mail slot \"" + strMailslotName + "\""); CloseHandle( pHandle ); return; } else { nResult = WriteFile( pHandle, strMsgText, ( DWORD )strMsgText.GetLength(), &dwBytesSent, NULL ); if( nResult == 0 || ( DWORD )strMsgText.GetLength() != dwBytesSent ) { CString Error; LPVOID lpMsgBuf; if (!::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL )) { AfxMessageBox("An unknown error occured."); } else { Error = "Error writing to mailslot: "; Error += (LPCTSTR)lpMsgBuf; AfxMessageBox(Error); } LocalFree( lpMsgBuf ); } } CloseHandle( pHandle ); } Any ideas whats wrong with this? I don't see how it could be sending two messages. m_sComputerName is the local computer's name. Thanks for you help!

      J Offline
      J Offline
      Joel Lucsy
      wrote on last edited by
      #2

      This is actually by design. Sending on a mailslot goes across all the available protocals installed on the machine. This means if you have both TCP/IP and IPX installed, you'd get two messages. If you peruse the documentaion more carefully you'll see that this is documented. You need to include some kind of ID with the message to you can throw out duplicates. Also note that this protocal does not ensure order of deliverly. Just because msg 1 went out before msg 2 doesn't mean you'll get msg 1 before msg 2. In testing i've found that 99% of the time you'll get them in order, but the documentation say's it this isn't guaranteed. If you need further help, let me know. Joel Lucsy (jjlucsy@concentric.net)

      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