2 * Emulator initialisation code
19 #include "stackframe.h"
23 static char **MAIN_argv
;
25 /***********************************************************************
26 * Emulator initialisation
28 BOOL32
MAIN_EmulatorInit(void)
30 /* Main initialization */
31 if (!MAIN_MainInit()) return FALSE
;
33 /* Initialize relay code */
34 if (!RELAY_Init()) return FALSE
;
36 /* Initialize signal handling */
37 if (!SIGNAL_InitEmulator()) return FALSE
;
39 /* Create the Win16 printer driver */
40 if (!WIN16DRV_Init()) return FALSE
;
42 /* Create the Postscript printer driver (FIXME: should be in Winelib) */
43 if (!PSDRV_Init()) return FALSE
;
48 /***********************************************************************
49 * Main loop of initial task
51 void MAIN_EmulatorRun( void )
53 char startProg
[256], defProg
[256];
57 BOOL32 (*WINAPI pGetMessage
)(MSG32
* lpmsg
,HWND32 hwnd
,UINT32 min
,UINT32 max
);
58 BOOL32 (*WINAPI pTranslateMessage
)( const MSG32
* msg
);
59 LONG (*WINAPI pDispatchMessage
)( const MSG32
* msg
);
63 /* Load system DLLs into the initial process (and initialize them) */
64 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibrary32A("GDI32.DLL" )
65 || !LoadLibrary16("USER.EXE") || !LoadLibrary32A("USER32.DLL"))
68 /* Add the Default Program if no program on the command line */
71 PROFILE_GetWineIniString( "programs", "Default", "",
72 defProg
, sizeof(defProg
) );
73 if (defProg
[0]) MAIN_argv
[MAIN_argc
++] = defProg
;
76 /* Add the Startup Program to the run list */
77 PROFILE_GetWineIniString( "programs", "Startup", "",
78 startProg
, sizeof(startProg
) );
79 if (startProg
[0]) MAIN_argv
[MAIN_argc
++] = startProg
;
82 for (i
= 1; i
< MAIN_argc
; i
++)
84 if ((handle
= WinExec32( MAIN_argv
[i
], SW_SHOWNORMAL
)) < 32)
86 MSG("wine: can't exec '%s': ", MAIN_argv
[i
]);
89 case 2: MSG("file not found\n" ); break;
90 case 11: MSG("invalid exe file\n" ); break;
91 case 21: MSG("win32 executable\n" ); break; /* FIXME: Obsolete? */
92 default: MSG("error=%d\n", handle
); break;
99 if (!loaded
) { /* nothing loaded */
100 MAIN_Usage(MAIN_argv
[0]);
104 if (GetNumTasks() <= 1)
106 MSG("wine: no executable file found.\n" );
110 if (Options
.debug
) DEBUG_AddModuleBreakpoints();
113 /* Start message loop for desktop window */
115 hModule
= GetModuleHandle32A( "USER32" );
116 pGetMessage
= GetProcAddress32( hModule
, "GetMessageA" );
117 pTranslateMessage
= GetProcAddress32( hModule
, "TranslateMessage" );
118 pDispatchMessage
= GetProcAddress32( hModule
, "DispatchMessageA" );
120 assert( pGetMessage
);
121 assert( pTranslateMessage
);
122 assert( pDispatchMessage
);
124 while ( GetNumTasks() > 1 && pGetMessage( &msg
, 0, 0, 0 ) )
126 pTranslateMessage( &msg
);
127 pDispatchMessage( &msg
);
134 /**********************************************************************
137 int main( int argc
, char *argv
[] )
140 HINSTANCE16 hInstance
;
141 extern char * DEBUG_argv0
;
143 __winelib
= 0; /* First of all, clear the Winelib flag */
144 ctx_debug_call
= ctx_debug
;
147 * Save this so that the internal debugger can get a hold of it if
150 DEBUG_argv0
= argv
[0];
152 /* Create the initial process */
153 if (!PROCESS_Init()) return FALSE
;
155 /* Parse command-line */
156 if (!MAIN_WineInit( &argc
, argv
)) return 1;
157 MAIN_argc
= argc
; MAIN_argv
= argv
;
159 /* Handle -dll option (hack) */
160 if (Options
.dllFlags
)
162 if (!BUILTIN_ParseDLLOptions( Options
.dllFlags
))
164 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
171 /* Initialize everything */
172 if (!MAIN_EmulatorInit()) return 1;
174 /* Load kernel modules */
175 if (!LoadLibrary16( "KERNEL" )) return 1;
176 if (!LoadLibrary32A( "KERNEL32" )) return 1;
178 /* Create initial task */
179 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
180 hInstance
= NE_CreateInstance( pModule
, NULL
, TRUE
);
181 PROCESS_Current()->task
= TASK_Create( THREAD_Current(), pModule
, hInstance
, 0, FALSE
);
183 /* Initialize CALL32 routines */
184 /* This needs to be done just before switching stacks */
185 IF1632_CallLargeStack
= (int (*)(int (*func
)(), void *arg
))CALL32_Init();
187 /* Switch to initial task */
188 CURRENT_STACK16
->frame32
->retaddr
= (DWORD
)MAIN_EmulatorRun
;
189 TASK_StartTask( PROCESS_Current()->task
);
190 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );