blob: e248d8ab2cc144a859a60b93944d33ee2ed206b0 [file] [log] [blame]
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001/*
2 * Emulator initialisation code
3 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00004 * 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 Julliarda0b2b1d1997-11-16 17:38:29 +000019 */
20
Alexandre Julliardc192ba22000-05-29 21:25:10 +000021#include "winbase.h"
Marcus Meissner317af321999-02-17 13:51:06 +000022#include "wine/winbase16.h"
Alexandre Julliardc192ba22000-05-29 21:25:10 +000023#include "wingdi.h"
24#include "winuser.h"
25
Ove Kaavene5557b32000-12-26 00:22:45 +000026#include "miscemu.h"
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000027#include "callback.h"
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000028#include "options.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000029#include "wine/debug.h"
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000030
Alexandre Julliard105b0f42001-01-06 01:55:49 +000031static char main_exe_name[MAX_PATH];
32static HANDLE main_exe_file;
33
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000034static BOOL (WINAPI *pGetMessageA)(LPMSG,HWND,UINT,UINT);
35static BOOL (WINAPI *pTranslateMessage)(const MSG*);
36static LONG (WINAPI *pDispatchMessageA)(const MSG*);
37
Alexandre Julliard105b0f42001-01-06 01:55:49 +000038extern void PROCESS_InitWine( int argc, char *argv[], LPSTR win16_exe_name,
39 HANDLE *win16_exe_file ) WINE_NORETURN;
40extern HINSTANCE16 NE_StartMain( LPCSTR name, HANDLE file );
Alexandre Julliardbecb9a32000-12-11 03:48:15 +000041
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000042/***********************************************************************
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000043 * Main loop of initial task
44 */
Alexandre Julliard909eff92000-12-15 03:38:11 +000045int WINAPI wine_initial_task( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, INT show )
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000046{
Alexandre Julliarda3960291999-02-26 11:11:13 +000047 MSG msg;
Alexandre Julliardc192ba22000-05-29 21:25:10 +000048 HINSTANCE16 instance;
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000049 HMODULE user32;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000050
Joshua Thielen3f089a12001-11-25 00:49:10 +000051 /* some programs assume mmsystem is always present */
52 LoadLibrary16( "mmsystem.dll" );
53
Alexandre Julliard105b0f42001-01-06 01:55:49 +000054 if ((instance = NE_StartMain( main_exe_name, main_exe_file )) < 32)
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000055 {
Alexandre Julliarde0875082000-11-08 04:33:20 +000056 if (instance == 11) /* try DOS format */
57 {
Ove Kaavene5557b32000-12-26 00:22:45 +000058 if (DPMI_LoadDosSystem())
Alexandre Julliard105b0f42001-01-06 01:55:49 +000059 Dosvm.LoadDosExe( main_exe_name, main_exe_file );
Alexandre Julliarde0875082000-11-08 04:33:20 +000060 /* if we get back here it failed */
61 instance = GetLastError();
62 }
63
Alexandre Julliardc192ba22000-05-29 21:25:10 +000064 MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() );
65 switch (instance)
Alexandre Julliardfe085682000-03-18 21:56:10 +000066 {
Alexandre Julliardc192ba22000-05-29 21:25:10 +000067 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 Weigande8b02741998-11-08 12:07:36 +000070 }
Alexandre Julliardc192ba22000-05-29 21:25:10 +000071 ExitProcess(instance);
Marcus Meissner40978651999-02-14 11:32:18 +000072 }
Alexandre Julliard105b0f42001-01-06 01:55:49 +000073 CloseHandle( main_exe_file ); /* avoid file sharing problems */
Ulrich Weigande8b02741998-11-08 12:07:36 +000074
Ulrich Weigande8b02741998-11-08 12:07:36 +000075 /* Start message loop for desktop window */
76
Alexandre Julliard627c9072001-03-28 18:47:05 +000077 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 Julliardea2a9a82001-02-20 00:55:17 +000086 while ( GetNumTasks16() > 1 && pGetMessageA( &msg, 0, 0, 0 ) )
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000087 {
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000088 pTranslateMessage( &msg );
89 pDispatchMessageA( &msg );
Ulrich Weiganda1957c41999-05-24 08:10:46 +000090 }
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000091
92 ExitProcess( 0 );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000093}
94
95
96/**********************************************************************
97 * main
98 */
99int main( int argc, char *argv[] )
100{
Alexandre Julliard105b0f42001-01-06 01:55:49 +0000101 PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file );
Alexandre Julliardc192ba22000-05-29 21:25:10 +0000102 return 1; /* not reached */
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000103}