Release 970120
[wine/multimedia.git] / loader / main.c
blobf78ee78bc09c82a913c89c7b075abed4c5a4df71
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 "comm.h"
17 #include "win.h"
18 #include "menu.h"
19 #include "atom.h"
20 #include "dialog.h"
21 #include "drive.h"
22 #include "queue.h"
23 #include "syscolor.h"
24 #include "sysmetrics.h"
25 #include "file.h"
26 #include "gdi.h"
27 #include "heap.h"
28 #include "keyboard.h"
29 #include "miscemu.h"
30 #include "neexe.h"
31 #include "options.h"
32 #include "spy.h"
33 #include "task.h"
34 #include "user.h"
35 #include "dce.h"
36 #include "shell.h"
37 #include "winproc.h"
38 #include "stddebug.h"
39 #include "debug.h"
41 #ifndef WINELIB
42 #include "debugger.h"
43 #endif
45 /* Winelib run-time flag */
46 #ifdef WINELIB
47 int __winelib = 1;
48 #else
49 int __winelib = 0;
50 #endif
52 HANDLE32 SystemHeap = 0;
53 HANDLE32 SegptrHeap = 0;
55 /***********************************************************************
56 * Main initialisation routine
58 int MAIN_Init(void)
60 extern BOOL32 RELAY_Init(void);
61 extern BOOL32 WIN16DRV_Init(void);
62 extern BOOL32 SIGNAL_Init(void);
63 extern BOOL32 WIDGETS_Init(void);
64 extern int KERN32_Init(void);
66 int queueSize;
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 #ifdef WINELIB
79 /* Create USER and GDI heap */
80 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
81 LocalInit( USER_HeapSel, 0, 0xffff );
82 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
83 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
84 #else
85 /* Initialize relay code */
86 if (!RELAY_Init()) return 0;
88 /* Create built-in modules */
89 if (!BUILTIN_Init()) return 0;
91 /* Initialize signal handling */
92 if (!SIGNAL_Init()) return 0;
94 /* Create the Win16 printer driver */
95 if (!WIN16DRV_Init()) return 0;
96 #endif /* WINELIB */
98 /* Initialise DOS drives */
99 if (!DRIVE_Init()) return 0;
101 /* Initialise DOS directories */
102 if (!DIR_Init()) return 0;
104 /* Initialize tasks */
105 if (!TASK_Init()) return 0;
107 /* Initialize communications */
108 COMM_Init();
110 /* registry initialisation */
111 SHELL_LoadRegistry();
113 /* Global atom table initialisation */
114 if (!ATOM_Init()) return 0;
116 /* GDI initialisation */
117 if (!GDI_Init()) return 0;
119 /* Initialize system colors and metrics*/
120 SYSMETRICS_Init();
121 SYSCOLOR_Init();
123 /* Create the DCEs */
124 DCE_Init();
126 /* Initialize keyboard */
127 if (!KEYBOARD_Init()) return 0;
129 /* Initialize window procedures */
130 if (!WINPROC_Init()) return 0;
132 /* Initialize built-in window classes */
133 if (!WIDGETS_Init()) return 0;
135 /* Initialize dialog manager */
136 if (!DIALOG_Init()) return 0;
138 /* Initialize menus */
139 if (!MENU_Init()) return 0;
141 /* Create desktop window */
142 if (!WIN_CreateDesktopWindow()) return 0;
144 /* Initialize message spying */
145 if (!SPY_Init()) return 0;
147 /* Initialize Win32 data structures */
148 if (!KERN32_Init()) return 0;
150 /* Create system message queue */
151 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
152 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
154 /* Set double click time */
155 SetDoubleClickTime( GetProfileInt32A("windows","DoubleClickSpeed",452) );
157 return 1;
161 #ifndef WINELIB
162 /**********************************************************************
163 * main
165 int main(int argc, char *argv[] )
167 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
168 extern char * DEBUG_argv0;
170 int i,loaded;
171 HINSTANCE16 handle;
174 * Save this so that the internal debugger can get a hold of it if
175 * it needs to.
177 DEBUG_argv0 = argv[0];
179 if (!MAIN_WineInit( &argc, argv )) return 1;
180 if (!MAIN_Init()) return 1;
182 loaded=0;
183 for (i = 1; i < argc; i++)
185 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
187 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
188 switch (handle)
190 case 2: fprintf( stderr, "file not found\n" ); break;
191 case 11: fprintf( stderr, "invalid exe file\n" ); break;
192 case 21: fprintf( stderr, "win32 executable\n" ); break;
193 default: fprintf( stderr, "error=%d\n", handle ); break;
195 return 1;
197 loaded++;
200 if (!loaded) { /* nothing loaded */
201 extern void MAIN_Usage(char*);
202 MAIN_Usage(argv[0]);
203 return 1;
206 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
208 Yield(); /* Start the first task */
209 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
210 return 0;
213 #endif /* #ifndef WINELIB */