Release 960728
[wine] / loader / main.c
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 "kernel32.h"
20 #include "atom.h"
21 #include "dialog.h"
22 #include "directory.h"
23 #include "drive.h"
24 #include "queue.h"
25 #include "syscolor.h"
26 #include "sysmetrics.h"
27 #include "gdi.h"
28 #include "heap.h"
29 #include "debugger.h"
30 #include "miscemu.h"
31 #include "neexe.h"
32 #include "options.h"
33 #include "spy.h"
34 #include "task.h"
35 #include "user.h"
36 #include "dce.h"
37 #include "pe_image.h"
38 #include "shell.h"
39 #include "winproc.h"
40 #include "stddebug.h"
41 #include "debug.h"
42
43
44 /* Winelib run-time flag */
45 #ifdef WINELIB
46 int __winelib = 1;
47 #else
48 int __winelib = 0;
49 #endif
50
51 HANDLE32 SystemHeap = 0;
52 HANDLE32 SegptrHeap = 0;
53
54 /***********************************************************************
55  *           Main initialisation routine
56  */
57 int MAIN_Init(void)
58 {
59     extern BOOL32 RELAY_Init(void);
60     extern BOOL32 SIGNAL_Init(void);
61     extern BOOL32 WIDGETS_Init(void);
62
63     int queueSize;
64
65     /* Create the system and SEGPTR heaps */
66     if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
67     if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
68
69     /* Load the configuration file */
70     if (!PROFILE_LoadWineIni()) return 0;
71
72 #ifdef WINELIB
73     /* Create USER and GDI heap */
74     USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
75     LocalInit( USER_HeapSel, 0, 0xffff );
76     GDI_HeapSel  = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
77     LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
78 #else
79     /* Initialize relay code */
80     if (!RELAY_Init()) return 0;
81
82     /* Create built-in modules */
83     if (!BUILTIN_Init()) return 0;
84
85     /* Initialize interrupt vectors */
86     if (!INT_Init()) return 0;
87
88       /* Initialize DOS memory */
89     if (!DOSMEM_Init()) return 0;
90
91       /* Initialize the DOS interrupt */
92     if (!INT21_Init()) return 0;
93
94       /* Initialize signal handling */
95     if (!SIGNAL_Init()) return 0;
96 #endif  /* WINELIB */
97
98     /* Initialise DOS drives */
99     if (!DRIVE_Init()) return 0;
100
101     /* Initialise DOS directories */
102     if (!DIR_Init()) return 0;
103
104       /* Initialize tasks */
105     if (!TASK_Init()) return 0;
106
107       /* Initialize communications */
108     COMM_Init();
109
110       /* registry initialisation */
111     SHELL_LoadRegistry();
112     
113       /* Global atom table initialisation */
114     if (!ATOM_Init()) return 0;
115
116       /* GDI initialisation */
117     if (!GDI_Init()) return 0;
118
119       /* Initialize system colors and metrics*/
120     SYSMETRICS_Init();
121     SYSCOLOR_Init();
122
123       /* Create the DCEs */
124     DCE_Init();
125
126     /* Initialize window procedures */
127     if (!WINPROC_Init()) return 0;
128
129     /* Initialize built-in window classes */
130     if (!WIDGETS_Init()) return 0;
131
132       /* Initialize dialog manager */
133     if (!DIALOG_Init()) return 0;
134
135       /* Initialize menus */
136     if (!MENU_Init()) return 0;
137
138     /* Create desktop window */
139     if (!WIN_CreateDesktopWindow()) return 0;
140
141     /* Initialize message spying */
142     if (!SPY_Init()) return 0;
143
144       /* Initialize Win32 data structures */
145     if (!KERN32_Init()) return 0;
146
147       /* Create system message queue */
148     queueSize = GetProfileInt( "windows", "TypeAhead", 120 );
149     if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
150
151     /* Set double click time */
152     SetDoubleClickTime( GetProfileInt( "windows", "DoubleClickSpeed", 452 ) );
153
154     return 1;
155 }
156
157
158 #ifndef WINELIB
159 /**********************************************************************
160  *                                      main
161  */
162 int _WinMain(int argc, char **argv)
163 {
164     int i;
165     HANDLE handle;
166
167     if (!MAIN_Init()) return 0;
168
169     for (i = 1; i < argc; i++)
170     {
171         if ((handle = WinExec( argv[i], SW_SHOWNORMAL )) < 32)
172         {
173             fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
174             switch (handle)
175             {
176             case 2: fprintf( stderr, "file not found\n" ); break;
177             case 11: fprintf( stderr, "invalid exe file\n" ); break;
178             case 21: fprintf( stderr, "win32 executable\n" ); break;
179             default: fprintf( stderr, "error=%d\n", handle ); break;
180             }
181             exit(1);
182         }
183     }
184
185     if (Options.debug) DEBUG_SetBreakpoints( TRUE );  /* Setup breakpoints */
186
187     Yield();  /* Start the first task */
188     fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
189     return 0;
190 }
191
192 #endif /* #ifndef WINELIB */