Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Comparing commandline arguments

5 views
Skip to first unread message

Carsten Unterberg

unread,
Oct 13, 2009, 2:57:03 AM10/13/09
to
Hey everybody,

I am very new in C++, esp. on mobile devices based on
WindowsCe/WindowsMobile. For my current project, I need to compare
commandline arguments.

My Main()-function is defined like that:

int WINAPI WinMain(HINSTANCE h, HINSTANCE, LPTSTR arg, int nCmdShow)
{
//do something
}

In the definition of the Main()-function is a long pointer for the args. How
can I compare that 'string' with a own, specified parameter?

Best regards,

Carsten Unterberg | Test-Framework
http://test-framework.blogspot.com/


Ulrich Eckhardt

unread,
Oct 13, 2009, 3:32:19 AM10/13/09
to
Carsten Unterberg wrote:
> I am very new in C++, esp. on mobile devices based on
> WindowsCe/WindowsMobile. For my current project, I need to compare
> commandline arguments.
>
> My Main()-function is defined like that:
>
> int WINAPI WinMain(HINSTANCE h, HINSTANCE, LPTSTR arg, int nCmdShow)
> {
> //do something
> }
>
> In the definition of the Main()-function is a long pointer for the args.
> How can I compare that 'string' with a own, specified parameter?

The parameter is a TCHAR string, which evaluates to a CHAR or WCHAR string,
depending on the settings. Under CE though, it always is a WCHAR string.
Now, in order to compare TCHAR strings, use _tcscmp():

if(_tcscmp(arg, _T("some other text")==0)
found_it("!");

Under CE, you can also just drop the TCHAR stuff and directly use WCHAR:

... WinMain(..., WCHAR const* arg, ..) {
if(wcscmp(arg, L"some text"))
...
}

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

Luca Calligaris [eMVP]

unread,
Oct 13, 2009, 9:41:47 AM10/13/09
to
Unfortunately Windows CE does not support CommandLineToArg function which
converts the arg parameter of WinMain (remember that arg excludes the
program name)
in something like argc/argv. You can anyway find a lot of ready to use code
if you search the web for "winmain argc argv"

By the way, if you are writing a console program (but probably it is not the
case) your applicatin entry point can be wmain(int argc, WCHAR argv[]) or
_tmain(int argc, TCHAR argv).

--
Luca Calligaris (MVP-Windows Embedded)
l.calliga...@eurotech.it.nospam
www.eurotech.it


"Ulrich Eckhardt" <eckh...@satorlaser.com> ha scritto nel messaggio
news:31ndq6-...@satorlaser.homedns.org...

> Gesch�ftsf�hrer: Thorsten F�cking, Amtsgericht Hamburg HR B62 932
>


0 new messages