Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

708 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

15 Experts available now in Live!

Get 1:1 Help Now