CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2006
    Posts
    40

    Unhappy ‘CoInitialize has not been called’

    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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: ‘CoInitialize has not been called’

    Well, I never used Borland compiler... Isn't it possible to call CoInitialize in your project?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: ‘CoInitialize has not been called’

    CreateOleObject is a COM function and you need to call CoInitialize before using COM functions.
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured