Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. It is illegal to call out while inside message filter

It is illegal to call out while inside message filter

Scheduled Pinned Locked Moved C / C++ / MFC
csharpvisual-studiohelpquestion
3 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 534357
    wrote on last edited by
    #1

    I am running my application in Visual Studio .NET & am getting the following error "It is illegal to call out while inside message filter" What can be causing this error to occur? Thanks

    A 1 Reply Last reply
    0
    • M Member 534357

      I am running my application in Visual Studio .NET & am getting the following error "It is illegal to call out while inside message filter" What can be causing this error to occur? Thanks

      A Offline
      A Offline
      Andrew Quinn AUS
      wrote on last edited by
      #2

      Hi, From my experience - this is caused by COM re-entrancy. For example, COM server has called back into your app (via eventing) and you are then calling back into the COM server. COM's telling you its blocking the call because it hasn't finished processing the previous method call. I did the following which still blocks but without the annoying message

      class CBusyState
      {
      public:

      // Constructor - by default the busy state is entered
      CBusyState(BOOL bEnterBusyState = TRUE, 
      	SERVERCALL scBusyReply = SERVERCALL\_RETRYLATER)
      	: m\_bBusy(FALSE)
      {
      	// get the MFC message filter implementation. This will return NULL if called from a DLL.
      	m\_pMessageFilter = AfxOleGetMessageFilter();
      	if (bEnterBusyState)
      	   Begin(scBusyReply); // enter the busy state
      }
      
      // Destructor - ends the busy state (if previously entered)
      ~COasisBusyState()
      {	
      	End(); // end the busy state
      };
      
      // Begins the busy state. By default, any incoming COM calls will be
      // rejected, but retried later
      BOOL Begin(SERVERCALL scBusyReply = SERVERCALL\_RETRYLATER)
      {	// check that we have a message filter, and that we're not already
      	// busy.
      	if (m\_pMessageFilter && !m\_bBusy)
      	{	// set the reply code for IMessageFilter::HandlingIncomingCall()
      		m\_pMessageFilter->SetBusyReply(scBusyReply);
      		// enter the busy state
      		m\_pMessageFilter->BeginBusyState();
      		m\_bBusy = TRUE;
      	}
      	return m\_bBusy;
      }
      
      // Ends the busy state, if previously entered
      void End()
      {	// check that we have a message filter, and that we're busy
      	if (m\_pMessageFilter && m\_bBusy)
      	{	// end the busy state
      		m\_pMessageFilter->EndBusyState();
      		m\_bBusy = FALSE;
      	}
      }
      

      private:
      BOOL m_bBusy;
      COleMessageFilter* m_pMessageFilter;
      };

      Then whenever we call the COM server, I'd put the object on the stack, e.g. function xyzxyzxyz() { CBusyState blocker(TRUE); MyCOMServer->method(xyz) } Hope this helps, Andy

      M 1 Reply Last reply
      0
      • A Andrew Quinn AUS

        Hi, From my experience - this is caused by COM re-entrancy. For example, COM server has called back into your app (via eventing) and you are then calling back into the COM server. COM's telling you its blocking the call because it hasn't finished processing the previous method call. I did the following which still blocks but without the annoying message

        class CBusyState
        {
        public:

        // Constructor - by default the busy state is entered
        CBusyState(BOOL bEnterBusyState = TRUE, 
        	SERVERCALL scBusyReply = SERVERCALL\_RETRYLATER)
        	: m\_bBusy(FALSE)
        {
        	// get the MFC message filter implementation. This will return NULL if called from a DLL.
        	m\_pMessageFilter = AfxOleGetMessageFilter();
        	if (bEnterBusyState)
        	   Begin(scBusyReply); // enter the busy state
        }
        
        // Destructor - ends the busy state (if previously entered)
        ~COasisBusyState()
        {	
        	End(); // end the busy state
        };
        
        // Begins the busy state. By default, any incoming COM calls will be
        // rejected, but retried later
        BOOL Begin(SERVERCALL scBusyReply = SERVERCALL\_RETRYLATER)
        {	// check that we have a message filter, and that we're not already
        	// busy.
        	if (m\_pMessageFilter && !m\_bBusy)
        	{	// set the reply code for IMessageFilter::HandlingIncomingCall()
        		m\_pMessageFilter->SetBusyReply(scBusyReply);
        		// enter the busy state
        		m\_pMessageFilter->BeginBusyState();
        		m\_bBusy = TRUE;
        	}
        	return m\_bBusy;
        }
        
        // Ends the busy state, if previously entered
        void End()
        {	// check that we have a message filter, and that we're busy
        	if (m\_pMessageFilter && m\_bBusy)
        	{	// end the busy state
        		m\_pMessageFilter->EndBusyState();
        		m\_bBusy = FALSE;
        	}
        }
        

        private:
        BOOL m_bBusy;
        COleMessageFilter* m_pMessageFilter;
        };

        Then whenever we call the COM server, I'd put the object on the stack, e.g. function xyzxyzxyz() { CBusyState blocker(TRUE); MyCOMServer->method(xyz) } Hope this helps, Andy

        M Offline
        M Offline
        Member 534357
        wrote on last edited by
        #3

        Thanks alot for your response, I will try your idea, for now I put some workaround in my code. Thanks again for the info.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups