WinMain argc and argv - can't get back argv

  • Thread starter Thread starter cb12__
  • Start date Start date
C

cb12__

Guest
In my program I am running a Windows service using:

extern




"C"intWINAPI_tWinMain(HINSTANCE, HINSTANCE, LPTSTR, intnShowCmd) //hInstance, hPrevInstance, lpCmdLine



{.....

at the start of my code and have decided to try to use __argc and __argv rather than


GetCommandLine. I decided that my code might read better if I used __argc and __argv. However, although __argc comes out fine as 4, __argv seems to give me problems. I try to do the following:


string configurationInputFile =__argv[1];




and then write configurationInputFile out to a log file and the program crashes. Any ideas would be welcome. Snippet of code is:


extern






"C"intWINAPI_tWinMain(HINSTANCE, HINSTANCE, LPTSTR, intnShowCmd) //hInstance, hPrevInstance, lpCmdLine


{




LOG_INFO("<=============================== START OF PROGRAM ===============================>");




LOG_INFO("ServiceControllerService: Main: Entry, Log level: LOG_INFO");




try


{




//Read in command line arguments



int argc = 0;



char** argv = NULL;


argc = __argc;




argv = __argv;






ostringstreamss, ss2;


ss <<"ServiceControllerService: Main: argc = "<<argc <<", Log level: LOG_INFO";


LOG_INFO(ss.str());

LOG_INFO("Before config file read name");


string configurationInputFile =argv[1];


stringstrMessage = "ServiceControllerService: Main: config file="+configurationInputFile +", Log level: LOG_INFO";


LOG_INFO(strMessage);




Doesn't write out last LOG_INFO message and program stops.

Continue reading...
 
Back
Top