Arguments On a Console eMbedded Visual C++ Application

936 Views Asked by At

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:

int WinMain(int argc,char **argv) {
    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.

3

There are 3 best solutions below

3
On

The 'main' function of a Windows application can take one of a few different forms. There's WinMain, there's main and wmain. In your case, you've written a WinMain function that takes classic main parameters (i.e. argc and argv).

I'd recommend that you switch the name of your function to main and confirm that your Visual Studio project is correctly configured for the "correct" application entry point.

0
On

You need to supply more details about the embedded platform. Embedded platforms vary widely from desktop computers, especially about their resources such as file systems I/O, memory capacity and hardware layout (addressing).

For developing a WinCE application, you must confirm that the platform supports a file system. Many embedded systems don't.

Next, you should research on how WinCE is set up to execute a C function: does it use Windows (WinMain), tmain, wmain or main? Also, you need to research how parameters are passed to the program. Windowing programming is different than "console" programming.

0
On

WinMain is defined as

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR    lpCmdLine, /* command line */
                   int       nCmdShow)

You'd probably want something similar to

if (sscanf(lpCmdLine, "%s", filename) != 1) {
  showHelp();
}