Click to See Complete Forum and Search --> : ‘CoInitialize has not been called’


jwspring
October 14th, 2010, 03:35 PM
DATATABLE * myObj;

void __fastcall TfmMain::btnExportClick(TObject *Sender)
{
myObj->Export(NULL);
}

void DATATABLE::Export(void* pParam) {
Variant my_excel ;
my_excel=CreateOleObject("Excel.Application");


}

Export() member function works fine at above case. but it takes long time and frozes interface.
So i tried to do this way:

void __fastcall TfmMain::btnExportClick(TObject *Sender)
{
unsigned ThreadId;
DATATABLE *thisParam= myObj;
HANDLE hndE;
hndE=(HANDLE)_beginthreadex(NULL, 0, myObj ->Export2,thisParam,0, &ThreadId);

}

unsigned __stdcall DATATABLE::Export2(void* pParam)
{
DATATABLE *thisParam= reinterpret_cast< DATATABLE *>(pParam);

thisParam->Export(NULL);

}

However, I got error at the line CreateOleObject("Excel.Application");
Project MyProj.exe raised exception class EOleSysError with message ‘CoInitialize has not been called’

Why? and how to fix it?
i use Borland compiler.

Thanks

VictorN
October 14th, 2010, 04:06 PM
Well, I never used Borland compiler... Isn't it possible to call CoInitialize in your project?

Zaccheus
November 8th, 2010, 11:58 AM
CreateOleObject is a COM function and you need to call CoInitialize before using COM functions.