Release 950727
[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 "task.h"
16 #include "selectors.h"
17 #include "comm.h"
18 #include "user.h"
19 #include "menu.h"
20 #include "atom.h"
21 #include "dialog.h"
22 #include "message.h"
23 #include "syscolor.h"
24 #include "sysmetrics.h"
25 #include "gdi.h"
26 #include "debugger.h"
27 #include "dos_fs.h"
28 #include "dlls.h"
29 #include "miscemu.h"
30 #include "neexe.h"
31 #include "options.h"
32 #include "task.h"
33 #include "dce.h"
34 #include "pe_image.h"
35 #include "stddebug.h"
36 #include "debug.h"
37
38
39 /***********************************************************************
40  *           Main initialisation routine
41  */
42 int MAIN_Init(void)
43 {
44     extern BOOL RELAY_Init(void);
45     extern BOOL RELAY32_Init(void); 
46
47     int queueSize;
48
49     SpyInit();
50
51       /* Initialize relay code */
52     if (!RELAY_Init()) return 0;
53
54       /* Initialize Win32 relay code */
55     if (!RELAY32_Init()) return 0;
56
57       /* Create built-in modules */
58     if (!MODULE_Init()) return 0;
59
60       /* Initialize tasks */
61     if (!TASK_Init()) return 0;
62
63       /* Initialize interrupt vectors */
64     if (!INT_Init()) return 0;
65
66       /* Initialize the DOS file system */
67     DOS_InitFS();
68
69       /* Create DOS environment */
70     CreateSelectors();
71
72       /* Initialize signal handling */
73     init_wine_signals();
74
75       /* Initialize communications */
76     COMM_Init();
77
78 #ifndef WINELIB    
79       /* Initialize the DOS memory */
80     INT21_Init();
81
82       /* Create USER heap */
83     if (!USER_HeapInit()) return 0;
84 #endif
85     
86       /* Global atom table initialisation */
87     if (!ATOM_Init()) return 0;
88     
89       /* GDI initialisation */
90     if (!GDI_Init()) return 0;
91
92       /* Initialize system colors and metrics*/
93     SYSMETRICS_Init();
94     SYSCOLOR_Init();
95
96       /* Create the DCEs */
97     DCE_Init();
98     
99       /* Initialize dialog manager */
100     if (!DIALOG_Init()) return 0;
101
102       /* Initialize menus */
103     if (!MENU_Init()) return 0;
104
105       /* Create system message queue */
106     queueSize = GetProfileInt( "windows", "TypeAhead", 120 );
107     if (!MSG_CreateSysMsgQueue( queueSize )) return 0;
108
109     return 1;
110 }
111
112
113 #ifndef WINELIB
114 /**********************************************************************
115  *                                      main
116  */
117 int _WinMain(int argc, char **argv)
118 {
119     int i;
120     HANDLE handle;
121
122     if (!MAIN_Init()) return 0;
123
124     for (i = 1; i < argc; i++)
125     {
126         if ((handle = WinExec( argv[i], SW_SHOWNORMAL )) < 32)
127         {
128             fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
129             switch (handle)
130             {
131             case 2: fprintf( stderr, "file not found\n" ); break;
132             case 11: fprintf( stderr, "invalid exe file\n" ); break;
133             case 21: fprintf( stderr, "win32 executable\n" ); break;
134             default: fprintf( stderr, "error=%d\n", handle ); break;
135             }
136             exit(1);
137         }
138     }
139
140     if (Options.debug) DEBUG_SetBreakpoints( TRUE );  /* Setup breakpoints */
141
142     Yield();  /* Start the first task */
143     fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
144     return 0;
145 }
146
147 #endif /* #ifndef WINELIB */