Release 970824
[wine/multimedia.git] / loader / main.c
blobb3e4f8b7b4098c38896ca715f51bf9ad0c158801
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 EVENT_Init(void);
58 extern BOOL32 RELAY_Init(void);
59 extern BOOL32 WIN16DRV_Init(void);
60 extern BOOL32 VIRTUAL_Init(void);
61 extern BOOL32 WIDGETS_Init(void);
63 int queueSize;
65 /* Initialize virtual memory management */
66 if (!VIRTUAL_Init()) return 0;
68 /* Create the system and SEGPTR heaps */
69 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
70 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
72 /* Load the configuration file */
73 if (!PROFILE_LoadWineIni()) return 0;
75 /* Initialize DOS memory */
76 if (!DOSMEM_Init()) return 0;
78 /* Initialize signal handling */
79 if (!SIGNAL_Init()) return 0;
81 /* Initialize event handling */
82 if (!EVENT_Init()) return 0;
84 #ifdef WINELIB
85 /* Create USER and GDI heap */
86 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
87 LocalInit( USER_HeapSel, 0, 0xffff );
88 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
89 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
90 #else
91 /* Initialize relay code */
92 if (!RELAY_Init()) return 0;
94 /* Create built-in modules */
95 if (!BUILTIN_Init()) return 0;
97 /* Initialize signal handling */
98 if (!SIGNAL_InitEmulator()) return 0;
100 /* Create the Win16 printer driver */
101 if (!WIN16DRV_Init()) return 0;
102 #endif /* WINELIB */
104 /* Initialize Wine tweaks */
105 if (!TWEAK_Init()) return 0;
107 /* Initialize OEM Bitmaps */
108 if (!OBM_Init()) return 0;
110 /* Initialise DOS drives */
111 if (!DRIVE_Init()) return 0;
113 /* Initialise DOS directories */
114 if (!DIR_Init()) return 0;
116 /* Initialize tasks */
117 if (!TASK_Init()) return 0;
119 /* Initialize communications */
120 COMM_Init();
122 /* Initialize IO-port permissions */
123 IO_port_init();
125 /* registry initialisation */
126 SHELL_LoadRegistry();
128 /* Global atom table initialisation */
129 if (!ATOM_Init()) return 0;
131 /* GDI initialisation */
132 if (!GDI_Init()) return 0;
134 /* Initialize system colors and metrics*/
135 SYSMETRICS_Init();
136 SYSCOLOR_Init();
138 /* Create the DCEs */
139 DCE_Init();
141 /* Initialize keyboard */
142 if (!KEYBOARD_Init()) return 0;
144 /* Initialize window procedures */
145 if (!WINPROC_Init()) return 0;
147 /* Initialize built-in window classes */
148 if (!WIDGETS_Init()) return 0;
150 /* Initialize dialog manager */
151 if (!DIALOG_Init()) return 0;
153 /* Initialize menus */
154 if (!MENU_Init()) return 0;
156 /* Create desktop window */
157 if (!WIN_CreateDesktopWindow()) return 0;
159 /* Initialize message spying */
160 if (!SPY_Init()) return 0;
162 /* Check wine.conf for old/bad entries */
163 if (!TWEAK_CheckConfiguration()) return 0;
165 /* Create system message queue */
166 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
167 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
169 /* Set double click time */
170 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
172 return 1;
176 #ifndef WINELIB
177 /**********************************************************************
178 * main
180 int main(int argc, char *argv[] )
182 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
183 extern char * DEBUG_argv0;
185 int i,loaded;
186 HINSTANCE16 handle;
188 __winelib = 0; /* First of all, clear the Winelib flag */
191 * Save this so that the internal debugger can get a hold of it if
192 * it needs to.
194 DEBUG_argv0 = argv[0];
196 if (!MAIN_WineInit( &argc, argv )) return 1;
197 if (!MAIN_Init()) return 1;
199 loaded=0;
200 for (i = 1; i < argc; i++)
202 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
204 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
205 switch (handle)
207 case 2: fprintf( stderr, "file not found\n" ); break;
208 case 11: fprintf( stderr, "invalid exe file\n" ); break;
209 case 21: fprintf( stderr, "win32 executable\n" ); break;
210 default: fprintf( stderr, "error=%d\n", handle ); break;
212 return 1;
214 loaded++;
217 if (!loaded) { /* nothing loaded */
218 extern void MAIN_Usage(char*);
219 MAIN_Usage(argv[0]);
220 return 1;
223 if (!GetNumTasks())
225 fprintf( stderr, "wine: no executable file found.\n" );
226 return 0;
229 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
231 Yield(); /* Start the first task */
232 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
233 return 0;
236 #endif /* #ifndef WINELIB */