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