Release 960606
[wine.git] / loader / main.c
blobbc3ac02035ffdde804fed93f5346a913e7e044fb
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 "stddebug.h"
40 #include "debug.h"
42 void init_wine_signals(void);
44 HANDLE32 SystemHeap = 0;
45 HANDLE32 SegptrHeap = 0;
47 /***********************************************************************
48 * Main initialisation routine
50 int MAIN_Init(void)
52 extern BOOL RELAY_Init(void);
54 int queueSize;
56 /* Create the system and SEGPTR heaps */
57 if (!(SystemHeap = HeapCreate( HEAP_GROWABLE, 0x10000, 0 ))) return 0;
58 if (!(SegptrHeap = HeapCreate( HEAP_WINE_SEGPTR, 0, 0 ))) return 0;
60 /* Load the configuration file */
61 if (!PROFILE_LoadWineIni()) return 0;
63 /* Initialize message spying */
64 if (!SPY_Init()) return 0;
66 #ifdef WINELIB
67 /* Create USER and GDI heap */
68 USER_HeapSel = GlobalAlloc16( GMEM_FIXED, 0x10000 );
69 LocalInit( USER_HeapSel, 0, 0xffff );
70 GDI_HeapSel = GlobalAlloc16( GMEM_FIXED, GDI_HEAP_SIZE );
71 LocalInit( GDI_HeapSel, 0, GDI_HEAP_SIZE-1 );
72 #else
73 /* Initialize relay code */
74 if (!RELAY_Init()) return 0;
76 /* Create built-in modules */
77 if (!BUILTIN_Init()) return 0;
78 #endif
80 /* Initialise DOS drives */
81 if (!DRIVE_Init()) return 0;
83 /* Initialise DOS directories */
84 if (!DIR_Init()) return 0;
86 /* Initialize tasks */
87 if (!TASK_Init()) return 0;
89 /* Initialize communications */
90 COMM_Init();
92 #ifndef WINELIB
93 /* Initialize interrupt vectors */
94 if (!INT_Init()) return 0;
96 /* Initialize DOS memory */
97 if (!DOSMEM_Init()) return 0;
99 /* Initialize signal handling */
100 init_wine_signals();
102 /* Initialize the DOS memory */
103 if (!INT21_Init()) return 0;
104 #endif
105 /* registry initialisation */
106 SHELL_LoadRegistry();
108 /* Global atom table initialisation */
109 if (!ATOM_Init()) return 0;
111 /* GDI initialisation */
112 if (!GDI_Init()) return 0;
114 /* Initialize system colors and metrics*/
115 SYSMETRICS_Init();
116 SYSCOLOR_Init();
118 /* Create the DCEs */
119 DCE_Init();
121 /* Initialize dialog manager */
122 if (!DIALOG_Init()) return 0;
124 /* Initialize menus */
125 if (!MENU_Init()) return 0;
127 /* Initialize Win32 data structures */
128 if (!KERN32_Init()) return 0;
130 /* Create system message queue */
131 queueSize = GetProfileInt( "windows", "TypeAhead", 120 );
132 if (!QUEUE_CreateSysMsgQueue( queueSize )) return 0;
134 /* Set double click time */
135 SetDoubleClickTime( GetProfileInt( "windows", "DoubleClickSpeed", 452 ) );
137 return 1;
141 #ifndef WINELIB
142 /**********************************************************************
143 * main
145 int _WinMain(int argc, char **argv)
147 int i;
148 HANDLE handle;
150 if (!MAIN_Init()) return 0;
152 for (i = 1; i < argc; i++)
154 if ((handle = WinExec( argv[i], SW_SHOWNORMAL )) < 32)
156 fprintf(stderr, "wine: can't exec '%s': ", argv[i]);
157 switch (handle)
159 case 2: fprintf( stderr, "file not found\n" ); break;
160 case 11: fprintf( stderr, "invalid exe file\n" ); break;
161 case 21: fprintf( stderr, "win32 executable\n" ); break;
162 default: fprintf( stderr, "error=%d\n", handle ); break;
164 exit(1);
168 if (Options.debug) DEBUG_SetBreakpoints( TRUE ); /* Setup breakpoints */
170 Yield(); /* Start the first task */
171 fprintf( stderr, "WinMain: Should never happen: returned from Yield()\n" );
172 return 0;
175 #endif /* #ifndef WINELIB */