Solved

TService::ParamCount is always zero?

Posted on 2013-06-16
2
484 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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
This article will show, step by step, how to integrate R code into a R Sweave document
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now