WinCe, start Aplication with parameter???

Started by ml1969, May 21, 2009, 10:43:04 AM

Previous topic - Next topic

ml1969

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):

#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

Hello,

I found a code snipplet, that works quiet fine:

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

AlexN

Quote from: ml1969 on May 21, 2009, 10:43:04 AM
This is my "basic"-code (test.exe):

#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

 :)
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

Stefan Pendl

Quote from: ml1969 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....
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