Thursday, December 10, 2009

Mixing ActiveX GUI C++ and .NET

I came across a problem the other day. I have:
  • An ActiveX GUI control that requires a single-threaded apartment model in C++ (MFC)
  • A C++ static library that is a bridge between C++ and a .NET class library
  • A .NET class library
The GUI control cannot be instantiated in C++. Why? The .NET thread apartment model is multi-threaded by default. How do I set the apartment model of the C++ program to be STA, when there is no .NET code directly in the C++ program? Add a linker option to the project: /CLRTHREADATTRIBUTE:STA

No comments:

Post a Comment


Ryan Kuhn