Solved

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

Posted on 2001-08-13
4
274 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

813 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

13 Experts available now in Live!

Get 1:1 Help Now