COM outbound call results in “An outgoing call cannot be made since the application is dispatching an input-synchronous call.”

前端 未结 3 503
一个人的身影
一个人的身影 2021-02-03 11:26

I have a COM server (C++/STA (MFC based app)) and a COM client (C#/MTA). The COM server must live in an STA, since it\'s an MFC app (I have no choice in this matter). The client

3条回答
  •  暖寄归人
    2021-02-03 11:49

    RPC_E_CANTCALLOUT_ININPUTSYNCCALL means that you attempted to make a marshalled COM call from within the handler for a windows message sent via SendMessage. This is to help avoid certain deadlock situations. You have a number of options, which boil down to "avoid COM calls in a SendMessage handler":

    • You could use PostMessage to queue up a message to yourself, and in that posted message handler, invoke the COM callback.
    • You could use asynchronous DCOM, and avoid blocking on the result of the call from within the message handler.
    • You could marshal the callback interface, then invoke it from a thread pool work item. Since this is independent from the main application's message loop, it won't be in a SendMessage call, and it could even be in a MTA.
    • You could forgo the MFC COM support, and invoke CoRegisterClassObject directly from another thread. This means any calls into your server COM object will be invoked from the COM thread pool (or, if you use a STA thread, from that thread), not from the MFC UI thread, so you'll need to use Windows messages to communicate across threads; but if you need to make synchronous calls back to the client it may be the best approach.

提交回复
热议问题