Release 971012
[wine/multimedia.git] / loader / main.c
blob944ffb724a23ccd2bfc49aa3bb72c554d75eb915
1 /*
2 static char RCSId[] = "$Id: wine.c,v 1.2 1993/07/04 04:04:21 root Exp root $";
3 static char Copyright[] = "Copyright Robert J. Amstadt, 1993";
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 #include "windows.h"
14 #include "module.h"
15 #include "selectors.h"
16 #include "bitmap.h"
17 #include "comm.h"
18 #include "win.h"
19 #include "menu.h"
20 #include "atom.h"
21 #include "dialog.h"
22 #include "drive.h"
23 #include "queue.h"
24 #include "syscolor.h"
25 #include "sysmetrics.h"
26 #include "callback.h"
27 #include "file.h"
28 #include "gdi.h"
29 #include "heap.h"
30 #include "keyboard.h"
31 #include "miscemu.h"
32 #include "neexe.h"
33 #include "options.h"
34 #include "spy.h"
35 #include "task.h"
36 #include "tweak.h"
37 #include "user.h"
38 #include "dce.h"
39 #include "shell.h"
40 #include "winproc.h"
41 #include "stddebug.h"
42 #include "debug.h"
44 #ifndef WINELIB
45 #include "debugger.h"
46 #endif
48 int __winelib = 1; /* Winelib run-time flag */
50 HANDLE32 SystemHeap = 0;
51 HANDLE32 SegptrHeap = 0;
53 /***********************************************************************
54 * Main initialisation routine
56 int MAIN_Init(void)
58 extern BOOL32 EVENT_Init(void);
59 extern BOOL32 RELAY_Init(void);
60 extern BOOL32 WIN16DRV_Init(void);
61 extern BOOL32 VIRTUAL_Init(void);
62 extern BOOL32 WIDGETS_Init(void);
64 int queueSize;
66 /* Initialize virtual memory management */
67 if (!VIRTUAL_Init()) return 0;
69 /* Create the system and SEGPTR heaps */
70 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
71 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
73 /* Load the configuration file */
74 if (!PROFILE_LoadWineIni()) return 0;
76 /* Initialize DOS memory */
77 if (!DOSMEM_Init()) return 0;
79 /* Initialize signal handling */
80 if (!SIGNAL_Init()) return 0;
82 /* Initialize event handling */
83 if (!EVENT_Init()) return 0;
85 #ifdef WINELIB
86 /* Create USER and GDI heap */
87 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
88 LocalInit( USER_HeapSel, 0, 0xffff );
89 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
90 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
91 #else
92 /* Initialize relay code */
93 if (!RELAY_Init()) return 0;
95 /* Create built-in modules */
96 if (!BUILTIN_Init()) return 0;
98 /* Initialize signal handling */
99 if (!SIGNAL_InitEmulator()) return 0;
101 /* Create the Win16 printer driver */
102 if (!WIN16DRV_Init()) return 0;
103 #endif /* WINELIB */
105 /* Initialize Wine tweaks */
106 if (!TWEAK_Init()) return 0;
108 /* Initialize OEM Bitmaps */
109 if (!OBM_Init()) return 0;
111 /* Initialise DOS drives */
112 if (!DRIVE_Init()) return 0;
114 /* Initialise DOS directories */
115 if (!DIR_Init()) return 0;
117 /* Initialize tasks */
118 if (!TASK_Init()) return 0;
120 /* Initialize communications */
121 COMM_Init();
123 /* Initialize IO-port permissions */
124 IO_port_init();
126 /* registry initialisation */
127 SHELL_LoadRegistry();
129 /* Global atom table initialisation */
130 if (!ATOM_Init()) return 0;
132 /* GDI initialisation */
133 if (!GDI_Init()) return 0;
135 /* Initialize system colors and metrics*/
136 SYSMETRICS_Init();
137 SYSCOLOR_Init();
139 /* Create the DCEs */
140 DCE_Init();
142 /* Initialize keyboard */
143 if (!KEYBOARD_Init()) return 0;
145 /* Initialize window procedures */
146 if (!WINPROC_Init()) return 0;
148 /* Initialize built-in window classes */
149 if (!WIDGETS_Init()) return 0;
151 /* Initialize dialog manager */
152 if (!DIALOG_Init()) return 0;
154 /* Initialize menus */
155 if (!MENU_Init()) return 0;
157 /* Create desktop window */
158 if (!WIN_CreateDesktopWindow()) return 0;
160 /* Initialize message spying */
161 if (!SPY_Init()) return 0;
163 /* Check wine.conf for old/bad entries */
164 if (!TWEAK_CheckConfiguration()) return 0;
166 /* Create system message queue */
167 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
168 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
170 /* Set double click time */
171 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
173 return 1;
177 #ifndef WINELIB
178 /**********************************************************************
179 * main
181 int main(int argc, char *argv[] )
183 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
184 extern void *CALL32_Init(void);
185 extern char * DEBUG_argv0;
187 int i,loaded;
188 HINSTANCE32 handle;
190 __winelib = 0; /* First of all, clear the Winelib flag */
193 * Save this so that the internal debugger can get a hold of it if
194 * it needs to.
196 DEBUG_argv0 = argv[0];
198 if (!MAIN_WineInit( &argc, argv )) return 1;
199 if (!MAIN_Init()) return 1;
201 /* Initialize CALL32 routines */
202 /* This needs to be done just before task-switching starts */
203 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
205 loaded=0;
206 for (i = 1; i < argc; i++)
208 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
210 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
211 switch (handle)
213 case 2: fprintf( stderr, "file not found\n" ); break;
214 case 11: fprintf( stderr, "invalid exe file\n" ); break;
215 case 21: fprintf( stderr, "win32 executable\n" ); break;
216 default: fprintf( stderr, "error=%d\n", handle ); break;
218 return 1;
220 loaded++;
223 if (!loaded) { /* nothing loaded */
224 extern void MAIN_Usage(char*);
225 MAIN_Usage(argv[0]);
226 return 1;
229 if (!GetNumTasks())
231 fprintf( stderr, "wine: no executable file found.\n" );
232 return 0;
235 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
237 Yield(); /* Start the first task */
238 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
239 return 0;
242 #endif /* #ifndef WINELIB */