2 questions: WINAPI? lpcmdline?

This is a discussion on 2 questions: WINAPI? lpcmdline? within the Windows Programming forums, part of the Platform Specific Boards category; I'm reading two books that are explaining Windows Programming. The first is Petzold's Programming Windows, and the second is Lamothe's ...

  1. #1
    Ecologist
    Join Date
    Aug 2001
    Location
    Utah.
    Posts
    1,291

    2 questions: WINAPI? lpcmdline?

    I'm reading two books that are explaining Windows Programming.
    The first is Petzold's Programming Windows, and the second is
    Lamothe's Tricks of the Windows Game Programming Gurus ().
    I'm not far along in either of them...

    I'm really using TOTWGPG to learnDirectX. The first couple of
    of chapters in each book pretty much talk about the same thing.
    They explain it in different ways, though. That's good, makes it
    easier to understand.


    Anywho, in Lamothe's book, it says that WINAPI forces parameters
    to be passed left-to-right instead of the normal right-to-left order
    with the default CDECL.

    What exactly does this mean? I'm not completely finished learning
    C++, but what's the default CDECL? Can someone give an
    example of what Lamothe is talking about?

    Second question. Lamothe says that lpcmdline (the WinMain()
    parameter) is a null-terminated string that takes command-line
    parameters. He says that if you create a program called TEST.exe
    and launch it like this:

    TEST.exe one

    lpcmdline will contain the following:

    lpcmdline = "one two three."

    Is this just a printing mistake or something? I just want to make
    sure, because if it isn't -- I'm totally lost and need an explanation
    on why lpcmdline contains two extra words...

    Thanks.
    -ethic.
    Staying away from General.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    Must be a misprint. Basically, instead of handing you your argc, argv, Windows "helpfully" packs it into a single string, leaving it up to you to parse. Oddly enough, you usually can't obtain it from the third param of WinMain! You have to use something like GetCommandLine().

    You'll have to talk to an ASM expert to get a definitive answer on the calling convention question, but basically, it has to do with the order that function parameters are pushed onto the stack, and how everything gets cleaned up after the function call.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    You may be interested in GetCommandLine to ensure UNICODE compliance; the lpCmdLine parameter of WinMain only delivers ANSI strings, ie (from msdn):
    ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type.
    Hope that is of some interest to you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 11-22-2007, 11:13 PM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  4. Trouble with lpCmdLine
    By BianConiglio in forum C Programming
    Replies: 9
    Last Post: 05-07-2004, 08:39 AM
  5. Questions about WINAPI
    By GaPe in forum Windows Programming
    Replies: 8
    Last Post: 02-26-2002, 12:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21