🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #1129

Open a Form in a TServiceApplication during ServiceStart

#1129
From: Marc
Date: Thu, 25 Oct 2007 16:29
111 lines
4764 bytes
Hi all

Here we go:

1) I create a simple TServiceApplication using the designer in BCB6.

2) Then I add the two events ServiceStart and ServiceStop to respond to the 
service manager.

3) I install the service, start it, stop it, no problems :-)

4) Now I create a blank form and display [MyForm->Show()] it in the 
ServiceStart event.

5) Again I install the service, start it, stop it, no problems :-)

6) Now I add a Button to my form, no events behind.

5) Again I install the service, start it, stop it => it crashes with the 
error EOSError, Code: 1400 Invalid Window Handle.

If I check with the debugger, it crashes when it tries to release my form at 
the end of the application.

The same thing happens when I try to put a TMemo component and write 
something to it.

I have written services before that open Forms in the OnExecute loop.

Is it impossible to display a form when the service starts ? All I want is a 
Splash screen with some information about the startup process of the 
service.
Actually everything works fine during the service, the info is displayed, 
etc. But when the application closes (is closed by the service manager) it 
crashes.

Any ideas ?

Rds
Marc


************
Here is my sample code...



//---------------------------------------------------------------------------
#ifndef ServiceH
#define ServiceH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <SvcMgr.hpp>
#include <vcl.h>
//---------------------------------------------------------------------------
class TTestService : public TService
{
__published:    // Von der IDE verwaltete Komponenten
     void __fastcall ServiceStart(TService *Sender, bool &Started);
     void __fastcall ServiceStop(TService *Sender, bool &Stopped);
private:        // Anwender-Deklarationen
public:         // Anwender-Deklarationen
 __fastcall TTestService(TComponent* Owner);
 TServiceController __fastcall GetServiceController(void);

 friend void __stdcall ServiceController(unsigned CtrlCode);
};
//---------------------------------------------------------------------------
extern PACKAGE TTestService *TestService;
//---------------------------------------------------------------------------
#endif


//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include "Service.h"
#include "MyForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TTestService *TestService;
//---------------------------------------------------------------------------
__fastcall TTestService::TTestService(TComponent* Owner)
 : TService(Owner)
{
}
//---------------------------------------------------------------------------
TServiceController __fastcall TTestService::GetServiceController(void)
{
 return (TServiceController) ServiceController;
}
//---------------------------------------------------------------------------
void __stdcall ServiceController(unsigned CtrlCode)
{
 TestService->Controller(CtrlCode);
}
//---------------------------------------------------------------------------
void __fastcall TTestService::ServiceStart(TService *Sender, bool &Started)
{
     TheForm->Show();
     Started=true;
}
//---------------------------------------------------------------------------
void __fastcall TTestService::ServiceStop(TService *Sender, bool &Stopped)
{
     Stopped=true;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <4720c4bf@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8191050f071867e7,start
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Marc" <info@mawnet.com>
From: "Marc" <info@mawnet.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Open a Form in a TServiceApplication during ServiceStart 
Date: Thu, 25 Oct 2007 18:29:50 +0200
Lines: 119
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; Original
NNTP-Posting-Host: 83.76.62.142
Message-ID: <4720c4bf@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1193329855 83.76.62.142 (25 Oct 2007 09:30:55 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!194.134.4.77.MISMATCH!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail