Solved

MSMQ / MSVC++ 6.0 / Reading empty messages via Events handler

Posted on 2001-08-13
4
271 Views
Last Modified: 2007-11-27
Hi.

I use MSMQ on Widows NT 4.0 with MS Visual C++ 6.0. I have COM object which is event handler (implements IDispEventImpl<0, CM3Server, &DIID__DMSMQEventEvents, &LIBID_MSMQ, 1, 0>) and at the same time serves as a connection point container (implements IConnectionPointContainerImpl<CM3Server>).

This COM object uses MSMQQueue COM objects, collects messages from some small number of queues (only one now), and dispatches all those messages to other COM objects which can handle them (this will be always one COM object at a time).

My problem is trivial: I send some text messages to the queue (checked, message is delivered to the queue and contains the right text) and when I read those messages asynchronously, message body is empty!!! Right type (VT_BSTR), but zero length...

Do you know the answer? .... I have headache when meditating about this - but the worst thing is that it sometimes works! When I "shootdown" server without destroying the queue and run it again, it works as it should always. When I create the queue in the same session, it still receives empty messages.

Please help, I am very unhappy about this!
Martin
0
Comment
Question by:Martin Bodlák
4 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 6382914
Are you using Receive or Peek?  Show the code that is returning the empty BSTR.

-- Dan
0
 

Author Comment

by:Martin Bodlák
ID: 6383021
Here id the code I use to receive messages...

/////////////////////////////////////////////////////////////////////////////
// CM3Server Sink Interface Methods

STDMETHODIMP CM3Server::Arrived(IDispatch* pIQueue, long lCursor)
{
     IMSMQMessagePtr     pMessage;
     _variant_t          vtBody;
     _bstr_t               wsTemp;

     m_nHResult = S_OK;
     try
     {
          IMSMQQueuePtr pQueue(pIQueue);

          try
          {
               wsTemp = pQueue->QueueInfo->GetServiceTypeGuid();
               if (M3_GUID_QFAKE == wsTemp) Redirector(pQueue, lCursor);

               if (pQueue->QueueInfo->IsTransactional == TRUE)
               {
                    IMSMQCoordinatedTransactionDispenserPtr
                         pXActDispenser(L"MSMQ.MSMQCoordinatedTransactionDispenser");
                    IMSMQTransactionPtr pXAct = pXActDispenser->BeginTransaction();

                    VARIANT vXAct;
                    vXAct.vt = VT_UNKNOWN;
                    vXAct.punkVal = static_cast<IUnknown*>(pXAct);

                    pMessage = pQueue->ReceiveCurrent(&vXAct);
               }
               else
                    pMessage = pQueue->ReceiveCurrent();

               if (pMessage)
               {
                    vtBody = pMessage->GetBody();
                    if (pMessage->BodyLength == 0)
                    {
                         wsTemp = GetErrorCust(L"???", ERR_EMPTYMESSAGE, STR_DM3ITS, STR_EMPTYMESSAGE);
                         ProcessErr(wsTemp, M3_ERR_QNOTMESSAGE);
                    }
                    else
                         ProcessMsg(vtBody.bstrVal, pQueue->QueueInfo->PathName);
               }
               else
               {
                    wsTemp = GetErrorCust(L"???", ERR_RECEIVEFAIL, STR_DM3ITS, STR_RECEIVEFAIL);
                    ProcessErr(wsTemp, M3_ERR_QNOTMESSAGE);
               }
          }
          catch (_com_error &err)
          {
               ProcessErr(GetErrorText(err, STR_DM3ITS), err.Error());
          }
          // _variant_t varCursor(static_cast<long>(MQMSG_NEXT));
          pQueue->EnableNotification(m_pEvent); // , &varCursor);
     }
     catch (_com_error &err)
     {
          ProcessErr(GetErrorText(err, STR_DM3ITS), err.Error());
     }
     return m_nHResult;
}

STDMETHODIMP CM3Server::ArrivedError(IDispatch* pIQueue, long lErrorCode, long lCursor)
{
     HMODULE     hMQUtil = GetModuleHandle(_T("MQUTIL.DLL"));
     TCHAR     pMsg[999];
     int          nChars = 0, nSize = sizeof(pMsg) / sizeof(TCHAR);
     _bstr_t bsMsg;

     m_nHResult = S_OK;
     if (lErrorCode != MQ_ERROR_IO_TIMEOUT)
     {
          if (hMQUtil != NULL)
          {
               nChars = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, hMQUtil, lErrorCode, 0, reinterpret_cast<LPTSTR>(&pMsg), nSize, NULL);
               if (nChars == 0)
               {
                    nChars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, lErrorCode, 0, reinterpret_cast<LPTSTR>(&pMsg), nSize, NULL);
                    if (nChars == 0)
                         _sntprintf(pMsg, nSize, _T("Unidentified error 0x%8Xd encountered"), lErrorCode);
               }
               bsMsg = pMsg;
          }
          ProcessErr(GetErrorCust(L"???", ERR_OTHER, STR_DM3ITS, bsMsg), lErrorCode);
     }
     else
     {
          try
          {
               IMSMQQueuePtr     pQueue(pIQueue);
               // _variant_t          vtCursor(lCursor);
               pQueue->EnableNotification(m_pEvent); //, &vtCursor);
          }
          catch (_com_error &err)
          {
               ProcessErr(GetErrorText(err, STR_DM3ITS), err.Error());
          }
     }
     M3RETURN(IID_IM3Server);
}
0
 
LVL 11

Expert Comment

by:griessh
ID: 6851215
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. Unless there is objection or further activity,  I will suggest to refund the points and delete this question since nobody had an answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 6874970
Per recommendation points refunded and question closed.

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now