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