Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Emulator initialisation code |
| 3 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 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 |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 21 | #include "winbase.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 22 | #include "wine/winbase16.h" |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 23 | #include "wingdi.h" |
| 24 | #include "winuser.h" |
| 25 | |
Ove Kaaven | e5557b3 | 2000-12-26 00:22:45 +0000 | [diff] [blame] | 26 | #include "miscemu.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 27 | #include "callback.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 28 | #include "options.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 29 | #include "wine/debug.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 30 | |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 31 | static char main_exe_name[MAX_PATH]; |
| 32 | static HANDLE main_exe_file; |
| 33 | |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 34 | static BOOL (WINAPI *pGetMessageA)(LPMSG,HWND,UINT,UINT); |
| 35 | static BOOL (WINAPI *pTranslateMessage)(const MSG*); |
| 36 | static LONG (WINAPI *pDispatchMessageA)(const MSG*); |
| 37 | |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 38 | extern void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name, |
| 39 | HANDLE *win16_exe_file ) WINE_NORETURN; |
| 40 | extern HINSTANCE16 NE_StartMain( LPCSTR name, HANDLE file ); |
Alexandre Julliard | becb9a3 | 2000-12-11 03:48:15 +0000 | [diff] [blame] | 41 | |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 42 | /*********************************************************************** |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 43 | * Main loop of initial task |
| 44 | */ |
Alexandre Julliard | 909eff9 | 2000-12-15 03:38:11 +0000 | [diff] [blame] | 45 | int WINAPI wine_initial_task( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, INT show ) |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 46 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 47 | MSG msg; |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 48 | HINSTANCE16 instance; |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 49 | HMODULE user32; |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 50 | |
Joshua Thielen | 3f089a1 | 2001-11-25 00:49:10 +0000 | [diff] [blame] | 51 | /* some programs assume mmsystem is always present */ |
| 52 | LoadLibrary16( "mmsystem.dll" ); |
| 53 | |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 54 | if ((instance = NE_StartMain( main_exe_name, main_exe_file )) < 32) |
Alexandre Julliard | 5b4f3e8 | 2000-05-01 16:24:22 +0000 | [diff] [blame] | 55 | { |
Alexandre Julliard | e087508 | 2000-11-08 04:33:20 +0000 | [diff] [blame] | 56 | if (instance == 11) /* try DOS format */ |
| 57 | { |
Ove Kaaven | e5557b3 | 2000-12-26 00:22:45 +0000 | [diff] [blame] | 58 | if (DPMI_LoadDosSystem()) |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 59 | Dosvm.LoadDosExe( main_exe_name, main_exe_file ); |
Alexandre Julliard | e087508 | 2000-11-08 04:33:20 +0000 | [diff] [blame] | 60 | /* if we get back here it failed */ |
| 61 | instance = GetLastError(); |
| 62 | } |
| 63 | |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 64 | MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() ); |
| 65 | switch (instance) |
Alexandre Julliard | fe08568 | 2000-03-18 21:56:10 +0000 | [diff] [blame] | 66 | { |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 67 | case 2: MESSAGE("file not found\n" ); break; |
| 68 | case 11: MESSAGE("invalid exe file\n" ); break; |
| 69 | default: MESSAGE("error=%d\n", instance ); break; |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 70 | } |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 71 | ExitProcess(instance); |
Marcus Meissner | 4097865 | 1999-02-14 11:32:18 +0000 | [diff] [blame] | 72 | } |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 73 | CloseHandle( main_exe_file ); /* avoid file sharing problems */ |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 74 | |
Ulrich Weigand | e8b0274 | 1998-11-08 12:07:36 +0000 | [diff] [blame] | 75 | /* Start message loop for desktop window */ |
| 76 | |
Alexandre Julliard | 627c907 | 2001-03-28 18:47:05 +0000 | [diff] [blame] | 77 | if (!(user32 = LoadLibraryA( "user32.dll" ))) |
| 78 | { |
| 79 | MESSAGE( "Cannot load user32.dll\n" ); |
| 80 | ExitProcess( GetLastError() ); |
| 81 | } |
| 82 | pGetMessageA = (void *)GetProcAddress( user32, "GetMessageA" ); |
| 83 | pTranslateMessage = (void *)GetProcAddress( user32, "TranslateMessage" ); |
| 84 | pDispatchMessageA = (void *)GetProcAddress( user32, "DispatchMessageA" ); |
| 85 | |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 86 | while ( GetNumTasks16() > 1 && pGetMessageA( &msg, 0, 0, 0 ) ) |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 87 | { |
Alexandre Julliard | ea2a9a8 | 2001-02-20 00:55:17 +0000 | [diff] [blame] | 88 | pTranslateMessage( &msg ); |
| 89 | pDispatchMessageA( &msg ); |
Ulrich Weigand | a1957c4 | 1999-05-24 08:10:46 +0000 | [diff] [blame] | 90 | } |
Ulrich Weigand | c75d0e1 | 1998-11-01 17:59:35 +0000 | [diff] [blame] | 91 | |
| 92 | ExitProcess( 0 ); |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | |
| 96 | /********************************************************************** |
| 97 | * main |
| 98 | */ |
| 99 | int main( int argc, char *argv[] ) |
| 100 | { |
Alexandre Julliard | 105b0f4 | 2001-01-06 01:55:49 +0000 | [diff] [blame] | 101 | PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file ); |
Alexandre Julliard | c192ba2 | 2000-05-29 21:25:10 +0000 | [diff] [blame] | 102 | return 1; /* not reached */ |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 103 | } |