Problems with Command Line Args in MFC App
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Problems with Command Line Args in MFC App

  1. #1
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Problems with Command Line Args in MFC App

    I read a few of the posts on this after doing a search but didn't see my situation in them.

    My situation is wanting to receive 2 strings.
    1. a path with c:\Program Files\.....
    2. a DLL to register using RegAsm.exe through the use of WaitForSingleObject and SHELLEXECUTEINFO STRUCT.

    The problem I am running into is with the command CommandLineToArgvW()

    see below (path is first)

    Code:
    	szArgList = CommandLineToArgvW(lpCmdLine, &argCount);
    	Register the com dll in directory sent in in lpCmdLine
    	CString sDllName = szArgList[1];
    	sDllName += " /Silent";
    	CString sExeDir = szArgList[0];
    The sDllName is good but...
    No matter what I have tried sExeDir ends up being "c:\Progam" and the space is cutting off full path name , ,,,because of wide char function?

    I also noticed _UNICODE is defined and I dont remember doing that.

    How would you do this? Differently?

    Oh one other thing, I noticed that it works fine when commandline is supplied and run in Visual Studio but not when app is run separately and values are supplied through Start and Run in windows. Strange and frustrating. Don't understand.

  2. #2
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Problems with Command Line Args in MFC App

    You didn't show how you start it from the command line, but try enclosing your command line arguments in quotes:
    Code:
    C:\Myapp>myexe "C:\Program Files\MyDir\argfile.txt"
    Normally, each argument is separated by a space, but since this ONE argument actually contains a space, you need to enclose it in quotes.

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  3. #3
    Join Date
    Aug 2000
    Location
    High on a hill in the Ohio valley
    Posts
    711

    Re: Problems with Command Line Args in MFC App

    Yea I did that.
    In debug both args 0 , and 1 appear full strings but when assigned into CString vars is where the trouble begins.

    I may have to post the project to show what I mean.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center