Implemented new Wine startup sequence, separating startup into
[wine/wine-kai.git] / miscemu / main.c
blobe28d8e8e8afb63ac474eacbe521cd428a228590d
1 /*
2 * Emulator initialisation code
4 */
6 #include <assert.h>
7 #include "callback.h"
8 #include "debug.h"
9 #include "debugger.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "win16drv.h"
16 #include "psdrv.h"
17 #include "thread.h"
18 #include "windows.h"
21 /***********************************************************************
22 * Emulator initialisation
24 BOOL32 MAIN_EmulatorInit(void)
26 /* Main initialization */
27 if (!MAIN_MainInit()) return FALSE;
29 /* Initialize relay code */
30 if (!RELAY_Init()) return FALSE;
32 /* Initialize signal handling */
33 if (!SIGNAL_InitEmulator()) return FALSE;
35 /* Create the Win16 printer driver */
36 if (!WIN16DRV_Init()) return FALSE;
38 /* Create the Postscript printer driver (FIXME: should be in Winelib) */
39 if (!PSDRV_Init()) return FALSE;
41 /* Load system DLLs into the initial process (and initialize them) */
42 if (!LoadLibrary16( "KERNEL" )) return FALSE; /* always built-in */
43 if (!LoadLibrary32A( "KERNEL32" )) return FALSE; /* always built-in */
45 if (!LoadLibrary16( "GDI.EXE" )) return FALSE;
46 if (!LoadLibrary32A( "GDI32.DLL" )) return FALSE;
48 if (!LoadLibrary16( "USER.EXE" )) return FALSE;
49 if (!LoadLibrary32A( "USER32.DLL" )) return FALSE;
51 return TRUE;
55 /***********************************************************************
56 * Main loop of initial task
58 void MAIN_EmulatorRun( void )
60 BOOL32 (*WINAPI pGetMessage)(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max);
61 BOOL32 (*WINAPI pTranslateMessage)( const MSG32* msg );
62 LONG (*WINAPI pDispatchMessage)( const MSG32* msg );
63 MSG32 msg;
65 HMODULE32 hModule = GetModuleHandle32A( "USER32" );
66 pGetMessage = GetProcAddress32( hModule, "GetMessageA" );
67 pTranslateMessage = GetProcAddress32( hModule, "TranslateMessage" );
68 pDispatchMessage = GetProcAddress32( hModule, "DispatchMessageA" );
70 assert( pGetMessage );
71 assert( pTranslateMessage );
72 assert( pDispatchMessage );
74 while ( GetNumTasks() > 1 && pGetMessage( &msg, 0, 0, 0 ) )
76 pTranslateMessage( &msg );
77 pDispatchMessage( &msg );
80 ExitProcess( 0 );
84 /**********************************************************************
85 * main
87 int main( int argc, char *argv[] )
89 extern char * DEBUG_argv0;
90 char startProg[256], defProg[256];
91 int i,loaded;
92 HINSTANCE32 handle;
94 __winelib = 0; /* First of all, clear the Winelib flag */
97 * Save this so that the internal debugger can get a hold of it if
98 * it needs to.
100 DEBUG_argv0 = argv[0];
102 /* Create the initial process */
103 if (!PROCESS_Init()) return FALSE;
105 /* Parse command-line */
106 if (!MAIN_WineInit( &argc, argv )) return 1;
108 /* Handle -dll option (hack) */
110 if (Options.dllFlags)
112 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
114 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
115 argv[0] );
116 BUILTIN_PrintDLLs();
117 exit(1);
121 /* Initialize everything */
123 if (!MAIN_EmulatorInit()) return 1;
125 /* Initialize CALL32 routines */
126 /* This needs to be done just before task-switching starts */
128 loaded=0;
130 /* Add the Default Program if no program on the command line */
131 if (!argv[1])
133 PROFILE_GetWineIniString( "programs", "Default", "",
134 defProg, sizeof(defProg) );
135 if (defProg[0]) argv[argc++] = defProg;
138 /* Add the Startup Program to the run list */
139 PROFILE_GetWineIniString( "programs", "Startup", "",
140 startProg, sizeof(startProg) );
141 if (startProg[0]) argv[argc++] = startProg;
143 for (i = 1; i < argc; i++)
145 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
147 MSG("wine: can't exec '%s': ", argv[i]);
148 switch (handle)
150 case 2: MSG("file not found\n" ); break;
151 case 11: MSG("invalid exe file\n" ); break;
152 case 21: MSG("win32 executable\n" ); break; /* FIXME: Obsolete? */
153 default: MSG("error=%d\n", handle ); break;
155 return 1;
157 loaded++;
160 if (!loaded) { /* nothing loaded */
161 MAIN_Usage(argv[0]);
162 return 1;
165 if (!GetNumTasks())
167 MSG("wine: no executable file found.\n" );
168 return 0;
171 if (Options.debug) DEBUG_AddModuleBreakpoints();
173 ctx_debug_call = ctx_debug;
174 #if 0 /* FIXME!! */
175 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
176 #endif
177 MAIN_EmulatorRun();
178 MSG("WinMain: Should never happen: returned from Yield16()\n" );
179 return 0;