Fixed resizing bugs for windows with WS_THICKFRAME and WS_DLGFRAME
[wine/dcerpc.git] / loader / main.c
blob695f4c4a8af4bdc2831d9523f5629751f86cfd9a
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 "display.h"
30 #include "miscemu.h"
31 #include "options.h"
32 #include "process.h"
33 #include "spy.h"
34 #include "tweak.h"
35 #include "user.h"
36 #include "cursoricon.h"
37 #include "global.h"
38 #include "dce.h"
39 #include "shell.h"
40 #include "win.h"
41 #include "winproc.h"
42 #include "syslevel.h"
43 #include "services.h"
44 #include "winsock.h"
45 #include "thread.h"
46 #include "task.h"
47 #include "debugtools.h"
48 #include "psdrv.h"
49 #include "win16drv.h"
50 #include "callback.h"
51 #include "server.h"
52 #include "cursoricon.h"
53 #include "loadorder.h"
55 DEFAULT_DEBUG_CHANNEL(server)
57 int __winelib = 1; /* Winelib run-time flag */
59 /***********************************************************************
60 * Main initialisation routine
62 BOOL MAIN_MainInit(void)
64 /* Set server debug level */
65 CLIENT_SetDebug( TRACE_ON(server) );
67 /* Initialize syslevel handling */
68 SYSLEVEL_Init();
70 /* Initialize signal handling */
71 if (!SIGNAL_Init()) return FALSE;
73 /* Load the configuration file */
74 if (!PROFILE_LoadWineIni()) return FALSE;
76 /* Initialize module loadorder */
77 if (!MODULE_InitLoadOrder()) return FALSE;
79 /* Initialize DOS memory */
80 if (!DOSMEM_Init(0)) return FALSE;
82 /* Initialise DOS drives */
83 if (!DRIVE_Init()) return FALSE;
85 /* Initialise DOS directories */
86 if (!DIR_Init()) return FALSE;
88 /* Initialize event handling */
89 if (!EVENT_Init()) return FALSE;
91 /* Initialise WINSOCK handling */
92 if (!WINSOCK_Init()) return FALSE;
94 /* Initialize communications */
95 COMM_Init();
97 /* Initialize IO-port permissions */
98 IO_port_init();
100 /* registry initialisation */
101 SHELL_LoadRegistry();
103 /* Read DOS config.sys */
104 if (!DOSCONF_ReadConfig()) return FALSE;
106 /* Initialize relay code */
107 if (!RELAY_Init()) return FALSE;
109 return TRUE;
112 /***********************************************************************
113 * KERNEL initialisation routine
115 BOOL WINAPI MAIN_KernelInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
117 static BOOL initDone = FALSE;
119 HMODULE16 hModule;
121 if ( initDone ) return TRUE;
122 initDone = TRUE;
124 /* Initialize special KERNEL entry points */
125 hModule = GetModuleHandle16( "KERNEL" );
126 if ( hModule )
128 WORD cs, ds;
130 /* Initialize KERNEL.178 (__WINFLAGS) with the correct flags value */
131 NE_SetEntryPoint( hModule, 178, GetWinFlags16() );
133 /* Initialize KERNEL.454/455 (__FLATCS/__FLATDS) */
134 GET_CS(cs); GET_DS(ds);
135 NE_SetEntryPoint( hModule, 454, cs );
136 NE_SetEntryPoint( hModule, 455, ds );
138 /* Initialize KERNEL.THHOOK */
139 TASK_InstallTHHook((THHOOK *)PTR_SEG_TO_LIN(
140 (SEGPTR)NE_GetEntryPoint( hModule, 332 )));
142 /* Initialize the real-mode selector entry points */
143 #define SET_ENTRY_POINT( num, addr ) \
144 NE_SetEntryPoint( hModule, (num), GLOBAL_CreateBlock( GMEM_FIXED, \
145 DOSMEM_MapDosToLinear(addr), 0x10000, hModule, \
146 FALSE, FALSE, FALSE, NULL ))
148 SET_ENTRY_POINT( 183, 0x00000 ); /* KERNEL.183: __0000H */
149 SET_ENTRY_POINT( 174, 0xa0000 ); /* KERNEL.174: __A000H */
150 SET_ENTRY_POINT( 181, 0xb0000 ); /* KERNEL.181: __B000H */
151 SET_ENTRY_POINT( 182, 0xb8000 ); /* KERNEL.182: __B800H */
152 SET_ENTRY_POINT( 195, 0xc0000 ); /* KERNEL.195: __C000H */
153 SET_ENTRY_POINT( 179, 0xd0000 ); /* KERNEL.179: __D000H */
154 SET_ENTRY_POINT( 190, 0xe0000 ); /* KERNEL.190: __E000H */
155 NE_SetEntryPoint( hModule, 173, DOSMEM_BiosSysSeg ); /* KERNEL.173: __ROMBIOS */
156 NE_SetEntryPoint( hModule, 193, DOSMEM_BiosDataSeg ); /* KERNEL.193: __0040H */
157 NE_SetEntryPoint( hModule, 194, DOSMEM_BiosSysSeg ); /* KERNEL.194: __F000H */
158 #undef SET_ENTRY_POINT
160 return TRUE;
163 /***********************************************************************
164 * GDI initialisation routine
166 BOOL WINAPI MAIN_GdiInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
168 NE_MODULE *pModule;
170 if ( GDI_HeapSel ) return TRUE;
172 /* Create GDI heap */
173 pModule = NE_GetPtr( GetModuleHandle16( "GDI" ) );
174 if ( pModule )
176 GDI_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
177 pModule->dgroup - 1)->hSeg );
179 else
181 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
182 LocalInit16( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
185 if (!TWEAK_Init()) return FALSE;
187 /* GDI initialisation */
188 if(!GDI_Init()) return FALSE;
190 /* Create the Win16 printer driver */
191 if (!WIN16DRV_Init()) return FALSE;
193 /* PSDRV initialization */
194 if(!PSDRV_Init()) return FALSE;
196 return TRUE;
199 /***********************************************************************
200 * USER initialisation routine
202 BOOL WINAPI MAIN_UserInit(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
204 NE_MODULE *pModule;
205 int queueSize;
207 if ( USER_HeapSel ) return TRUE;
209 /* Create USER heap */
210 pModule = NE_GetPtr( GetModuleHandle16( "USER" ) );
211 if ( pModule )
213 USER_HeapSel = GlobalHandleToSel16( (NE_SEG_TABLE( pModule ) +
214 pModule->dgroup - 1)->hSeg );
216 else
218 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
219 LocalInit16( USER_HeapSel, 0, 0xffff );
222 /* Global atom table initialisation */
223 if (!ATOM_Init( USER_HeapSel )) return FALSE;
225 /* Initialize window handling (critical section) */
226 WIN_Init();
228 /* Initialize system colors and metrics*/
229 SYSMETRICS_Init();
230 SYSCOLOR_Init();
232 /* Create the DCEs */
233 DCE_Init();
235 /* Initialize timers */
236 if (!TIMER_Init()) return FALSE;
238 /* Initialize window procedures */
239 if (!WINPROC_Init()) return FALSE;
241 /* Initialize built-in window classes */
242 if (!WIDGETS_Init()) return FALSE;
244 /* Initialize dialog manager */
245 if (!DIALOG_Init()) return FALSE;
247 /* Initialize menus */
248 if (!MENU_Init()) return FALSE;
250 /* Initialize cursor/icons */
251 CURSORICON_Init();
253 /* Initialize message spying */
254 if (!SPY_Init()) return FALSE;
256 /* Check wine.conf for old/bad entries */
257 if (!TWEAK_CheckConfiguration()) return FALSE;
259 /* Create system message queue */
260 queueSize = GetProfileIntA( "windows", "TypeAhead", 120 );
261 if (!QUEUE_CreateSysMsgQueue( queueSize )) return FALSE;
263 /* Set double click time */
264 SetDoubleClickTime( GetProfileIntA("windows","DoubleClickSpeed",452) );
266 /* Create message queue of initial thread */
267 InitThreadInput16( 0, 0 );
269 /* Create desktop window */
270 if (!WIN_CreateDesktopWindow()) return FALSE;
272 /* Initialize keyboard driver */
273 KEYBOARD_Enable( keybd_event, InputKeyStateTable );
275 /* Initialize mouse driver */
276 MOUSE_Enable( mouse_event );
278 /* Start processing X events */
279 UserRepaintDisable16( FALSE );
281 return TRUE;
285 /***********************************************************************
286 * Winelib initialisation routine
288 HINSTANCE MAIN_WinelibInit( int *argc, char *argv[] )
290 WINE_MODREF *wm;
291 NE_MODULE *pModule;
292 OFSTRUCT ofs;
293 HMODULE16 hModule;
295 /* Create the initial process */
296 if (!PROCESS_Init()) return 0;
298 /* Parse command line arguments */
299 MAIN_WineInit( argc, argv );
301 /* Main initialization */
302 if (!MAIN_MainInit()) return 0;
304 /* Initialize KERNEL */
305 if (!LoadLibrary16( "KERNEL" )) return 0;
306 if (!LoadLibraryA( "KERNEL32" )) return 0;
308 /* Create and switch to initial task */
309 if (!(wm = ELF_CreateDummyModule( argv[0], argv[0] )))
310 return 0;
311 PROCESS_Current()->exe_modref = wm;
313 strcpy( ofs.szPathName, wm->modname );
314 if ((hModule = MODULE_CreateDummyModule( &ofs, NULL )) < 32) return 0;
315 pModule = (NE_MODULE *)GlobalLock16( hModule );
316 pModule->flags = NE_FFLAGS_WIN32;
317 pModule->module32 = wm->module;
319 if (!TASK_Create( pModule, FALSE )) return 0;
321 /* Load system DLLs into the initial process (and initialize them) */
322 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
323 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
324 ExitProcess( 1 );
326 /* Get pointers to USER routines called by KERNEL */
327 THUNK_InitCallout();
329 return wm->module;
332 /***********************************************************************
333 * ExitKernel16 (KERNEL.2)
335 * Clean-up everything and exit the Wine process.
338 void WINAPI ExitKernel16( void )
340 /* Do the clean-up stuff */
342 WriteOutProfiles16();
343 SHELL_SaveRegistry();
345 TerminateProcess( GetCurrentProcess(), 0 );