Hello Everyone,
I write extensions to a C++ program. I write standard C/C++ dlls and I use IJW to call C# dlls. This has always worked perfectly until I wrote and called a C# dll that in turn called an OpenFileDialog and a SaveFileDialog. Whenever either was called with ShowDialog, the app would freeze.
So in making a "Minimum Working Example" I got an: An unhandled exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Additional information: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.
So, I tried to add the STAThread attribute infront of the main in my "Minimum Working Example" and I got this error.
error C2337: 'STAThread' : attribute not found
So, two questions:
- How d0 I get the "Minimum Working Example" working and
- How do I get the real app working?
(is it even possible to add the STAThread attribute in a #pragma unmanaged block?)
#pragma unmanaged
BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
...
}
Thanks for your help.