BUG: "HRESULT - 0x80010106" error occurs when you run a managed Visual C++ application in Visual Studio .NET (824480)
The information in this article applies to:
- Microsoft Visual C++ .NET (2003)
SYMPTOMSWhen you try to run a Managed C++ application that has
Component Object Model (COM) initialization on the main thread, you may receive
the following error message at run time: HRESULT -
0x80010106 - Cannot change thread mode after it is set.
CAUSESetting the apartment state on the main thread is not
reliable.RESOLUTIONThe main function is not the real managed entry point. The
real managed entry point is the C Run-Time Libraries (CRT) entry point. To
resolve this problem, write the managed entry point and manually
initialize the CRT as follows: #define _WIN32_WINNT 0x501
#include <objbase.h>
#include <stdio.h>
#using <mscorlib.dll>
using namespace System;
extern "C" void mainCRTStartup();
[System::STAThread]
int mymain() //the new entry point
{
//Initialize COM
HRESULT hr = CoInitialize(0);
//Initialize the CRT
mainCRTStartup();
//uninit
CoUninitialize();
return 0;
}
int main()
{
/*
Do the application work
that you would do in your main thread
*/
} Explicitly specify the entry point to the mymain function. To do this, follow these steps: - Click Project, and then click Properties.
- In the Property Pages dialog box, expand Linker under Configuration Properties, and then click to select Advanced.
- In the Entry Point text box, type mymain, and then click OK.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are
listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 1/5/2006 |
---|
Keywords: | kberrmsg kbThread kbCodeGen kbCRT kbAppWizard kbbug KB824480 kbAudDeveloper |
---|
|