Prototypes OleInitialize, OleUninitialize.
[wine/multimedia.git] / miscemu / main.c
blob09d4e6b6dd1849c1bff9dd99e631a9853198c7a7
1 /*
2 * Emulator initialisation code
4 */
6 #include <stdlib.h>
7 #include <assert.h>
8 #include "wine/winbase16.h"
9 #include "callback.h"
10 #include "debugger.h"
11 #include "main.h"
12 #include "miscemu.h"
13 #include "module.h"
14 #include "options.h"
15 #include "process.h"
16 #include "thread.h"
17 #include "task.h"
18 #include "stackframe.h"
19 #include "wine/exception.h"
20 #include "debugtools.h"
22 static int MAIN_argc;
23 static char **MAIN_argv;
26 /***********************************************************************
27 * Main loop of initial task
29 void MAIN_EmulatorRun( void )
31 char startProg[256], defProg[256];
32 HINSTANCE handle;
33 int i, tasks = 0;
34 MSG msg;
35 BOOL err_msg = FALSE;
37 /* Load system DLLs into the initial process (and initialize them) */
38 if ( !LoadLibrary16("GDI.EXE" ) || !LoadLibraryA("GDI32.DLL" )
39 || !LoadLibrary16("USER.EXE") || !LoadLibraryA("USER32.DLL"))
40 ExitProcess( 1 );
42 /* Get pointers to USER routines called by KERNEL */
43 THUNK_InitCallout();
45 /* Call FinalUserInit routine */
46 Callout.FinalUserInit16();
48 /* Call InitApp for initial task */
49 Callout.InitApp16( MapHModuleLS( 0 ) );
51 /* Add the Default Program if no program on the command line */
52 if (!MAIN_argv[1])
54 PROFILE_GetWineIniString( "programs", "Default", "",
55 defProg, sizeof(defProg) );
56 if (defProg[0]) MAIN_argv[MAIN_argc++] = defProg;
59 /* Add the Startup Program to the run list */
60 PROFILE_GetWineIniString( "programs", "Startup", "",
61 startProg, sizeof(startProg) );
62 if (startProg[0]) MAIN_argv[MAIN_argc++] = startProg;
64 /* Abort if no executable on command line */
65 if (MAIN_argc <= 1)
67 MAIN_Usage(MAIN_argv[0]);
68 ExitProcess( 1 );
71 /* Load and run executables given on command line */
72 for (i = 1; i < MAIN_argc; i++)
74 if ((handle = WinExec( MAIN_argv[i], SW_SHOWNORMAL )) < 32)
76 err_msg = TRUE;
77 MESSAGE("wine: can't exec '%s': ", MAIN_argv[i]);
78 switch (handle)
80 case 2: MESSAGE("main executable or required DLL not found\n" ); break;
81 case 11: MESSAGE("invalid exe file\n" ); break;
82 default: MESSAGE("error=%d\n", handle ); break;
85 else tasks++;
88 if (!tasks)
90 if (!err_msg) MESSAGE("wine: no executable file found.\n" );
91 ExitProcess( 0 );
94 /* Start message loop for desktop window */
96 while ( GetNumTasks16() > 1 && Callout.GetMessageA( &msg, 0, 0, 0 ) )
98 Callout.TranslateMessage( &msg );
99 Callout.DispatchMessageA( &msg );
102 ExitProcess( 0 );
106 /**********************************************************************
107 * main
109 int main( int argc, char *argv[] )
111 NE_MODULE *pModule;
113 /* Initialize everything */
114 if (!MAIN_MainInit( &argc, argv, FALSE )) return 1;
115 MAIN_argc = argc; MAIN_argv = argv;
117 /* Create initial task */
118 if ( !(pModule = NE_GetPtr( GetModuleHandle16( "KERNEL" ) )) ) return 1;
119 if ( !TASK_Create( pModule, FALSE ) ) return 1;
121 /* Switch to initial task */
122 PostEvent16( PROCESS_Current()->task );
123 TASK_Reschedule();
125 /* Switch stacks and jump to MAIN_EmulatorRun */
126 CALL32_Init( &IF1632_CallLargeStack, MAIN_EmulatorRun, NtCurrentTeb()->stack_top );
128 MESSAGE( "main: Should never happen: returned from CALL32_Init()\n" );
129 return 0;