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