Use the right buffer size in SYSPARAMS_Load instead of some random
[wine] / miscemu / main.c
1 /*
2  * Emulator initialisation code
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "winbase.h"
22 #include "wine/winbase16.h"
23 #include "wingdi.h"
24 #include "winuser.h"
25
26 #include "miscemu.h"
27 #include "callback.h"
28 #include "options.h"
29 #include "wine/debug.h"
30
31 static char main_exe_name[MAX_PATH];
32 static HANDLE main_exe_file;
33
34 static BOOL (WINAPI *pGetMessageA)(LPMSG,HWND,UINT,UINT);
35 static BOOL (WINAPI *pTranslateMessage)(const MSG*);
36 static LONG (WINAPI *pDispatchMessageA)(const MSG*);
37
38 extern void DECLSPEC_NORETURN PROCESS_InitWine(
39         int argc, char *argv[], LPSTR win16_exe_name,
40         HANDLE *win16_exe_file );
41 extern HINSTANCE16 NE_StartMain( LPCSTR name, HANDLE file );
42
43 /***********************************************************************
44  *           Main loop of initial task
45  */
46 int WINAPI wine_initial_task( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, INT show )
47 {
48     MSG msg;
49     HINSTANCE16 instance;
50     HMODULE user32;
51
52     /* some programs assume mmsystem is always present */
53     LoadLibrary16( "mmsystem.dll" );
54
55     if ((instance = NE_StartMain( main_exe_name, main_exe_file )) < 32)
56     {
57         if (instance == 11)  /* try DOS format */
58         {
59             if (DPMI_LoadDosSystem())
60                 Dosvm.LoadDosExe( main_exe_name, main_exe_file );
61             /* if we get back here it failed */
62             instance = GetLastError();
63         }
64
65         WINE_MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() );
66         switch (instance)
67         {
68         case  2: WINE_MESSAGE("file not found\n" ); break;
69         case 11: WINE_MESSAGE("invalid exe file\n" ); break;
70         default: WINE_MESSAGE("error=%d\n", instance ); break;
71         }
72         ExitProcess(instance);
73     }
74     CloseHandle( main_exe_file );  /* avoid file sharing problems */
75
76     /* Start message loop for desktop window */
77
78     if (!(user32 = LoadLibraryA( "user32.dll" )))
79     {
80         WINE_MESSAGE( "Cannot load user32.dll\n" );
81         ExitProcess( GetLastError() );
82     }
83     pGetMessageA      = (void *)GetProcAddress( user32, "GetMessageA" );
84     pTranslateMessage = (void *)GetProcAddress( user32, "TranslateMessage" );
85     pDispatchMessageA = (void *)GetProcAddress( user32, "DispatchMessageA" );
86
87     while ( GetNumTasks16() > 1  && pGetMessageA( &msg, 0, 0, 0 ) )
88     {
89         pTranslateMessage( &msg );
90         pDispatchMessageA( &msg );
91     }
92
93     ExitProcess( 0 );
94 }
95
96
97 /**********************************************************************
98  *           main
99  */
100 int main( int argc, char *argv[] )
101 {
102     PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file );
103     return 1;  /* not reached */
104 }