2 * Emulator initialisation code
8 #include "wine/winbase16.h"
17 #include "stackframe.h"
18 #include "wine/exception.h"
19 #include "debugtools.h"
21 extern DWORD DEBUG_WinExec(LPCSTR lpCmdLine, int sw);
24 static BOOL exec_program( LPCSTR cmdline )
29 handle = DEBUG_WinExec( cmdline, SW_SHOWNORMAL );
31 handle = WinExec( cmdline, SW_SHOWNORMAL );
35 MESSAGE( "%s: can't exec '%s': ", argv0, cmdline );
38 case 2: MESSAGE("file not found\n" ); break;
39 case 11: MESSAGE("invalid exe file\n" ); break;
40 default: MESSAGE("error=%d\n", handle ); break;
43 return (handle >= 32);
46 /***********************************************************************
47 * Main loop of initial task
49 void MAIN_EmulatorRun( void )
51 char startProg[256], defProg[256];
55 /* Load system DLLs into the initial process (and initialize them) */
56 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
57 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
60 /* Get pointers to USER routines called by KERNEL */
63 /* Call FinalUserInit routine */
64 Callout.FinalUserInit16();
66 /* Call InitApp for initial task */
67 Callout.InitApp16( MapHModuleLS( 0 ) );
69 /* Add the Startup Program to the run list */
70 PROFILE_GetWineIniString( "programs", "Startup", "",
71 startProg, sizeof(startProg) );
72 if (startProg[0]) tasks += exec_program( startProg );
74 /* Add the Default Program if no program on the command line */
77 PROFILE_GetWineIniString( "programs", "Default", "",
78 defProg, sizeof(defProg) );
79 if (defProg[0]) tasks += exec_program( defProg );
80 else if (!tasks && !startProg[0]) OPTIONS_Usage();
84 /* Load and run executables given on command line */
85 for (i = 1; Options.argv[i]; i++)
87 tasks += exec_program( Options.argv[i] );
90 if (!tasks) ExitProcess( 0 );
92 /* Start message loop for desktop window */
94 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
96 Callout.TranslateMessage( &msg );
97 Callout.DispatchMessageA( &msg );
104 /**********************************************************************
107 int main( int argc, char *argv[] )
111 /* Initialize everything */
112 if (!MAIN_MainInit( &argc, argv, FALSE )) return 1;
114 /* Create initial task */
115 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
116 if ( !TASK_Create( pModule, FALSE ) ) return 1;
118 /* Switch to initial task */
119 PostEvent16( PROCESS_Current()->task );
122 /* Switch stacks and jump to MAIN_EmulatorRun */
123 CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
125 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );