1 Attachment(s)
CoInitialize has not been called
Hi all,
I got problem with my project
First-chance exception at 0x75669617 in BasicReport.exe: 0x800401F0: CoInitialize has not been called.
Warning: constructing COleException, scode = CO_E_NOTINITIALIZED ($800401F0).
First-chance exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x034bed94..
Unhandled exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x034bed94..
Can any1 explain to me what the problem is ? and how can i fix it
Thanks
Re: CoInitialize has not been called
You need to call CoInitialize when your program starts and CoUnitialize when it terminates.
The best place to do this is in InitInstance and ExitInstance.
Just make CoInistialize the first call to InitInstance.
Code:
BOOL CBasicReportApp::InitInstance()
{
CoInitialize( NULL );
if(!AfxOleInit())
// etc.
}
For the CoUnitialize call, you need to override ExitInstance.
To do this, Open the Class view, select the CBasicReportApp class.
Right click and choose "Properties".
At the top of the properties window you'll see a series of icons.
One is a little lightning bolt, one looks like a small window, and one looks like a little green box. If you hover over these, you get a tooltip for each one. In order this will be "Events", "Messages", and "Overrides". Click on the Green Icon ("Overrides"),
Scroll down until you find ExitInstance and create an override for this method.
Well, that's how you normally do it. Looks like using CWinAppEx breaks that.
So enter it manually (and put a declaration in the header file too).
Code:
INT CBasicReportApp::ExitInstance()
{
CoUninitialize( );
return CWinAppEx::ExitInstance( );
}
Re: CoInitialize has not been called
i have followed ur help and add both CoInitialize, CoUnInitialize function into CBasicReportApp::InitInstance() and CBasicReportApp::ExitInstance() but till got the same problem
First-chance exception at 0x75669617 in BasicReport.exe: 0x800401F0: CoInitialize has not been called.
Warning: constructing COleException, scode = CO_E_NOTINITIALIZED ($800401F0).
First-chance exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x0259f13c..
Unhandled exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x0259f13c..
Re: CoInitialize has not been called
Are you using a worker thread?
Re: CoInitialize has not been called
Yeah, I used Worker thread in my project.
I have att my project with this post
You can see my code there and please tell me what is the problems with my code.
Re: CoInitialize has not been called
Quote:
Originally Posted by
pcuong1983
Yeah, I used Worker thread in my project.
I have att my project with this post
You can see my code there and please tell me what is the problems with my code.
You'll need to put the CoInitialize/CoUnitialize pair into each thread where COM objects are called.
Re: CoInitialize has not been called
Can you give me more information about CoInitialize/CoUnInitialize in Thread ?
i tried to add CoInitialize at the begining of my thread function. It look like
Code:
UINT ThreadFunc(LPVOID lpParam)
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
......................
CoUninitialize();
}
and now im facing new problem:
First-chance exception at 0x75669617 in BasicReport.exe: 0x8001010E: The application called an interface that was marshalled for a different thread.
Warning: constructing COleException, scode = RPC_E_WRONG_THREAD ($8001010E).
First-chance exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x038ef28c..
Unhandled exception at 0x75669617 in BasicReport.exe: Microsoft C++ exception: COleException at memory location 0x038ef28c.
Im new in COM and Thread programming.
Re: CoInitialize has not been called
You can't directly share a STA COM object pointer across threads.
You need to marshal it. Check out the CoMarshalInterThreadInterfaceInStream approach listed in this article.
http://www.codeproject.com/KB/COM/CCOMThread2.aspx
Re: CoInitialize has not been called