Click here to Skip to main content
13,050,429 members (134,709 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 6:43am
Rate this: bad
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.

Rate this: bad
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.
  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 4 Aug 2010
Copyright © CodeProject, 1999-2017
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