Takes print spooler functions out of win16drv.
[wine/multimedia.git] / miscemu / main.c
blob07de95a265399803354f3540002662157ce9492e
1 /*
2 * Emulator initialisation code
4 */
6 #include <assert.h>
7 #include "callback.h"
8 #include "debug.h"
9 #include "debugger.h"
10 #include "main.h"
11 #include "miscemu.h"
12 #include "module.h"
13 #include "options.h"
14 #include "process.h"
15 #include "win16drv.h"
16 #include "thread.h"
17 #include "task.h"
18 #include "stackframe.h"
19 #include "windows.h"
21 static int MAIN_argc;
22 static char **MAIN_argv;
24 /***********************************************************************
25 * Emulator initialisation
27 BOOL32 MAIN_EmulatorInit(void)
29 /* Main initialization */
30 if (!MAIN_MainInit()) return FALSE;
32 /* Initialize relay code */
33 if (!RELAY_Init()) return FALSE;
35 /* Initialize signal handling */
36 if (!SIGNAL_InitEmulator()) return FALSE;
38 /* Create the Win16 printer driver */
39 if (!WIN16DRV_Init()) return FALSE;
41 return TRUE;
44 /***********************************************************************
45 * Main loop of initial task
47 void MAIN_EmulatorRun( void )
49 char startProg[256], defProg[256];
50 HINSTANCE32 handle;
51 int i;
53 BOOL32 (*WINAPI pGetMessage)(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max);
54 BOOL32 (*WINAPI pTranslateMessage)( const MSG32* msg );
55 LONG (*WINAPI pDispatchMessage)( const MSG32* msg );
56 HMODULE32 hModule;
57 MSG32 msg;
59 /* Load system DLLs into the initial process (and initialize them) */
60 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibrary32A("GDI32.DLL" )
61 || !LoadLibrary16("USER.EXE") || !LoadLibrary32A("USER32.DLL"))
62 ExitProcess( 1 );
64 /* Add the Default Program if no program on the command line */
65 if (!MAIN_argv[1])
67 PROFILE_GetWineIniString( "programs", "Default", "",
68 defProg, sizeof(defProg) );
69 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
72 /* Add the Startup Program to the run list */
73 PROFILE_GetWineIniString( "programs", "Startup", "",
74 startProg, sizeof(startProg) );
75 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
77 /* Abort if no executable on command line */
78 if (MAIN_argc <= 1)
80 MAIN_Usage(MAIN_argv[0]);
81 exit(1);
84 /* Load and run executables given on command line */
85 for (i = 1; i < MAIN_argc; i++)
86 if ((handle = WinExec32( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
88 MSG("wine: can't exec '%s': ", MAIN_argv[i]);
89 switch (handle)
91 case 2: MSG("file not found\n" ); break;
92 case 11: MSG("invalid exe file\n" ); break;
93 default: MSG("error=%d\n", handle ); break;
97 if (GetNumTasks() <= 1)
99 MSG("wine: no executable file found.\n" );
100 ExitProcess( 0 );
104 /* Start message loop for desktop window */
106 hModule = GetModuleHandle32A( "USER32" );
107 pGetMessage = GetProcAddress32( hModule, "GetMessageA" );
108 pTranslateMessage = GetProcAddress32( hModule, "TranslateMessage" );
109 pDispatchMessage = GetProcAddress32( hModule, "DispatchMessageA" );
111 assert( pGetMessage );
112 assert( pTranslateMessage );
113 assert( pDispatchMessage );
115 while ( GetNumTasks() > 1 && pGetMessage( &msg, 0, 0, 0 ) )
117 pTranslateMessage( &msg );
118 pDispatchMessage( &msg );
121 ExitProcess( 0 );
125 /**********************************************************************
126 * main
128 int main( int argc, char *argv[] )
130 NE_MODULE *pModule;
131 HINSTANCE16 hInstance;
132 extern char * DEBUG_argv0;
134 __winelib = 0; /* First of all, clear the Winelib flag */
137 * Save this so that the internal debugger can get a hold of it if
138 * it needs to.
140 DEBUG_argv0 = argv[0];
142 /* Create the initial process */
143 if (!PROCESS_Init()) return FALSE;
145 /* Parse command-line */
146 if (!MAIN_WineInit( &argc, argv )) return 1;
147 MAIN_argc = argc; MAIN_argv = argv;
149 /* Handle -dll option (hack) */
150 if (Options.dllFlags)
152 if (!BUILTIN_ParseDLLOptions( Options.dllFlags ))
154 MSG("%s: Syntax: -dll +xxx,... or -dll -xxx,...\n",
155 argv[0] );
156 BUILTIN_PrintDLLs();
157 exit(1);
161 /* Set up debugger callback routines */
162 ctx_debug_call = ctx_debug;
163 if (Options.debug)
164 TASK_AddTaskEntryBreakpoint = DEBUG_AddTaskEntryBreakpoint;
166 /* Initialize everything */
167 if (!MAIN_EmulatorInit()) return 1;
169 /* Load kernel modules */
170 if (!LoadLibrary16( "KERNEL" )) return 1;
171 if (!LoadLibrary32A( "KERNEL32" )) return 1;
173 /* Create initial task */
174 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL32" ) )) ) return 1;
175 hInstance = NE_CreateInstance( pModule, NULL, TRUE );
176 PROCESS_Current()->task = TASK_Create( THREAD_Current(), pModule, hInstance, 0, FALSE );
178 /* Initialize CALL32 routines */
179 /* This needs to be done just before switching stacks */
180 IF1632_CallLargeStack = (int (*)(int (*func)(), void *arg))CALL32_Init();
182 /* Switch to initial task */
183 CURRENT_STACK16->frame32->retaddr = (DWORD)MAIN_EmulatorRun;
184 TASK_StartTask( PROCESS_Current()->task );
185 MSG( "main: Should never happen: returned from TASK_StartTask()\n" );
186 return 0;