Thread: argv[0] with WinMain()

  1. #1
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057

    argv[0] with WinMain()

    Is there a way to access the equivilent of argv[0] when you have WinMain()?

    In other words, is there a Windows function to return the name of the executable?
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    71

    I Think

    Please someone correct me if I'm wrong =P but I think the equivalent is LPSTR

    Code:
    int WINAPI WinMain(HINSTANCE,HISTANCE,LPSTR,int);
    You could always use the function GetModuleFileName

    example from winprog.org's site:

    Code:
            case WM_LBUTTONDOWN:
            {
                char szFileName[MAX_PATH];
                HINSTANCE hInstance = GetModuleHandle(NULL);
    
                GetModuleFileName(hInstance, szFileName, MAX_PATH);
                MessageBox(hwnd, szFileName, "This program is:", MB_OK | MB_ICONINFORMATION);
            }
            break;
    Last edited by Homunculus; 03-05-2006 at 11:15 AM.

  3. #3
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    no..

    LPSTR lpCmdLine is used for any parameters passed to the program, or if you drag and drop a file on the program it will have the path of the file.
    My Website
    010000110010101100101011
    Add Color To Your Code!

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Just use GetModuleFileName, and pass NULL as the first parameter. If you need the rest of the arguments, use GetCommandLine or the lpCmdLine variable passed to WinMain().

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Thanks.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. main() ; argv[1] = string at argv[0]???
    By UCnLA in forum C Programming
    Replies: 1
    Last Post: 03-31-2008, 12:16 AM
  2. WinMain entry point in .lib
    By cloudy in forum Windows Programming
    Replies: 8
    Last Post: 10-28-2006, 12:16 PM
  3. WinMain Paramaters.
    By C+noob in forum Windows Programming
    Replies: 8
    Last Post: 07-11-2005, 11:44 AM
  4. Silly WinMain question
    By Magos in forum Windows Programming
    Replies: 2
    Last Post: 09-07-2002, 09:38 AM
  5. Is this necessary: int APIENTRY WinMain
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2002, 07:09 PM