Another one from someone sending a comment:
I came across your blog and was wondering if what to do when encountering above error message in an application program.
The error occurs once in a while when printing out from a Windows application.
Is there some setting missing in computer administration or in the Registry or can it only be solved in the code?
Appreciate your help!
Yech. This one's ugly. It's time for Raymond's Psychic Powers(tm) of detection.
If you take the error message text and look inside winerror.h, you'll see that the error message mentioned is exactly the text for the RPC_E_WRONG_THREAD error.
If you then do an MSDN search for RPC_E_WRONG_THREAD, the first hit is: "INFO: Explanation of RPC_E_WRONG_THREAD Error". Essentially, the error's a side effect of messing up threading models. I wrote about them about 18 months ago in "What are these threading models, and why do I care?".
So, knowing that the app's dutifully reporting RPC_E_WRONG_THREAD to the user, what had to have happened to cause this error?
It means that the application did a CoCreateInstance of an Single Threaded Apartment COM object in one thread, but used it in another thread.
Given the comment that it only happens once in a while, we can further deduce that the application called CoCreateInstance from a thread in a pool of worker threads, and attempted to use it in a function queued to that pool of threads (otherwise it would fail all the time and the author of the app would have found the problem). Given that it only happens when printing (an operation that's usually handled in a background thread), this makes sense.
Unfortunately for the person who asked the question, they don't really have any choice but to contact the vendor that created the app and hope that they have an update that fixes the problem, because there's no workaround you can do outside the app 🙁