BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using COM from a service application

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Ian Boyd
Guest





PostPosted: Mon Sep 04, 2006 11:09 pm    Post subject: Using COM from a service application Reply with quote



i have having horrible, horrible, horrible, problems using COM from a Delphi
service application. Things that just make no sense and just don't work.
Rather than getting involved in a week long discussion about what the
symptoms i'm experiencing, i'll tell you that i've guessed what the problem
is; and want an answer to this question:

When should i call CoInitialize/Couninitialize from my service application?


Delphi services create a thread to do *something*. My service application
has nothing in it's OnExecute event.
During OnCreate i construct an object that loads COM objects from dlls.
During OnDestroy i nil off those COM object references and destroy my main
object.
During OnPause i call a method of my object that "pauses" it.
During OnResume i call a method of my object that "resumes" it.


Should i call CoInitialize during OnCreate? Isn't OnCreate not yet in a
thread? Is OnCreate called from the context of a thread? If the service
application is a out of process host for COM objects, will those object
methods be called from the service application's main thread or from the
thread Delphi creates?

Should i not be using COM objects during OnCreate if they will be access
later via the delph thread?

Should i be doing:

procedure Service.OnExecute()
var
o: TMyEverythingObject
begin
CoInitializeEx(nil, 0);
try
o := TMyEverythingObject.Create;
try
while not Terminated do
begin
end;
finally
o.Free;
end;
finally
Counitialize;
end;
end;

But then am i allowed to talk to my object during OnPause/OnResume/OnStop?
Are those also executed in the context of the thread? Who calls OnPause? How
is it called? What does it do to the main application thread? What does it
do to the "service" thread? What does it do to OnExecute?

If the service is paused, is the thread paused? Is OnPause just before the
thread is paused?

etc, etc, etc.

What's maddening is that COM is not throwing any exceptions saying i haven't
entered an apartment yet with CoInitialize.


If you're not an up-tight priss, and you want to read what my latest problem
in the long chain of this one "quick change" is, do a google search for:
"Ian Boyd Can a marshalled interface be marshalled?"
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.