2 * Emulator initialisation code
8 #include "wine/winbase16.h"
17 #include "stackframe.h"
18 #include "wine/exception.h"
19 #include "debugtools.h"
21 static BOOL
exec_program( LPCSTR cmdline
)
23 HINSTANCE handle
= WinExec( cmdline
, SW_SHOWNORMAL
);
26 MESSAGE( "%s: can't exec '%s': ", argv0
, cmdline
);
29 case 2: MESSAGE("file not found\n" ); break;
30 case 11: MESSAGE("invalid exe file\n" ); break;
31 default: MESSAGE("error=%d\n", handle
); break;
34 return (handle
>= 32);
37 /***********************************************************************
38 * Main loop of initial task
40 void MAIN_EmulatorRun( void )
42 char startProg
[256], defProg
[256];
46 /* Load system DLLs into the initial process (and initialize them) */
47 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
48 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
51 /* Get pointers to USER routines called by KERNEL */
54 /* Call FinalUserInit routine */
55 Callout
.FinalUserInit16();
57 /* Call InitApp for initial task */
58 Callout
.InitApp16( MapHModuleLS( 0 ) );
60 /* Add the Startup Program to the run list */
61 PROFILE_GetWineIniString( "programs", "Startup", "",
62 startProg
, sizeof(startProg
) );
63 if (startProg
[0]) tasks
+= exec_program( startProg
);
65 /* Add the Default Program if no program on the command line */
68 PROFILE_GetWineIniString( "programs", "Default", "",
69 defProg
, sizeof(defProg
) );
70 if (defProg
[0]) tasks
+= exec_program( defProg
);
71 else if (!tasks
&& !startProg
[0]) OPTIONS_Usage();
75 /* Load and run executables given on command line */
76 for (i
= 1; Options
.argv
[i
]; i
++)
78 tasks
+= exec_program( Options
.argv
[i
] );
81 if (!tasks
) ExitProcess( 0 );
83 /* Start message loop for desktop window */
85 while ( GetNumTasks16() > 1 && Callout
.GetMessageA( &msg
, 0, 0, 0 ) )
87 Callout
.TranslateMessage( &msg
);
88 Callout
.DispatchMessageA( &msg
);
95 /**********************************************************************
98 int main( int argc
, char *argv
[] )
102 /* Initialize everything */
103 if (!MAIN_MainInit( argc
, argv
, FALSE
)) return 1;
105 /* Create initial task */
106 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
107 if ( !TASK_Create( pModule
, FALSE
) ) return 1;
109 /* Switch to initial task */
110 PostEvent16( PROCESS_Current()->task
);
113 /* Switch stacks and jump to MAIN_EmulatorRun */
114 CALL32_Init( &IF1632_CallLargeStack
, MAIN_EmulatorRun
, NtCurrentTeb()->stack_top
);
116 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );