Article View: borland.public.delphi.com.activex.using
Article #176Re: What CoInitialization?
From: Remy Lebeau (TeamB)
Date: Tue, 29 Jul 2008 16:22
Date: Tue, 29 Jul 2008 16:22
49 lines
2608 bytes
2608 bytes
"Yogi Yang" <yogiyang007@gmail.com> wrote in message
news:488e98b2@newsgroups.borland.com...
> Thanks for the info but this sounds absurd.
A thread has to be assigned to a COM apartment (whether that be a
single-threaded apartment or a multi-threaded apartment) before it can
access COM objects. The apartment dicates how the thread can access the COM
objects (directly or via proxies). The OS can't detemine ahead of time how
you want to manage your threads. So you have to explitically
initialize/uninitialize your threads in your code instead. Why is that
absurd?
> I have imported an ActiveX in the Delphi IDE.
>
> 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.
Because you are using it in the main thread, and the main thread has already
been initialized for you at startup.
> But when I use this ActiveX in an existing project I keep
> getting this message.
Because your existing project is not doing the same things to initialize the
main thread at startup.
> Can you give me code snipper as to how to call CoInitialize and
> CoUnInitialize?
Did you look at the documentation for them yet? They are just function
calls, and not very difficult ones at that, ie:
unit Unit1;
interface
...
implementation
...
initialization
CoInitialize(nil);
finalization
CoUninitialize();
Gambit
Technical Details
Message-ID:
<488f4414$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<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-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.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: Tue, 29 Jul 2008 09:22:13 -0700 Lines: 51 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 207.178.157.90 Message-ID: <488f4414$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1217348628 207.178.157.90 (29 Jul 2008 09:23:48 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news2.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail X-Original-Bytes: 2438