CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4

Thread: Using command line help

  1. #1
    Join Date
    Nov 2009

    Question Using command line help

    I want to copy a file. I would like it so i can give the argument in command line and that would be the file name of the copied one. But when i run it with the argument, nothing happens. Also, can i set "lpCmdLine" to have a default value when no value is assigned to it? Thanks for help!

    #include <windows.h>
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
    lpCmdLine = (LPSTR)GetCommandLine();
    CopyFile(L"lol.txt", (LPCWSTR)lpCmdLine, FALSE);
    return 0;

  2. #2
    Join Date
    Apr 2009

    Re: Using command line help

    I am not sure if it is a good thing to call GetCommandLine(). This will override the content of lpCmdLine. This is a pity since lpCmdLine is already containing your command line. You can see what is in this variable, with
    FILE *log_fp; log_fp = fopen(log_file, "wt"); fprintf(log_fp, lpCmdLine); fclose(log_fp);

  3. #3
    Join Date
    Apr 2004

    Re: Using command line help

    To convert the command line to an argv style array of strings, call CommandLineToArgvW which is explained at GetCommandLine

  4. #4
    Join Date
    Sep 2009

    Re: Using command line help

    You can use the global variables __argc and __argv (and probably __envp), which contain the cmdline arguments like in a standard C program

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)