🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How can a Applicantion work as a Service?

#7394
From: Eelke
Date: Thu, 03 Feb 2005 08:41
90 lines
3913 bytes
Remy Lebeau (TeamB) wrote:
> "Emmanuel" <emmanuel@erphk.com> wrote in message
> news:4201c82d$1@newsgroups.borland.com...
> 
> 
>>but I find that Borland SocketServer which provided by
>>Borland C++builder can work as Service and work as
>>a single program
> 
> 
> TServerSocket is an individual component, not a project of its own.  Writing
> a project for a standalone application and writing a project for a service
> use very different architectures.  For what you ask, you would have to write
> project-neutral code and then include it into both projects.  For that, you
> can use a TDataModule, for instance.  Put all of your shared code into a
> TDataModule that has no concept of what kind of project it is being used
> with, and then you can include the DataModule into both an application
> project and a service project.
You can modify a project to support both running as an application or as 
a service. You need to take some precautions to prevend builder from 
screwing up the changes you have to make to the WinMain function. I have 
done it as follows.

project.cpp
===========

USERES("hybrid.res");
USEFORM("hybridserviceunit.cpp", HybridService); /* TService: DesignClass */
USEFORM("HybridFormUnit.cpp", HybridForm);
//---------------------------------------------------------------------------
// This WinMain is to keep builder happy.
#if 0
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	try
	{
		Application->Initialize();
		Application->Title = "hybrid";
		Application->CreateForm(__classid(THybridService), &HybridService);
		Application->CreateForm(__classid(THybridForm), &HybridForm);
		Application->Run();
	}
	catch (Exception &exception)
	{
		Sysutils::ShowException(&exception, Sysutils::ExceptAddr());
	}
	return 0;
}
#else
// This file contains the real WinMain
#include "winmain.cpp"
#endif


winmain.cpp
===========

#include <SvcMgr.hpp>

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR cmd, int)
{
	try
	{
		AnsiString cmdline = AnsiString(cmd).Trim().LowerCase();
		bool service = true;
		if (cmdline == "/app") service = false;
		// >>>>>>>>>>>>>
		if (service) {
			Svcmgr::Application->Initialize();
			Svcmgr::Application->Title = "hybrid";
			Svcmgr::Application->CreateForm(__classid(THybridService), 
&HybridService);
			Svcmgr::Application->Run();
		} else {
			Forms::Application->Initialize();
			Forms::Application->Title = "hybrid";
			Forms::Application->CreateForm(__classid(THybridForm), &HybridForm);
			Forms::Application->Run();
		}
		// >>>>>>>>>>>>>
	}
	catch (Exception &exception)
	{
		Sysutils::ShowException(&exception, Sysutils::ExceptAddr());
	}
	return 0;
}


Eelke
Technical Details
Message-ID: <4201e3b6$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <4200af09$1@newsgroups.borland.com> <4200bfe5@newsgroups.borland.com> <4201c82d$1@newsgroups.borland.com> <4201d87e@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,591b0fbb1373b772
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Thu, 03 Feb 2005 09:41:46 +0100
From: Eelke <e.klein@mplussoftware.nl>
User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: How can a Applicantion work as a Service?
References: <4200af09$1@newsgroups.borland.com> <4200bfe5@newsgroups.borland.com> <4201c82d$1@newsgroups.borland.com> <4201d87e@newsgroups.borland.com>
In-Reply-To: <4201d87e@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.58.1.162
Message-ID: <4201e3b6$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1107420086 81.58.1.162 (3 Feb 2005 00:41:26 -0800)
Lines: 90
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail