views:

44

answers:

1

Hi all,

I am developing a Windows app with WebBrowser control (IWebBrowser2) embedded.

Things look good if I initialize COM apartment as single threaded:

CoInitialize(NULL);

However, if I change it to be multithreaded:

CoInitializeEx(NULL, COINIT_MULTITHREADED);

then it starts to fail all over the places with return value of:

An outgoing call cannot be made since the application is dispatching an input-synchronous call.

from calls to IWebBrowser2 methods.

Can someone please tell me how so solve the problem? I have to use multithreaded apartment as a requirement. Please help!

Thanks.

A: 

You can't initialize a visual activex control in a multithreaded apartment.

In theory you can create a separate thread, initialize it as STA, create your IWebBrowser2 interface there and marshal it across to the MTA thread using CoMarshalInterThreadInterfaceInStream / CoGetInterfaceAndReleaseStream. However it's disgustingly fiddly and I wouldn't recommend trying it if you want to escape with your sanity intact.

I spent several days looking at this exact problem and gave up in disgust (and used Chromium Embedded Framework instead as it happens).

Work out whether you really need to use MTA. Chances are you don't, you're just doing something wrong with iTunes.

Biblin
I, too, have given up trying to get it to work in MTA. Thanks for mentioning Chromium Embedded Framework as I had no clue we actually have an alternative How is it compared to IWebBrowser2 in you opinions? Thanks.
TopQ
So far, excellent. It depends what you're trying to use it for though. IWebBrowser2 exposes a lot of functionality of playing around behind the scenes that Chromium doesn't. Chromium also adds 23MB of dlls to your application footprint, whereas IWebBrowser2 comes with Windows. The only thing I've found lacking is the inability to manually set the zoom level.
Biblin