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
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