NO

Author Topic: WinCe, start Aplication with parameter???  (Read 3630 times)

ml1969

  • Guest
WinCe, start Aplication with parameter???
« on: May 21, 2009, 10:43:04 AM »
Hello,

Im still at the beginnig of C, some things goes very well, and Im learning every day more...

Now, I have a problem, where I cannot find any answers. Not really in MSDN, here or google, so I hope someone can healp me.

I will writing an application for a WINCE Device (PNA).
This is my "basic"-code (test.exe):
Code: [Select]
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>

/** Prototypes **************************************************************/

/** Global variables ********************************************************/

/****************************************************************************
 *
 * Function: WinMain
 *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
   
MessageBox(NULL,TEXT("Hello World"),TEXT("Test"),MB_OKCANCEL);

return 0;
}

It shows me a messagebox an exit after clicking OK or CANCEL.


I want to call this ap with parameters e.g. 
test.exe "parameter1" "parameter2"  where parameter1 = \My Flash Disk\test2.exe

Instaed of the messagebox I will do something like:
CreateProcess(parameter1,NULL,0,0,FALSE,0, 0, 0, NULL, NULL);


I found something with arc and argv in MSDN:
int main( int argc,      // Number of strings in array argv
          char *argv[],   // Array of command-line argument strings
          char *envp[] )  // Array of environment variable strings

but I dont know how to use this exactly.

Michael


ml1969

  • Guest
Re: WinCe, start Aplication with parameter???
« Reply #1 on: May 21, 2009, 01:06:37 PM »
Hello,

I found a code snipplet, that works quiet fine:
Code: [Select]
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
  // MessageBox(NULL,TEXT("1"),TEXT("1"),MB_OK);
wchar_t szParams[255];


    lstrcpy(szParams, lpszCmdLine);
    CharUpper(szParams);
   
    if (!*szParams) {
return 0;
}
wchar_t Multi [100][16];
wchar_t *token;
long L_Counter = 0;
//wchar_t *ptr;

   token = wcstok( szParams, L"-" , NULL);
   while( token != NULL )
   {
  wcscpy(Multi[L_Counter],token);
         token = wcstok( NULL, L"-", NULL );
  L_Counter++;
  MessageBoxW(NULL, Multi[L_Counter], L"This is a test", MB_OK);
   }



return 0;
}

But something seems to be wrong.
If i call the ap  test.exe -test -\My flash disk\test.exe

the first array is empty and the second one show only est.exe :-)

Any suggestions?

Michael

Offline AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: WinCe, start Aplication with parameter???
« Reply #2 on: May 22, 2009, 11:01:58 AM »
This is my "basic"-code (test.exe):
Code: [Select]
#include <windows.h>
#include <windowsx.h>
/****************************************************************************
 *
 * Function: WinMain
 *
 ****************************************************************************/

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpszCmdLine, int nCmdShow)
{
   
MessageBox(NULL,TEXT("Hello World"),TEXT("Test"),MB_OKCANCEL);

return 0;
}

I want to call this ap with parameters e.g. 
test.exe "parameter1" "parameter2"  where parameter1 = \My Flash Disk\test2.exe

If you look you will see that the function WinMain has a parameter lpszCmdLine, there you will find your parameters.
best regards
 Alex ;)

ml1969

  • Guest
Re: WinCe, start Aplication with parameter???
« Reply #3 on: May 24, 2009, 12:31:53 PM »
 :)
Thanks it works ....
But I have one little problem.
If i take 2 Parameter e.g.  test.exe -param1 -param2  there is a whitespace between the two parameters, so I have to call the application:
test.exe -param1-param2

How can I remove the Whitespace at the end?
The App should work on an WinCe Device....


Michael

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: WinCe, start Aplication with parameter???
« Reply #4 on: May 24, 2009, 12:59:13 PM »
:)
Thanks it works ....
But I have one little problem.
If i take 2 Parameter e.g.  test.exe -param1 -param2  there is a whitespace between the two parameters, so I have to call the application:
test.exe -param1-param2

How can I remove the Whitespace at the end?
The App should work on an WinCe Device....
I would not remove the whitespace, but change the parsing routine, since parameters are always separated by whitespace.

If you only need to check if the command line includes a certain option, you do not need to do anything, just use the appropriate string compare command.
---
Stefan

Proud member of the UltraDefrag Development Team