2 * Emulator initialisation code
18 #include "stackframe.h"
22 static char **MAIN_argv
;
24 /***********************************************************************
25 * Emulator initialisation
27 BOOL32
MAIN_EmulatorInit(void)
29 /* Main initialization */
30 if (!MAIN_MainInit()) return FALSE
;
32 /* Initialize relay code */
33 if (!RELAY_Init()) return FALSE
;
35 /* Initialize signal handling */
36 if (!SIGNAL_InitEmulator()) return FALSE
;
38 /* Create the Win16 printer driver */
39 if (!WIN16DRV_Init()) return FALSE
;
44 typedef BOOL32 (*WINAPI tGetMessage
)(MSG32
* lpmsg
,HWND32 hwnd
,UINT32 min
,UINT32 max
);
45 typedef BOOL32 (*WINAPI tTranslateMessage
)(const MSG32
* msg
);
46 typedef LONG (*WINAPI tDispatchMessage
)( const MSG32
* msg
);
48 /***********************************************************************
49 * Main loop of initial task
51 void MAIN_EmulatorRun( void )
53 char startProg
[256], defProg
[256];
57 tGetMessage pGetMessage
;
58 tTranslateMessage pTranslateMessage
;
59 tDispatchMessage pDispatchMessage
;
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
;
81 /* Abort if no executable on command line */
84 MAIN_Usage(MAIN_argv
[0]);
88 /* Load and run executables given on command line */
89 for (i
= 1; i
< MAIN_argc
; i
++)
90 if ((handle
= WinExec32( MAIN_argv
[i
], SW_SHOWNORMAL
)) < 32)
92 MSG("wine: can't exec '%s': ", MAIN_argv
[i
]);
95 case 2: MSG("file not found\n" ); break;
96 case 11: MSG("invalid exe file\n" ); break;
97 default: MSG("error=%d\n", handle
); break;
101 if (GetNumTasks() <= 1)
103 MSG("wine: no executable file found.\n" );
108 /* Start message loop for desktop window */
110 hModule
= GetModuleHandle32A( "USER32" );
111 pGetMessage
= (tGetMessage
)GetProcAddress32( hModule
, "GetMessageA" );
112 pTranslateMessage
= (tTranslateMessage
)GetProcAddress32( hModule
, "TranslateMessage" );
113 pDispatchMessage
= (tDispatchMessage
)GetProcAddress32( hModule
, "DispatchMessageA" );
115 assert( pGetMessage
);
116 assert( pTranslateMessage
);
117 assert( pDispatchMessage
);
119 while ( GetNumTasks() > 1 && pGetMessage( &msg
, 0, 0, 0 ) )
121 pTranslateMessage( &msg
);
122 pDispatchMessage( &msg
);
129 /**********************************************************************
132 int main( int argc
, char *argv
[] )
135 HINSTANCE16 hInstance
;
136 extern char * DEBUG_argv0
;
138 __winelib
= 0; /* First of all, clear the Winelib flag */
141 * Save this so that the internal debugger can get a hold of it if
144 DEBUG_argv0
= argv
[0];
146 /* Create the initial process */
147 if (!PROCESS_Init()) return FALSE
;
149 /* Parse command-line */
150 if (!MAIN_WineInit( &argc
, argv
)) return 1;
151 MAIN_argc
= argc
; MAIN_argv
= argv
;
153 /* Handle -dll option (hack) */
154 if (Options
.dllFlags
)
156 if (!BUILTIN_ParseDLLOptions( Options
.dllFlags
))
158 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
165 /* Set up debugger callback routines */
166 ctx_debug_call
= ctx_debug
;
168 TASK_AddTaskEntryBreakpoint
= DEBUG_AddTaskEntryBreakpoint
;
170 /* Initialize everything */
171 if (!MAIN_EmulatorInit()) return 1;
173 /* Load kernel modules */
174 if (!LoadLibrary16( "KERNEL" )) return 1;
175 if (!LoadLibrary32A( "KERNEL32" )) return 1;
177 /* Create initial task */
178 if ( !(pModule
= NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
179 hInstance
= NE_CreateInstance( pModule
, NULL
, TRUE
);
180 PROCESS_Current()->task
= TASK_Create( THREAD_Current(), pModule
, hInstance
, 0, FALSE
);
182 /* Initialize CALL32 routines */
183 /* This needs to be done just before switching stacks */
184 IF1632_CallLargeStack
= (int (*)(int (*func
)(), void *arg
))CALL32_Init();
186 /* Switch to initial task */
187 CURRENT_STACK16
->frame32
->retaddr
= (DWORD
)MAIN_EmulatorRun
;
188 TASK_StartTask( PROCESS_Current()->task
);
189 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );