x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Arguments On a Console eMbedded Visual C++ Application

nathanpc Page Icon Posted 2010-04-11 8:38 PM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
Hello,
I'm trying to develop a simple application that will read some files, targeted for Windows CE. For this I'm using Microsoft eMbedded Visual C++ 3. This program(that is for console) will be called like this:
/Storage Card/Test> coms file.cmss

As you can see, file.cmss is the first argument, but on my main I have a condition to show the help(the normal, how to use the program) if the arguments are smaller than 2:
if(argc < 2) { 
showhelp();
return 0;
}

But when I execute the program on the command-line of Windows CE(using all the necessary arguments) I got the showHelp() content. Then I've checked all the code, but it's entirelly correct. But I think that eVC++ don't use argc and argv[] for arguments, then I want some help on how to determine the arguments on it.

Best Regards,
Nathan Paulino Campos
 Top of the page
mscdex Page Icon Posted 2010-04-11 9:34 PM
#
Avatar image of mscdex
H/PC Sensei

Posts:
1,054
Location:
United States
Status:
Post the rest of the 'main' method, including the function declaration, as well as the command-line argument examples you are trying.
 Top of the page
nathanpc Page Icon Posted 2010-04-11 9:50 PM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
Here it is:
int WinMain(int argc,char **argv) { 
    if(argc < 2) {  
showhelp();
return 0;
}
/* Some more code that I don't want to show */

return 0;
}
 Top of the page
mscdex Page Icon Posted 2010-04-11 10:05 PM
#
Avatar image of mscdex
H/PC Sensei

Posts:
1,054
Location:
United States
Status:
Yes, your WinMain declaration should look like:
Quote
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpCmdLine, int sw)

where lpCmdLine is a "Pointer to a null-terminated string that specifies the command line for the application, excluding the program name."

Here is an additional resource which gives a fairly useful overview of WinCE C++ apps.

Edited by mscdex 2010-04-11 10:06 PM
 Top of the page
nathanpc Page Icon Posted 2010-04-11 10:23 PM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
But I have things like this on my WinMain function:
	for(i=1;i<argc;i++ { 
		if(*argv=='-' || *argv=='/' { 
switch(argv[1]) {
case 'h':
case '?':
showhelp();
return 0;
case 'L':
verboselisting=1;
case 'l':
listfilename=(char*)1;
break;
case 'd':
if(argv[2]) {
if(!findlabel(&argv[2])) {
p=newlabel();
(*p).name=strdup(&argv[2]);
(*p).type=VALUE;
(*p).value=1;
(*p).line=(char*)1;
(*p).pass=0;
}
}
break;
default:
printf("unknown option: %s\n",argv);
break;
}
} else {
if(notoption==0)
inputfilename=argv;
else if(notoption==1)
outputfilename=argv;
else if(notoption==2)
listfilename=argv;
else
printf("unused argument: %s\n",argv);
notoption++;
}
}


Then what I need to change?

Remember that if I try to use main instead of WinMain, I got this:
Deleting intermediate files and output files for project 'ASM - Win32 (WCE ARM) Release'. 
--------------------Configuration: ASM - Win32 (WCE ARM) Release--------------------
Compiling...
main.c
C:\Documents and Settings\Nathan\Desktop\ASM\celib\inc\cecrt_defs.h(147) : warning C4005: 'fileno' : macro redefinition
C:\Windows CE Toolsramas\wce211\MS HPC PRO\include\stdlib.h(332) : see previous definition of 'fileno'
Linking...
corelibc.lib(pegwmain.obj) : error LNK2001: unresolved external symbol WinMain
ARMRel/ASM.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ASM.exe - 2 error(s), 1 warning(s)
 Top of the page
mscdex Page Icon Posted 2010-04-11 11:35 PM
#
Avatar image of mscdex
H/PC Sensei

Posts:
1,054
Location:
United States
Status:
In your WinMain, simply create an argv array which contains the tokens from lpCmdLine and argc which contains the count of argv (obviously). You may want to create a separate function that does the token array generation if your application may have arguments that are more complex and require more than a simple call to wcstok, using a space character as the delimiter.

Something else I read is that depending on the version of CE, lpCmdLine may not be supplied by the OS. In that case you will have to use GetCommandLine which returns a LPTSTR instead of a LPWSTR.

This SO question may be of particular interest too.
 Top of the page
nathanpc Page Icon Posted 2010-04-13 10:23 PM
#
Avatar image of nathanpc
H/PC Philosopher

Posts:
327
Location:
Portugal
Status:
How can I do this?
 Top of the page
technogeist2k9 Page Icon Posted 2010-06-12 1:18 PM
#
Avatar image of technogeist2k9
Factorite (Elite)

Posts:
156
Location:
United Kingdom
Status:
CommandLineToArgs is the only way I've successfully achieved this. I got the source and header from Embedded CE 5.0 or 6.0 (memory not good on this point)

Here is a snippet of my code (which is a working example) assuming the two files are in your search path. cmdline.cpp & cmdline.h

#include <cmdline.h>

#define MAX_CLARGS
#define MAXSTR 256

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {

LPTSTR argv[ MAX_CLARGS ];
int argc;

argc = MAX_CLARGS;
CommandLineToArgs( lpCmdLine, &argc, argv ); /* on return you will have the typical argv[] array + argc, NOTE: argv[0] does not contain the exe name. */



Edited by technogeist2k9 2010-06-12 1:19 PM
 Top of the page
Jump to forum:
Seconds to generate: 0.140 - Cached queries : 65 - Executed queries : 9