- Updated API files
[wine.git] / miscemu / main.c
blobf141ba4c58886eadb80c3379f35a0e6476d31936
1 /*
2 * Emulator initialisation code
4 */
6 #include <stdlib.h>
7 #include <assert.h>
8 #include "wine/winbase16.h"
9 #include "callback.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "thread.h"
16 #include "task.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 )
26 HINSTANCE handle;
28 if (Options.debug)
29 handle = DEBUG_WinExec( cmdline, SW_SHOWNORMAL );
30 else
31 handle = WinExec( cmdline, SW_SHOWNORMAL );
33 if (handle < 32)
35 MESSAGE( "%s: can't exec '%s': ", argv0, cmdline );
36 switch (handle)
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];
52 int i, tasks = 0;
53 MSG msg;
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"))
58 ExitProcess( 1 );
60 /* Get pointers to USER routines called by KERNEL */
61 THUNK_InitCallout();
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 */
75 if (!Options.argv[1])
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();
82 else
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 );
100 ExitProcess( 0 );
104 /**********************************************************************
105 * main
107 int main( int argc, char *argv[] )
109 NE_MODULE *pModule;
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 );
120 TASK_Reschedule();
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" );
126 return 0;