Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » access to raw command line parameters
access to raw command line parameters [message #3869] Tue, 04 July 2006 18:21 Go to next message
dr_jumba is currently offline  dr_jumba
Messages: 24
Registered: February 2006
Location: Ukraine
Promising Member
Hi,

Is there exist an easy way to access to command line parameters passed to GUI_APP?

What I need is to pass these parameters to 3rd party library init function.
E.g.
SuperLibInit(argc, argv);

Thanks.
Re: access to raw command line parameters [message #3874 is a reply to message #3869] Wed, 05 July 2006 09:03 Go to previous messageGo to next message
fallingdutch is currently offline  fallingdutch
Messages: 258
Registered: July 2006
Experienced Member
dr_jumba wrote on Tue, 04 July 2006 18:21

Is there exist an easy way to access to command line parameters passed to GUI_APP?


yes, as far as i can see you get them by calling "CommandLine()" it returns a Vector of Strings (Vector<String> &)

dr_jumba wrote on Tue, 04 July 2006 18:21

What I need is to pass these parameters to 3rd party library init function.
E.g.
SuperLibInit(argc, argv);

I am not sure, but take a look at dli (Core/dli.h, Core/Dli.cpp) in the "Win32 support" section of Core.
As far as i know you can even load .so at *nix OS, using these files, but not sure.

If you have a solution for this please poste it, working on it, too

Bas
Re: access to raw command line parameters [message #3875 is a reply to message #3869] Wed, 05 July 2006 09:04 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

dr_jumba wrote on Tue, 04 July 2006 12:21

Hi,

Is there exist an easy way to access to command line parameters passed to GUI_APP?

What I need is to pass these parameters to 3rd party library init function.
E.g.
SuperLibInit(argc, argv);

Thanks.


It seems there is no way to access that variables directly, but you can get command line parameters into string vector using CommnadLine() function:

const Vector<String> &cmd = CommandLine();
int cnt = cmd.GetCount();
const char **argv = new const char*[cnt];
	
for(int i = 0; i < cnt; i++)
    argv[i] = cmd[i];

SuperLibInit(cnt, argv); 
Re: access to raw command line parameters [message #3911 is a reply to message #3875] Sat, 08 July 2006 22:08 Go to previous messageGo to next message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
unodgs wrote on Wed, 05 July 2006 09:04

dr_jumba wrote on Tue, 04 July 2006 12:21

Hi,

Is there exist an easy way to access to command line parameters passed to GUI_APP?

What I need is to pass these parameters to 3rd party library init function.
E.g.
SuperLibInit(argc, argv);

Thanks.


It seems there is no way to access that variables directly, but you can get command line parameters into string vector using CommnadLine() function:

const Vector<String> &cmd = CommandLine();
int cnt = cmd.GetCount();
const char **argv = new const char*[cnt];
	
for(int i = 0; i < cnt; i++)
    argv[i] = cmd[i];

SuperLibInit(cnt, argv); 



If the above code doesn't help (it doesn't comply with the C++ standard Rolling Eyes ) you might want to have a look at my recent posting "ArgcArgv – use argc and argv under Ultimate++!" (Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples!)

Werner
Re: access to raw command line parameters [message #3912 is a reply to message #3911] Sat, 08 July 2006 22:32 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Werner wrote on Sat, 08 July 2006 16:08


If the above code doesn't help (it doesn't comply with the C++ standard Rolling Eyes )



May I know what's wrong with it??
Re: access to raw command line parameters [message #3913 is a reply to message #3912] Sat, 08 July 2006 23:53 Go to previous message
Werner is currently offline  Werner
Messages: 234
Registered: May 2006
Location: Cologne / Germany
Experienced Member
unodgs wrote on Sat, 08 July 2006 22:32

Werner wrote on Sat, 08 July 2006 16:08


If the above code doesn't help (it doesn't comply with the C++ standard Rolling Eyes )



May I know what's wrong with it??



Sure! You have every right to know! Smile

Here we go:

1.
dr_jumba wrote that he needs to pass the command line arguments to a 3rd party library. It seems much more likely that the "3rd party" expects these arguments to be passed in the standard C++ way than in the Ultimate++ way. Crying or Very Sad

2.
So lets compare the results of your code with what the C++ standard expects:

a)
The first argument (argv[0]) expected by the C++ standard is the (path and) name of the running application. If this is not available the standard expects "argv[0][0] == '\0'".

Your code passes the 1st "real" argument as argv[0]. It suggests itself that this might mislead the receiving library.

b)
The standard expects "argv[argc] == (char* 0)".

I'm not sure whether your code guarantees that and this missing final pointer could terribly crash the library and everything else.

c)
argv itself and the strings to which it points must be modifiable.

You use "const char **argv".

d)
Finally the "application name issue" makes your cnt (= argc) carry a wrong value - 1 too few.

Smile Apologies for this lecture! Smile

Werner
Previous Topic: Web/SSL SSL_CTX_load_verify_locations [FEATURE REQUEST]
Next Topic: cutting the string
Goto Forum:
  


Current Time: Tue Apr 30 10:24:54 CEST 2024

Total time taken to generate the page: 0.03224 seconds