Article View: borland.public.cppbuilder.nativeapi
Article #10109Re: Hybrid (Service + App)
From: Frank Gruber
Date: Fri, 14 May 2004 22:16
Date: Fri, 14 May 2004 22:16
57 lines
2843 bytes
2843 bytes
> > I think it doesn't matter.
>
> Well, it does, because the coding is different depending on which approach
> you take.
Maybe I picked the wrong english term.
What I wanted to say is that I have no preference
which route to go.
> What I do in that situation is to modify the service's WinMain() function
> directly. When I want to run as a service, I let the default service code
> execute. When I want to run as a normal application, I simply bypass the
> default code and run my normal code instead. For example:
<snip>
Thank's very much for the example.
I will give it a try.
> > AFAIK TThreads create one for synchronisation
> > with the main thread.
>
> That is not true, TThread does not have a window handle at all. It merely
> posts a message to the TApplication's Handle instead, and then
Looking at the source tells me something different at least for BCB5.
IIRC this has changed for BCB6.
procedure AddThread;
function AllocateWindow: HWND;
var
TempClass: TWndClass;
ClassRegistered: Boolean;
begin
ThreadWindowClass.hInstance := HInstance;
ClassRegistered := GetClassInfo(HInstance,
ThreadWindowClass.lpszClassName,
TempClass);
if not ClassRegistered or (TempClass.lpfnWndProc <> @ThreadWndProc) then
begin
if ClassRegistered then
Windows.UnregisterClass(ThreadWindowClass.lpszClassName, HInstance);
Windows.RegisterClass(ThreadWindowClass);
end;
Result := CreateWindow(ThreadWindowClass.lpszClassName, '', 0,
0, 0, 0, 0, 0, 0, HInstance, nil);
end;
procedure TThread.Synchronize(Method: TThreadMethod);
begin
FSynchronizeException := nil;
FMethod := Method;
SendMessage(ThreadWindow, CM_EXECPROC, 0, Longint(Self));
if Assigned(FSynchronizeException) then raise FSynchronizeException;
end;
Regards,
Frank.
Technical Details
Message-ID:
<40a54492@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news-spur1.glorb.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<40a4b84e@newsgroups.borland.com> <40a50242$1@newsgroups.borland.com> <40a510da$1@newsgroups.borland.com> <40a52b88$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,f39ab9099040c7a4 X-Google-Attributes: gid10cc67,public From: "Frank Gruber" <HVFDMIPUMFPS@spammotel.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <40a4b84e@newsgroups.borland.com> <40a50242$1@newsgroups.borland.com> <40a510da$1@newsgroups.borland.com> <40a52b88$1@newsgroups.borland.com> Subject: Re: Hybrid (Service + App) Date: Sat, 15 May 2004 00:16:18 +0200 Lines: 59 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4927.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4927.1200 NNTP-Posting-Host: 217.225.6.44 Message-ID: <40a54492@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1084572818 217.225.6.44 (14 May 2004 15:13:38 -0700) Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news-spur1.glorb.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail