Implemented toolbar multirow button layout.
[wine/testsucceed.git] / loader / main.c
blob3d8b03babffdf51228ae1ff5447c651e3fffcac4
1 /*
2 * Main initialization code
3 */
5 #include <stdlib.h>
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <string.h>
11 #include <errno.h>
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
14 #include "bitmap.h"
15 #include "comm.h"
16 #include "neexe.h"
17 #include "main.h"
18 #include "menu.h"
19 #include "message.h"
20 #include "dialog.h"
21 #include "drive.h"
22 #include "queue.h"
23 #include "sysmetrics.h"
24 #include "file.h"
25 #include "heap.h"
26 #include "keyboard.h"
27 #include "mouse.h"
28 #include "input.h"
29 #include "miscemu.h"
30 #include "options.h"
31 #include "process.h"
32 #include "spy.h"
33 #include "tweak.h"
34 #include "user.h"
35 #include "cursoricon.h"
36 #include "global.h"
37 #include "dce.h"
38 #include "shell.h"
39 #include "winproc.h"
40 #include "syslevel.h"
41 #include "services.h"
42 #include "thread.h"
43 #include "task.h"
44 #include "debug.h"
45 #include "psdrv.h"
46 #include "server.h"
47 #include "cursoricon.h"
48 #include "loadorder.h"
50 DEFAULT_DEBUG_CHANNEL(server)
52 int __winelib = 1; /* Winelib run-time flag */
54 /***********************************************************************
55 * Main initialisation routine
57 BOOL MAIN_MainInit(void)
59 /* Set server debug level */
60 /* To fool make_debug: TRACE(server) */
61 CLIENT_SetDebug( TRACE_ON(server) );
63 /* Initialize syslevel handling */
64 SYSLEVEL_Init();
66 /* Initialize signal handling */
67 if (!SIGNAL_Init()) return FALSE;
69 /* Initialize kernel services thread */
70 if (!SERVICE_Init()) return FALSE;
72 /* Load the configuration file */
73 if (!PROFILE_LoadWineIni()) return FALSE;
75 /* Initialize module loadorder */
76 if (!MODULE_InitLoadOrder()) return FALSE;
78 /* Initialize DOS memory */
79 if (!DOSMEM_Init(0)) return FALSE;
81 /* Initialise DOS drives */
82 if (!DRIVE_Init()) return FALSE;
84 /* Initialise DOS directories */
85 if (!DIR_Init()) return FALSE;
87 /* Initialize event handling */
88 if (!EVENT_Init()) return FALSE;
90 /* Initialize communications */
91 COMM_Init();
93 /* Initialize IO-port permissions */
94 IO_port_init();
96 /* registry initialisation */
97 SHELL_LoadRegistry();
99 /* Read DOS config.sys */
100 if (!DOSCONF_ReadConfig()) return FALSE;
102 return TRUE;
105 /***********************************************************************
106 * KERNEL initialisation routine
108 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
110 static BOOL initDone = FALSE;
112 HMODULE16 hModule;
114 if ( initDone ) return TRUE;
115 initDone = TRUE;
117 /* Initialize special KERNEL entry points */
118 hModule = GetModuleHandle16( "KERNEL" );
119 if ( hModule )
121 WORD cs, ds;
123 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
124 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
126 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
127 GET_CS(cs); GET_DS(ds);
128 NE_SetEntryPoint( hModule, 454, cs );
129 NE_SetEntryPoint( hModule, 455, ds );
131 /* Initialize KERNEL.THHOOK */
132 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
133 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
135 /* Initialize the real-mode selector entry points */
136 #define SET_ENTRY_POINT( num, addr ) \
137 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
138 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
139 FALSE, FALSE, FALSE, NULL ))
141 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
142 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
143 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
144 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
145 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
146 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
147 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
148 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
149 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
150 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
151 #undef SET_ENTRY_POINT
153 return TRUE;
156 /***********************************************************************
157 * GDI initialisation routine
159 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
161 NE_MODULE *pModule;
163 if ( GDI_HeapSel ) return TRUE;
165 /* Create GDI heap */
166 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
167 if ( pModule )
169 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
170 pModule->dgroup - 1)->hSeg );
172 else
174 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
175 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
178 if (!TWEAK_Init()) return FALSE;
180 /* GDI initialisation */
181 if(!GDI_Init()) return FALSE;
184 /* PSDRV initialization */
185 if(!PSDRV_Init()) return FALSE;
187 return TRUE;
190 /***********************************************************************
191 * USER initialisation routine
193 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
195 NE_MODULE *pModule;
196 int queueSize;
198 if ( USER_HeapSel ) return TRUE;
200 /* Create USER heap */
201 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
202 if ( pModule )
204 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
205 pModule->dgroup - 1)->hSeg );
207 else
209 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
210 LocalInit16( USER_HeapSel, 0, 0xffff );
213 /* Global atom table initialisation */
214 if (!ATOM_Init( USER_HeapSel )) return FALSE;
216 /* Initialize system colors and metrics*/
217 SYSMETRICS_Init();
218 SYSCOLOR_Init();
220 /* Create the DCEs */
221 DCE_Init();
223 /* Initialize timers */
224 if (!TIMER_Init()) return FALSE;
226 /* Initialize window procedures */
227 if (!WINPROC_Init()) return FALSE;
229 /* Initialize built-in window classes */
230 if (!WIDGETS_Init()) return FALSE;
232 /* Initialize dialog manager */
233 if (!DIALOG_Init()) return FALSE;
235 /* Initialize menus */
236 if (!MENU_Init()) return FALSE;
238 /* Initialize cursor/icons */
239 CURSORICON_Init();
241 /* Initialize message spying */
242 if (!SPY_Init()) return FALSE;
244 /* Check wine.conf for old/bad entries */
245 if (!TWEAK_CheckConfiguration()) return FALSE;
247 /* Create system message queue */
248 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
249 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
251 /* Set double click time */
252 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
254 /* Create task message queue for the initial task */
255 queueSize = GetProfileIntA( "windows", "DefaultQueueSize", 8 );
256 if (!SetMessageQueue( queueSize )) return FALSE;
258 /* Create desktop window */
259 if (!WIN_CreateDesktopWindow()) return FALSE;
261 /* Initialize keyboard driver */
262 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
264 /* Initialize mouse driver */
265 MOUSE_Enable( mouse_event );
267 return TRUE;
271 /***********************************************************************
272 * Winelib initialisation routine
274 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
276 WINE_MODREF *wm;
277 NE_MODULE *pModule;
278 OFSTRUCT ofs;
279 HMODULE16 hModule;
281 /* Create the initial process */
282 if (!PROCESS_Init()) return 0;
284 /* Parse command line arguments */
285 MAIN_WineInit( argc, argv );
287 /* Main initialization */
288 if (!MAIN_MainInit()) return 0;
290 /* Initialize KERNEL */
291 if (!LoadLibraryA( "KERNEL32" )) return 0;
293 /* Create and switch to initial task */
294 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
295 return 0;
296 PROCESS_Current()->exe_modref = wm;
298 strcpy( ofs.szPathName, wm->modname );
299 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
300 pModule = (NE_MODULE *)GlobalLock16( hModule );
301 pModule->flags = NE_FFLAGS_WIN32;
302 pModule->module32 = wm->module;
304 if (!TASK_Create( THREAD_Current(), pModule, 0, 0, FALSE )) return 0;
305 TASK_StartTask( PROCESS_Current()->task );
307 /* Initialize GDI and USER */
308 if (!LoadLibraryA( "GDI32.DLL" )) return 0;
309 if (!LoadLibraryA( "USER32.DLL" )) return 0;
311 return wm->module;