Release 961222
[wine/multimedia.git] / loader / main.c
blobb14f6914173549acdf8ba8f061ccf184dde883f9
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 "directory.h"
22 #include "drive.h"
23 #include "queue.h"
24 #include "syscolor.h"
25 #include "sysmetrics.h"
26 #include "gdi.h"
27 #include "heap.h"
28 #include "debugger.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 "pe_image.h"
37 #include "shell.h"
38 #include "winproc.h"
39 #include "stddebug.h"
40 #include "debug.h"
43 /* Winelib run-time flag */
44 #ifdef WINELIB
45 int __winelib = 1;
46 #else
47 int __winelib = 0;
48 #endif
50 HANDLE32 SystemHeap = 0;
51 HANDLE32 SegptrHeap = 0;
53 /***********************************************************************
54 * Main initialisation routine
56 int MAIN_Init(void)
58 extern BOOL32 RELAY_Init(void);
59 extern BOOL32 WIN16DRV_Init(void);
60 extern BOOL32 SIGNAL_Init(void);
61 extern BOOL32 WIDGETS_Init(void);
62 extern int KERN32_Init(void);
64 int queueSize;
66 /* Create the system and SEGPTR heaps */
67 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
68 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
70 /* Load the configuration file */
71 if (!PROFILE_LoadWineIni()) return 0;
73 #ifdef WINELIB
74 /* Create USER and GDI heap */
75 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
76 LocalInit( USER_HeapSel, 0, 0xffff );
77 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
78 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
79 #else
80 /* Initialize relay code */
81 if (!RELAY_Init()) return 0;
83 /* Create built-in modules */
84 if (!BUILTIN_Init()) return 0;
86 /* Initialize interrupt vectors */
87 if (!INT_Init()) return 0;
89 /* Initialize DOS memory */
90 if (!DOSMEM_Init()) return 0;
92 /* Initialize the DOS interrupt */
93 if (!INT21_Init()) return 0;
95 /* Initialize signal handling */
96 if (!SIGNAL_Init()) return 0;
98 /* Create the Win16 printer driver */
99 if (!WIN16DRV_Init()) return 0;
100 #endif /* WINELIB */
102 /* Initialise DOS drives */
103 if (!DRIVE_Init()) return 0;
105 /* Initialise DOS directories */
106 if (!DIR_Init()) return 0;
108 /* Initialize tasks */
109 if (!TASK_Init()) return 0;
111 /* Initialize communications */
112 COMM_Init();
114 /* registry initialisation */
115 SHELL_LoadRegistry();
117 /* Global atom table initialisation */
118 if (!ATOM_Init()) return 0;
120 /* GDI initialisation */
121 if (!GDI_Init()) return 0;
123 /* Initialize system colors and metrics*/
124 SYSMETRICS_Init();
125 SYSCOLOR_Init();
127 /* Create the DCEs */
128 DCE_Init();
130 /* Initialize window procedures */
131 if (!WINPROC_Init()) return 0;
133 /* Initialize built-in window classes */
134 if (!WIDGETS_Init()) return 0;
136 /* Initialize dialog manager */
137 if (!DIALOG_Init()) return 0;
139 /* Initialize menus */
140 if (!MENU_Init()) return 0;
142 /* Create desktop window */
143 if (!WIN_CreateDesktopWindow()) return 0;
145 /* Initialize message spying */
146 if (!SPY_Init()) return 0;
148 /* Initialize Win32 data structures */
149 if (!KERN32_Init()) return 0;
151 /* Create system message queue */
152 queueSize = GetProfileInt32A( "windows", "TypeAhead", 120 );
153 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
155 /* Set double click time */
156 SetDoubleClickTime( GetProfileInt32A("windows","DoubleClickSpeed",452) );
158 return 1;
162 #ifndef WINELIB
163 /**********************************************************************
164 * main
166 int main(int argc, char *argv[] )
168 extern BOOL32 MAIN_WineInit( int *argc, char *argv[] );
169 extern char * DEBUG_argv0;
171 int i;
172 HINSTANCE16 handle;
175 * Save this so that the internal debugger can get a hold of it if
176 * it needs to.
178 DEBUG_argv0 = argv[0];
180 if (!MAIN_WineInit( &argc, argv )) return 1;
181 if (!MAIN_Init()) return 1;
183 for (i = 1; i < argc; i++)
185 if ((handle = WinExec( 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;
199 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
201 Yield(); /* Start the first task */
202 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
203 return 0;
206 #endif /* #ifndef WINELIB */