It is illegal to call out while inside message filter
-
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
-
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
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
-
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
Thanks alot for your response, I will try your idea, for now I put some workaround in my code. Thanks again for the info.