Solved

TService::ParamCount is always zero?

Posted on 2013-06-16
2
498 Views
Last Modified: 2013-06-17
I have written a service application in Borland C++ builder 5 and wish to pass a parameter on the command line when the service application is installed (not when it is started). I have tested this by entering the following onstallation command :
 myservice /install  param1

The following code is my constructor for the service application and always indicates that the ParamCount has a value of zero, even when passing a parameter after the /install parameter when installing the service.

Is there any way to pass a parameter on the command line when installing a service application ?

__fastcall T_2WSOPDSService1::T_2WSOPDSService1(TComponent* Owner)
      : TService(Owner)
{
    int pcount;
    AnsiString s;

    pcount = ParamCount;
    s.sprintf("ParamCount on installation was %d",pcount);
    LogMessage(s,EVENTLOG_INFORMATION_TYPE,0,0);


    dbsconnected = false;
    update = NULL;
    return;
}
0
Comment
Question by:alcindor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 39251995
Just a small note. The install parameter will be processed by the application when it runs in "Application" mode, not as a service mode. It will be handled by your "main" entry point.
You would probably need to provide us with more code in order to help. Please upload here the main program entry point where you handle the "/install" command line parameter
0
 
LVL 2

Author Comment

by:alcindor
ID: 39253037
I don't handle the "/install" command line parameter myself, this is handled by a built-in handler provided by the Borland compiler when making a service application.
However, I managed to extract the command line parameters from the command line by using the code in WinMain as follows. Thanks for your help.

AnsiString s_main; // added this variable to hold the command line
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR s, int)
{

try
{
                   s_main = s; // s_main is referenced in the service application constuctor
      Application->Initialize();
      Application->CreateForm(__classid(T_2WSOPDSService1), &_2WSOPDSService1);
                  Application->Run();
}
catch (Exception &exception)
{
      Sysutils::ShowException(&exception, Sysutils::ExceptAddr());
}
      return 0;
}
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question