Solved

TService::ParamCount is always zero?

Posted on 2013-06-16
2
492 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
2 Comments
 
LVL 24

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video teaches viewers about errors in exception handling.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

856 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