Release 970215
[wine/multimedia.git] / loader / main.c
blob64854d6c1cc00dc8e3b0fead7d16f44ba7f5c832
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);
65 int queueSize;
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 #ifdef WINELIB
78 /* Create USER and GDI heap */
79 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
80 LocalInit( USER_HeapSel, 0, 0xffff );
81 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
82 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
83 #else
84 /* Initialize relay code */
85 if (!RELAY_Init()) return 0;
87 /* Create built-in modules */
88 if (!BUILTIN_Init()) return 0;
90 /* Initialize signal handling */
91 if (!SIGNAL_Init()) return 0;
93 /* Create the Win16 printer driver */
94 if (!WIN16DRV_Init()) return 0;
95 #endif /* WINELIB */
97 /* Initialise DOS drives */
98 if (!DRIVE_Init()) return 0;
100 /* Initialise DOS directories */
101 if (!DIR_Init()) return 0;
103 /* Initialize tasks */
104 if (!TASK_Init()) return 0;
106 /* Initialize communications */
107 COMM_Init();
109 /* registry initialisation */
110 SHELL_LoadRegistry();
112 /* Global atom table initialisation */
113 if (!ATOM_Init()) return 0;
115 /* GDI initialisation */
116 if (!GDI_Init()) return 0;
118 /* Initialize system colors and metrics*/
119 SYSMETRICS_Init();
120 SYSCOLOR_Init();
122 /* Create the DCEs */
123 DCE_Init();
125 /* Initialize keyboard */
126 if (!KEYBOARD_Init()) return 0;
128 /* Initialize window procedures */
129 if (!WINPROC_Init()) return 0;
131 /* Initialize built-in window classes */
132 if (!WIDGETS_Init()) return 0;
134 /* Initialize dialog manager */
135 if (!DIALOG_Init()) return 0;
137 /* Initialize menus */
138 if (!MENU_Init()) return 0;
140 /* Create desktop window */
141 if (!WIN_CreateDesktopWindow()) return 0;
143 /* Initialize message spying */
144 if (!SPY_Init()) return 0;
146 /* Create system message queue */
147 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
148 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
150 /* Set double click time */
151 SetDoubleClickTime32( GetProfileInt32A("windows","DoubleClickSpeed",452) );
153 return 1;
157 #ifndef WINELIB
158 /**********************************************************************
159 * main
161 int main(int argc, char *argv[] )
163 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
164 extern char * DEBUG_argv0;
166 int i,loaded;
167 HINSTANCE16 handle;
170 * Save this so that the internal debugger can get a hold of it if
171 * it needs to.
173 DEBUG_argv0 = argv[0];
175 if (!MAIN_WineInit( &argc, argv )) return 1;
176 if (!MAIN_Init()) return 1;
178 loaded=0;
179 for (i = 1; i < argc; i++)
181 if ((handle = WinExec32( argv[i], SW_SHOWNORMAL )) < 32)
183 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
184 switch (handle)
186 case 2: fprintf( stderr, "file not found\n" ); break;
187 case 11: fprintf( stderr, "invalid exe file\n" ); break;
188 case 21: fprintf( stderr, "win32 executable\n" ); break;
189 default: fprintf( stderr, "error=%d\n", handle ); break;
191 return 1;
193 loaded++;
196 if (!loaded) { /* nothing loaded */
197 extern void MAIN_Usage(char*);
198 MAIN_Usage(argv[0]);
199 return 1;
202 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
204 Yield(); /* Start the first task */
205 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
206 return 0;
209 #endif /* #ifndef WINELIB */