Thread: 2 questions: WINAPI? lpcmdline?

  1. #1
    Join Date
    Aug 2001

    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...

    Staying away from General.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    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.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    Join Date
    Jan 2002
    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-23-2007, 12:13 AM
  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
    Replies: 23
    Last Post: 12-26-2004, 09: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, 01:59 AM