Solved

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

Posted on 2001-08-13
4
280 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

627 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