2 * Emulator initialisation code
8 #include "wine/winbase16.h"
19 #include "stackframe.h"
20 #include "wine/exception.h"
21 #include "debugtools.h"
24 static char **MAIN_argv
;
27 /***********************************************************************
28 * Emulator initialisation
30 BOOL
MAIN_EmulatorInit(void)
32 /* Main initialization */
33 if (!MAIN_MainInit()) return FALSE
;
35 /* Initialize relay code */
36 if (!RELAY_Init()) return FALSE
;
38 /* Create the Win16 printer driver */
39 if (!WIN16DRV_Init()) return FALSE
;
45 /***********************************************************************
46 * Main loop of initial task
48 void MAIN_EmulatorRun( void )
50 extern void THUNK_InitCallout( void );
51 char startProg
[256], defProg
[256];
56 /* Load system DLLs into the initial process (and initialize them) */
57 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
58 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
61 /* Get pointers to USER routines called by KERNEL */
64 /* Call InitApp for initial task */
65 Callout
.InitApp16( MapHModuleLS( 0 ) );
67 /* Add the Default Program if no program on the command line */
70 PROFILE_GetWineIniString( "programs", "Default", "",
71 defProg
, sizeof(defProg
) );
72 if (defProg
[0]) MAIN_argv
[MAIN_argc
++] = defProg
;
75 /* Add the Startup Program to the run list */
76 PROFILE_GetWineIniString( "programs", "Startup", "",
77 startProg
, sizeof(startProg
) );
78 if (startProg
[0]) MAIN_argv
[MAIN_argc
++] = startProg
;
80 /* Abort if no executable on command line */
83 MAIN_Usage(MAIN_argv
[0]);
87 /* Load and run executables given on command line */
88 for (i
= 1; i
< MAIN_argc
; i
++)
90 if ((handle
= WinExec( MAIN_argv
[i
], SW_SHOWNORMAL
)) < 32)
92 MESSAGE("wine: can't exec '%s': ", MAIN_argv
[i
]);
95 case 2: MESSAGE("file not found\n" ); break;
96 case 11: MESSAGE("invalid exe file\n" ); break;
97 default: MESSAGE("error=%d\n", handle
); break;
105 MESSAGE("wine: no executable file found.\n" );
109 /* Start message loop for desktop window */
111 while ( GetNumTasks16() > 1 && Callout
.GetMessageA( &msg
, 0, 0, 0 ) )
113 Callout
.TranslateMessage( &msg
);
114 Callout
.DispatchMessageA( &msg
);
121 /**********************************************************************
124 int main( int argc
, char *argv
[] )
127 extern char * DEBUG_argv0
;
129 __winelib
= 0; /* First of all, clear the Winelib flag */
132 * Save this so that the internal debugger can get a hold of it if
135 DEBUG_argv0
= argv
[0];
137 /* Create the initial process */
138 if (!PROCESS_Init()) return FALSE
;
140 /* Parse command-line */
141 if (!MAIN_WineInit( &argc
, argv
)) return 1;
142 MAIN_argc
= argc
; MAIN_argv
= argv
;
144 /* Set up debugger hook */
145 EXC_SetDebugEventHook( wine_debugger
);
148 TASK_AddTaskEntryBreakpoint
= DEBUG_AddTaskEntryBreakpoint
;
150 /* Initialize everything */
151 if (!MAIN_EmulatorInit()) return 1;
153 /* Load kernel modules */
154 if (!LoadLibrary16( "KERNEL" )) return 1;
155 if (!LoadLibraryA( "KERNEL32" )) return 1;
157 /* Create initial task */
158 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
159 if ( !TASK_Create( pModule
, FALSE
) ) return 1;
161 /* Switch to initial task */
162 PostEvent16( PROCESS_Current()->task
);
165 /* Switch stacks and jump to MAIN_EmulatorRun */
166 CALL32_Init( &IF1632_CallLargeStack
, MAIN_EmulatorRun
, NtCurrentTeb()->stack_top
);
168 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );