πŸš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.com.activex.using
Article #178

Re: What CoInitialization?

#178
From: Z
Date: Wed, 30 Jul 2008 15:07
39 lines
2316 bytes
"Yogi Yang" <yogiyang007@gmail.com> a οΏ½crit dans le message de news: 
488e98b2@newsgroups.borland.com...
> Marc Rohloff [TeamB] wrote:

>> Initialization of the COM (ActiveX/DCOM) framework. You need to make
>> sure that CoInitialize* is called on every thread that uses COM.
> Now if I start a new blank project and place this ActiveX on its form and 
> run it (by pressing F9) it runs and the ActiveX behaves as documented.
>
> But when I use this ActiveX in an existing project I keep getting this 
> message.
>
> What must be the problem?
>
> Can you give me code snipper as to how to call CoInitialize and 
> CoUnInitialize?

In the new blank project, the main process is using (creating, calling, etc) 
the COM object. So it works.
In the existing project, a thread is doing it.

So in the thread's Execute procedure, you must enclose your existing code 
within a CoInitializeEx call at the beginning, and then a CoUninitialize at 
the end, with a "try-finally" as shown:

TYogisThread.Execute()
begin
 CoInitializeEx(nil,COINIT_APARTMENTTHREADED);
 try
   //the rest of your existing code
   finally
    CoUninitialize;
   end;

For more about the COINIT_APARTMENTTHREADED parameter, and other choices, 
look up the CoInitialize function in the Win32 Help.

Z 
Technical Details
Message-ID: <489083aa$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <488dc210@newsgroups.borland.com> <1xk4rbhnvqaeu.dlg@dlg.marcrohloff.com> <488e98b2@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 123df9,a5cfc09a3dc6f939
X-Google-Attributes: gid123df9,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
Reply-To: "Z" <z@nospam.com>
From: "Z" <z@nospam.com>
Newsgroups: borland.public.delphi.com.activex.using
References: <488dc210@newsgroups.borland.com> <1xk4rbhnvqaeu.dlg@dlg.marcrohloff.com> <488e98b2@newsgroups.borland.com>
Subject: Re: What CoInitialization?
Date: Wed, 30 Jul 2008 17:07:21 +0200
Lines: 41
Organization: Z
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5512
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 82.225.230.156
Message-ID: <489083aa$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1217430442 82.225.230.156 (30 Jul 2008 08:07:22 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail