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];
45 char szGraphicsDriver
[MAX_PATH
];
47 if (PROFILE_GetWineIniString( "Wine", "GraphicsDriver",
48 "x11drv", szGraphicsDriver
, sizeof(szGraphicsDriver
)))
50 if (!LoadLibraryA( szGraphicsDriver
)) ExitProcess(1);
53 /* Load system DLLs into the initial process (and initialize them) */
54 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
55 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
58 /* Get pointers to USER routines called by KERNEL */
61 /* Call FinalUserInit routine */
62 Callout
.FinalUserInit16();
64 /* Call InitApp for initial task */
65 Callout
.InitApp16( MapHModuleLS( 0 ) );
67 /* Add the Startup Program to the run list */
68 PROFILE_GetWineIniString( "programs", "Startup", "",
69 startProg
, sizeof(startProg
) );
70 if (startProg
[0]) tasks
+= exec_program( startProg
);
72 /* Add the Default Program if no program on the command line */
75 PROFILE_GetWineIniString( "programs", "Default", "",
76 defProg
, sizeof(defProg
) );
77 if (defProg
[0]) tasks
+= exec_program( defProg
);
78 else if (!tasks
&& !startProg
[0]) OPTIONS_Usage();
82 /* Load and run executables given on command line */
83 for (i
= 1; Options
.argv
[i
]; i
++)
85 tasks
+= exec_program( Options
.argv
[i
] );
88 if (!tasks
) ExitProcess( 0 );
90 /* Start message loop for desktop window */
92 while ( GetNumTasks16() > 1 && Callout
.GetMessageA( &msg
, 0, 0, 0 ) )
94 Callout
.TranslateMessage( &msg
);
95 Callout
.DispatchMessageA( &msg
);
102 /**********************************************************************
105 int main( int argc
, char *argv
[] )
109 /* Initialize everything */
110 if (!MAIN_MainInit( argc
, argv
, FALSE
)) return 1;
112 if (!THREAD_InitStack( NtCurrentTeb(), 0, TRUE
)) return 1;
113 SIGNAL_Init(); /* reinitialize signal stack */
115 /* Initialize KERNEL */
116 if (!LoadLibraryA( "KERNEL32" )) return FALSE
;
118 /* Create initial task */
119 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
120 if ( !TASK_Create( pModule
, FALSE
) ) return 1;
122 /* Switch to initial task */
123 PostEvent16( PROCESS_Current()->task
);
126 /* Switch stacks and jump to MAIN_EmulatorRun */
127 CALL32_Init( &IF1632_CallLargeStack
, MAIN_EmulatorRun
, NtCurrentTeb()->stack_top
);
129 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );