To set the thread as STA, initialize COM by calling either CoInitialize(nullptr) or CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED)
But remember at least two things: 1) only the first call to CoInitialize[Ex]() matters — all subsequent ones will fail unless they're told to set the same apartment type as the one currently used by the calling thread; 2) every call to CoInitialize[Ex]() that returns S_OK or S_FALSE must be paired with a call to CoUninitialize(). https://msdn.microsoft.com/en-us/library/windows/desktop/ms680112(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms678543(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms695279(v=vs.85).aspx On 04/01/2015 02:11 PM, prasad v n wrote: > hi, > I wanted to host a WPF user control in my QT application. > So I created a CLI dll that returns the HWND of the user control. It > creates an HwndSource for the WPF control and returns the handle of that > HWND source. > > I added reference to this CLI dll from my QT application and tried to > get the HWND. > > But I am getting an error as given below. > > > Unhandled Exception: System.InvalidOperationException: The calling > thread must be STA, because many UI components require this. > > at System.Windows.Input.InputManager..ctor() > > at System.Windows.Input.InputManager.GetCurrentInputManagerImpl() > > at System.Windows.Interop.HwndMouseInputProvider..ctor(HwndSource source) > > at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters > parameters) > > at System.Windows.Interop.HwndSource..ctor(Int32 classStyle, Int32 > style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, > String name, IntPtr parent) > > at GetWPFHwnd(HWND__* parent, Int32 x, Int32 y, Int32 width, Int32 > height) in > c:\users\ing08746\desktop\qt\staticclilib\staticclilib\staticclilib.cpp:line > 42 > > at WinMainCRTStartup() > > > I think we need to set the ApartmentState of QT application as STA. > > How can set the apartment state to STA for QT application? > > > with regards, > > prasad
signature.asc
Description: OpenPGP digital signature
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest