Release 970804
[wine/multimedia.git] / loader / main.c
blob4ac8026e3840ac8671e6f109a81a659798c77d42
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 "file.h"
27 #include "gdi.h"
28 #include "heap.h"
29 #include "keyboard.h"
30 #include "miscemu.h"
31 #include "neexe.h"
32 #include "options.h"
33 #include "spy.h"
34 #include "task.h"
35 #include "tweak.h"
36 #include "user.h"
37 #include "dce.h"
38 #include "shell.h"
39 #include "winproc.h"
40 #include "stddebug.h"
41 #include "debug.h"
43 #ifndef WINELIB
44 #include "debugger.h"
45 #endif
47 int __winelib = 1; /* Winelib run-time flag */
49 HANDLE32 SystemHeap = 0;
50 HANDLE32 SegptrHeap = 0;
52 /***********************************************************************
53 * Main initialisation routine
55 int MAIN_Init(void)
57 extern BOOL32 RELAY_Init(void);
58 extern BOOL32 WIN16DRV_Init(void);
59 extern BOOL32 VIRTUAL_Init(void);
60 extern BOOL32 WIDGETS_Init(void);
62 int queueSize;
64 /* Initialize virtual memory management */
65 if (!VIRTUAL_Init()) return 0;
67 /* Create the system and SEGPTR heaps */
68 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
69 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
71 /* Load the configuration file */
72 if (!PROFILE_LoadWineIni()) return 0;
74 /* Initialize DOS memory */
75 if (!DOSMEM_Init()) return 0;
77 /* Initialize signal handling */
78 if (!SIGNAL_Init()) return 0;
80 #ifdef WINELIB
81 /* Create USER and GDI heap */
82 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
83 LocalInit( USER_HeapSel, 0, 0xffff );
84 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
85 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
86 #else
87 /* Initialize relay code */
88 if (!RELAY_Init()) return 0;
90 /* Create built-in modules */
91 if (!BUILTIN_Init()) return 0;
93 /* Initialize signal handling */
94 if (!SIGNAL_InitEmulator()) return 0;
96 /* Create the Win16 printer driver */
97 if (!WIN16DRV_Init()) return 0;
98 #endif /* WINELIB */
100 /* Initialize Wine tweaks */
101 if (!TWEAK_Init()) return 0;
103 /* Initialize OEM Bitmaps */
104 if (!OBM_Init()) return 0;
106 /* Initialise DOS drives */
107 if (!DRIVE_Init()) return 0;
109 /* Initialise DOS directories */
110 if (!DIR_Init()) return 0;
112 /* Initialize tasks */
113 if (!TASK_Init()) return 0;
115 /* Initialize communications */
116 COMM_Init();
118 /* Initialize IO-port permissions */
119 IO_port_init();
121 /* registry initialisation */
122 SHELL_LoadRegistry();
124 /* Global atom table initialisation */
125 if (!ATOM_Init()) return 0;
127 /* GDI initialisation */
128 if (!GDI_Init()) return 0;
130 /* Initialize system colors and metrics*/
131 SYSMETRICS_Init();
132 SYSCOLOR_Init();
134 /* Create the DCEs */
135 DCE_Init();
137 /* Initialize keyboard */
138 if (!KEYBOARD_Init()) return 0;
140 /* Initialize window procedures */
141 if (!WINPROC_Init()) return 0;
143 /* Initialize built-in window classes */
144 if (!WIDGETS_Init()) return 0;
146 /* Initialize dialog manager */
147 if (!DIALOG_Init()) return 0;
149 /* Initialize menus */
150 if (!MENU_Init()) return 0;
152 /* Create desktop window */
153 if (!WIN_CreateDesktopWindow()) return 0;
155 /* Initialize message spying */
156 if (!SPY_Init()) return 0;
158 /* Check wine.conf for old/bad entries */
159 if (!TWEAK_CheckConfiguration()) return 0;
161 /* Create system message queue */
162 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
163 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
165 /* Set double click time */
166 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
168 return 1;
172 #ifndef WINELIB
173 /**********************************************************************
174 * main
176 int main(int argc, char *argv[] )
178 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
179 extern char * DEBUG_argv0;
181 int i,loaded;
182 HINSTANCE16 handle;
184 __winelib = 0; /* First of all, clear the Winelib flag */
187 * Save this so that the internal debugger can get a hold of it if
188 * it needs to.
190 DEBUG_argv0 = argv[0];
192 if (!MAIN_WineInit( &argc, argv )) return 1;
193 if (!MAIN_Init()) return 1;
195 loaded=0;
196 for (i = 1; i < argc; i++)
198 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
200 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
201 switch (handle)
203 case 2: fprintf( stderr, "file not found\n" ); break;
204 case 11: fprintf( stderr, "invalid exe file\n" ); break;
205 case 21: fprintf( stderr, "win32 executable\n" ); break;
206 default: fprintf( stderr, "error=%d\n", handle ); break;
208 return 1;
210 loaded++;
213 if (!loaded) { /* nothing loaded */
214 extern void MAIN_Usage(char*);
215 MAIN_Usage(argv[0]);
216 return 1;
219 if (!GetNumTasks())
221 fprintf( stderr, "wine: no executable file found.\n" );
222 return 0;
225 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
227 Yield(); /* Start the first task */
228 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
229 return 0;
232 #endif /* #ifndef WINELIB */