Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 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.

710 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