Solved

TService::ParamCount is always zero?

Posted on 2013-06-16
2
495 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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