2 * Emulator initialisation code
8 #include "wine/winbase16.h"
18 #include "stackframe.h"
19 #include "wine/exception.h"
20 #include "debugtools.h"
23 static char **MAIN_argv;
26 /***********************************************************************
27 * Main loop of initial task
29 void MAIN_EmulatorRun( void )
31 char startProg[256], defProg[256];
36 /* Load system DLLs into the initial process (and initialize them) */
37 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
38 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
41 /* Get pointers to USER routines called by KERNEL */
44 /* Call InitApp for initial task */
45 Callout.InitApp16( MapHModuleLS( 0 ) );
47 /* Add the Default Program if no program on the command line */
50 PROFILE_GetWineIniString( "programs", "Default", "",
51 defProg, sizeof(defProg) );
52 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
55 /* Add the Startup Program to the run list */
56 PROFILE_GetWineIniString( "programs", "Startup", "",
57 startProg, sizeof(startProg) );
58 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
60 /* Abort if no executable on command line */
63 MAIN_Usage(MAIN_argv[0]);
67 /* Load and run executables given on command line */
68 for (i = 1; i < MAIN_argc; i++)
70 if ((handle = WinExec( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
72 MESSAGE("wine: can't exec '%s': ", MAIN_argv[i]);
75 case 2: MESSAGE("file not found\n" ); break;
76 case 11: MESSAGE("invalid exe file\n" ); break;
77 default: MESSAGE("error=%d\n", handle ); break;
85 MESSAGE("wine: no executable file found.\n" );
89 /* Start message loop for desktop window */
91 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
93 Callout.TranslateMessage( &msg );
94 Callout.DispatchMessageA( &msg );
101 /**********************************************************************
104 int main( int argc, char *argv[] )
107 extern char * DEBUG_argv0;
109 __winelib = 0; /* First of all, clear the Winelib flag */
112 * Save this so that the internal debugger can get a hold of it if
115 DEBUG_argv0 = argv[0];
117 /* Create the initial process */
118 if (!PROCESS_Init()) return FALSE;
120 /* Parse command-line */
121 if (!MAIN_WineInit( &argc, argv )) return 1;
122 MAIN_argc = argc; MAIN_argv = argv;
124 /* Set up debugger hook */
125 EXC_SetDebugEventHook( wine_debugger );
128 TASK_AddTaskEntryBreakpoint = DEBUG_AddTaskEntryBreakpoint;
130 /* Initialize everything */
131 if (!MAIN_MainInit()) return 1;
133 /* Load kernel modules */
134 if (!LoadLibrary16( "KERNEL" )) return 1;
135 if (!LoadLibraryA( "KERNEL32" )) return 1;
137 /* Create initial task */
138 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
139 if ( !TASK_Create( pModule, FALSE ) ) return 1;
141 /* Switch to initial task */
142 PostEvent16( PROCESS_Current()->task );
145 /* Switch stacks and jump to MAIN_EmulatorRun */
146 CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
148 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );