Moved most of the real-mode stuff to dlls/winedos.
[wine] / miscemu / main.c
1 /*
2  * Emulator initialisation code
3  *
4  */
5
6 #include "winbase.h"
7 #include "wine/winbase16.h"
8 #include "wingdi.h"
9 #include "winuser.h"
10
11 #include "miscemu.h"
12 #include "callback.h"
13 #include "options.h"
14 #include "debugtools.h"
15
16 static char main_exe_name[MAX_PATH];
17 static HANDLE main_exe_file;
18
19 static BOOL (WINAPI *pGetMessageA)(LPMSG,HWND,UINT,UINT);
20 static BOOL (WINAPI *pTranslateMessage)(const MSG*);
21 static LONG (WINAPI *pDispatchMessageA)(const MSG*);
22
23 extern void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name,
24                               HANDLE *win16_exe_file ) WINE_NORETURN;
25 extern HINSTANCE16 NE_StartMain( LPCSTR name, HANDLE file );
26
27 /***********************************************************************
28  *           Main loop of initial task
29  */
30 int WINAPI wine_initial_task( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, INT show )
31 {
32     MSG msg;
33     HINSTANCE16 instance;
34     HMODULE user32;
35
36     /* some programs assume mmsystem is always present */
37     LoadLibrary16( "mmsystem.dll" );
38
39     if ((instance = NE_StartMain( main_exe_name, main_exe_file )) < 32)
40     {
41         if (instance == 11)  /* try DOS format */
42         {
43             if (DPMI_LoadDosSystem())
44                 Dosvm.LoadDosExe( main_exe_name, main_exe_file );
45             /* if we get back here it failed */
46             instance = GetLastError();
47         }
48
49         MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() );
50         switch (instance) 
51         {
52         case  2: MESSAGE("file not found\n" ); break;
53         case 11: MESSAGE("invalid exe file\n" ); break;
54         default: MESSAGE("error=%d\n", instance ); break;
55         }
56         ExitProcess(instance);
57     }
58     CloseHandle( main_exe_file );  /* avoid file sharing problems */
59
60     /* Start message loop for desktop window */
61
62     if (!(user32 = LoadLibraryA( "user32.dll" )))
63     {
64         MESSAGE( "Cannot load user32.dll\n" );
65         ExitProcess( GetLastError() );
66     }
67     pGetMessageA      = (void *)GetProcAddress( user32, "GetMessageA" );
68     pTranslateMessage = (void *)GetProcAddress( user32, "TranslateMessage" );
69     pDispatchMessageA = (void *)GetProcAddress( user32, "DispatchMessageA" );
70
71     while ( GetNumTasks16() > 1  && pGetMessageA( &msg, 0, 0, 0 ) )
72     {
73         pTranslateMessage( &msg );
74         pDispatchMessageA( &msg );
75     }
76
77     ExitProcess( 0 );
78 }
79
80
81 /**********************************************************************
82  *           main
83  */
84 int main( int argc, char *argv[] )
85 {
86     PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file );
87     return 1;  /* not reached */
88 }