Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    int main( void );
    int main( int argc, const char *argv[] );
    int wmain( void );
    int wmain( int argc, wchar_t *argv[] );
    int PASCAL WinMain( HINSTANCE hInstance,
                        HINSTANCE hPrevInstance,
                        LPSTR lpszCmdLine,
                        int nCmdShow );
    int PASCAL wWinMain( HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         wcharT *lpszCmdLine,
                         int nCmdShow );

Description:
     main is a user-supplied function where program execution begins.  The
    command line to the program is broken into a sequence of tokens
    separated by blanks and are passed to main as an array of pointers to
    character strings in the parameter argv.  The number of arguments found
    is passed in the parameter argc.  The first element of argv will be a
    pointer to a character string containing the program name.  The last
    element of the array pointed to by argv will be a NULL pointer (i.e.
     argv[argc] will be NULL).  Arguments that contain blanks can be passed
    to main by enclosing them within double quote characters (which are
    removed from that element in the argv vector.

    The command line arguments can also be obtained in its original format
    by using the  getcmd function.

    Alternatively, the main function can be declared to return  void (i.e.,
    no return value).  In this case, you will not be able to return an exit
    code from main using a  return statement; to do so, you must use the
     exit function.

    The wmain function is a user-defined wide-character version of main that
    operates with wide-character strings.  If this function is present in
    the application, then it will be called by the run-time system startup
    code (and the main function, if present, will not be called).

    As with main, the wmain function can be declared to return  void and the
    same considerations will apply.

    The  WinMain function is called by the system as the initial entry point
    for a Windows-based application.  The  wWinMain function is a
    wide-character version of  WinMain.

    Parameters     Meaning

hInstance
    Identifies the current instance of the application.

hPrevInstance
    Identifies the previous instance of the application.  For an application
    written for Windows NT, this parameter is always NULL.

lpszCmdLine
    Points to a null-terminated string specifying the command line for the
    application.

nCmdShow
    Specifies how the window is to be shown.  This parameter can be one of
    the following values:

    Value     Meaning

SW_HIDE
    Hides the window and activates another window.

SW_MINIMIZE
    Minimizes the specified window and activates the top-level window in the
    system's list.

SW_RESTORE
    Activates and displays a window.  If the window is minimized or
    maximized, Windows restores it to its original size and position (same
    as  SW_SHOWNORMAL).

SW_SHOW
    Activates a window and displays it in its current size and position.

SW_SHOWMAXIMIZED
    Activates a window and displays it as a maximized window.

SW_SHOWMINIMIZED
    Activates a window and displays it as an icon.

SW_SHOWMINNOACTIVE
    Displays a window as an icon.  The active window remains active.

SW_SHOWNA
    Displays a window in its current state.  The active window remains
    active.

SW_SHOWNOACTIVATE
    Displays a window in its most recent size and position.  The active
    window remains active.

SW_SHOWNORMAL
    Activates and displays a window.  If the window is minimized or
    maximized, Windows restores it to its original size and position (same
    as  SW_RESTORE).


    The  WinMain function initializes an application, and then performs a
    message retrieval-and-dispatch loop that is the top-level control
    structure for the remainder of the application's execution.  The loop
    terminates when a  WM_QUIT message is received.  At that point,  WinMain
    exits the application, returning the value passed in the  WM_QUIT
    message's  wParam parameter.  If  WM_QUIT was received as a result of
    calling  PostQuitMessage, the value of  wParam is the value of the
     PostQuitMessage function's  nExitCode parameter.

Returns:
    The main and wmain functions return an exit code back to the calling
    program (usually the operating system).

    If the  WinMain function terminates before entering the message loop, it
    should return 0.  Otherwise, it should terminate when it receives a
     WM_QUIT message and return the exit value contained in that message's
     wParam parameter.

Example:
    #include <stdio.h>

    int main( int argc, char *argv[] )
      {
        int i;
        for( i = 0; i < argc; ++i ) {
          printf( "argv[%d] = %s\n", i, argv[i] );
        }
        return( 0 );
      }
    #ifdef _WIDE_
    int wmain( int wargc, wchar_t *wargv[] )
      {
        int i;
        for( i = 0; i < wargc; ++i ) {
          wprintf( L"wargv[%d] = %s\n", i, wargv[i] );
        }
        return( 0 );
      }
    #endif

    produces the following:

    argv[0] = C:\WATCOM\DEMO\MYPGM.EXE
    argv[1] = hhhhh
    argv[2] = another arg

    when the program mypgm is executed with the command

    mypgm hhhhh  "another arg"

    A sample Windows main program is shown below.

    int PASCAL WinMain( HANDLE this_inst, HANDLE prev_inst,
                        LPSTR cmdline, int cmdshow )
      {
        MSG         msg;

        if( !prev_inst ) {
          if( !FirstInstance( this_inst ) ) return( 0 );
        }
        if( !AnyInstance( this_inst, cmdshow ) ) return( 0 );
        /*
          GetMessage returns FALSE when WM_QUIT is received
        */
        while( GetMessage( &msg, NULL, NULL, NULL ) ) {
          TranslateMessage( &msg );
          DispatchMessage( &msg );
        }
        return( msg.wParam );
      }

Classification:
    main is ANSI, wmain is not ANSI, WinMain is not ANSI, wWinMain is not
    ANSI

Systems:
     main - All, Netware

    wmain - Win32, OS/2-32
    WinMain - Windows, Win386, Win32
    wWinMain - Win32

See Also:
    abort, atexit, _bgetcmd, exec Functions, exit, _exit, getcmd, getenv,
    onexit, putenv, spawn Functions, system

See Also: abort atexit

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson