stammen / dnssd-uwp

This project is no longer being supported. It is sample code only.
MIT License
6 stars 5 forks source link

Best strategies for working with other Windows COM modules? (CoInitialize APARTMENTTHREADED, etc) #9

Open ewmailing opened 6 years ago

ewmailing commented 6 years ago

Can you give any tips on how to best work/cooperate with other Windows modules that also use COM?

While, trying to integrate the techniques of this module, I discovered the initialization of Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); conflicts with other modules that call CoInitialize with different options.

Most notably, I am using a GUI library that uses CoInitializeEx(NULL, COINIT_APARTMENTTHREADED), and I think things like the Windows File Dialog or any OLE components will not work if put into MULTITHREADED mode.

For curiosity, I tried changing this module to Windows::Foundation::Initialize(RO_INIT_SINGLETHREADED) (there don't appear to be any APARTMENT options), but in my actual program, exceptions were thrown at things like CreateWatcher().

Right now my thinking is to try putting this (and other UWP modules) on a background thread first and then calling Windows::Foundation::Initialize(RO_INIT_MULTITHREADED).

I'm hoping you can give a statement if that will actually work (and if there are any other gotchas to watch out for), or if there is a simpler/better way to do this.

Thanks!

stammen commented 6 years ago

I would try putting the winrt code on another thread first.