"Michael Kennedy [UB]" <(E-Mail Removed)> wrote in
message news:e%23qg%23%(E-Mail Removed)...
> As far as I can tell, the STAThread attribute doesn't actually initialize
> the COM system in the unmanaged C++ and only applies to the managed C++
and
> C# right?
No. The apartment is initialized after the first call to unmanaged code
occurs. Before that you can set it through
Thread.CurrentThread.ApartmentState. After the first call you can't touch
it. And if you don't set it, it's either set to the default or it picks up
the attribute, if present.
> How are you handling this? Is there an easier way to do this? Maybe some
> magical attribute that I'm not aware of?
Like Mattias said, it's a per-thread issue. If all of your code is running
in the same thread (and/or the same process) then you need to keep in mind
that the CLR already called CoInitialize[Ex] for you. But again, this
happens only until the first call to unmanaged code occurs.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/