Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C++/CLI C MFC ATL WTL STL
I'm automating Word and when I call a function that doesn't return for a long time (for example a call to
app.Run(_T("FilePrint"));) it tends to freeze the UI of my app until it returns from the call, so I tried to run this code from a worker thread, but then COM complains and throws an exception RPC_E_WRONG_THREAD - "0x8001010E: The application called an interface that was marshalled for a different thread."

How can I solve this problem?




btw, there's an explanation about RPC_E_WRONG_THREAD in MSDN - INFO: Explanation of RPC_E_WRONG_THREAD Error[^], but I couldn't figure out anything from it.

Posted 13-Aug-09 7:43am
sashoalm3.3K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Could you do all of the automation, including creation of the Word object, on the worker thread?

Basically you're running foul of COM single-threaded apartments and things, I think. This article[^] explains them well.

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You need to marshal calls across threads/apartments. See this[^] article for different ways to perform cross thread marshalling.
 
CoMarshalInterThreadInterfaceInStream() would probably be the easiest approach. Look it up in the MSDN documentation. It's quite easy to use.
  Permalink  
v2
  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Aug 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100