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