Announcement

Collapse
No announcement yet.

Exception "CoInitialize not called" in Delphi

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Exception "CoInitialize not called" in Delphi

    Hello,

    I just developed a soft using the desketop API in Delphi.

    The class "THooks" imported from the winsig.tlb works, I could easily retrieve data in real time during my first tests using the THooks.requestSymbol method and the OnQuoteChanged event... but something quite frustating happened.

    While the THooks.RequestSymbol method works well when it is called from a "button event", any call of the same THooks object from any other part of the soft is raising the exception "CoInitialize was not called".

    What is this CoInitialize ? I didn't find anything on this in the doc.

    Could you help me ?

  • #2
    CoInitialize is a Window's API call. I'm not a Delphi guy so I can't really help much, but if you call that function at the start of your app you might be good to go. You should also technically call CoUninitialize when you are done (one to one).

    Cheers... George

    Comment


    • #3
      Thank you for your quick answer !

      I am not very good in windows API call from Delphi, but I will search in this direction.

      cheers

      Comment


      • #4
        It is ok, I found a trick on google and it works. I report this below, if it can help somebody else :

        How do I eliminate the "CoInitialize has not been called" error?


        COM libraries can be picky about when CoInitialize is called. In order to guarantee it is initialized at the proper time, use the following unit (save it as ComInit.pas):


        [Delphi]

        unit ComInit;

        interface

        uses
        ActiveX;

        implementation

        initialization
        CoInitializeEx(nil,COINIT_MULTITHREADED);
        finalization
        CoUninitialize;
        end.


        Make sure this is the first unit listed in the "uses" statement of your .DPR file. For example:


        [Delphi]

        uses
        ComInit in 'ComInit.pas',
        WebBroker,
        ApacheApp,
        dMain in 'dMain.pas' {dmMain: TcxWebHomeDataModule},
        wMain in 'wMain.pas' {wpmMain: TcxWebPageModule} {*.html;}

        Comment

        Working...
        X