blob: f4c722c372d052944da3cdbc50867eec0cb4b03a [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
Patrik Stridvalle29345c2002-10-01 18:07:37 +000038extern void DECLSPEC_NORETURN PROCESS_InitWine(
39 int argc, char *argv[], LPSTR win16_exe_name,
40 HANDLE *win16_exe_file );
Alexandre Julliard105b0f42001-01-06 01:55:49 +000041extern HINSTANCE16 NE_StartMain( LPCSTR name, HANDLE file );
Alexandre Julliardbecb9a32000-12-11 03:48:15 +000042
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000043/***********************************************************************
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000044 * Main loop of initial task
45 */
Alexandre Julliard909eff92000-12-15 03:38:11 +000046int WINAPI wine_initial_task( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, INT show )
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000047{
Alexandre Julliarda3960291999-02-26 11:11:13 +000048 MSG msg;
Alexandre Julliardc192ba22000-05-29 21:25:10 +000049 HINSTANCE16 instance;
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000050 HMODULE user32;
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000051
Joshua Thielen3f089a12001-11-25 00:49:10 +000052 /* some programs assume mmsystem is always present */
53 LoadLibrary16( "mmsystem.dll" );
54
Alexandre Julliard105b0f42001-01-06 01:55:49 +000055 if ((instance = NE_StartMain( main_exe_name, main_exe_file )) < 32)
Alexandre Julliard5b4f3e82000-05-01 16:24:22 +000056 {
Alexandre Julliarde0875082000-11-08 04:33:20 +000057 if (instance == 11) /* try DOS format */
58 {
Ove Kaavene5557b32000-12-26 00:22:45 +000059 if (DPMI_LoadDosSystem())
Alexandre Julliard105b0f42001-01-06 01:55:49 +000060 Dosvm.LoadDosExe( main_exe_name, main_exe_file );
Alexandre Julliarde0875082000-11-08 04:33:20 +000061 /* if we get back here it failed */
62 instance = GetLastError();
63 }
64
Alexandre Julliardc192ba22000-05-29 21:25:10 +000065 MESSAGE( "%s: can't exec '%s': ", argv0, GetCommandLineA() );
Vincent Béron9a624912002-05-31 23:06:46 +000066 switch (instance)
Alexandre Julliardfe085682000-03-18 21:56:10 +000067 {
Alexandre Julliardc192ba22000-05-29 21:25:10 +000068 case 2: MESSAGE("file not found\n" ); break;
69 case 11: MESSAGE("invalid exe file\n" ); break;
70 default: MESSAGE("error=%d\n", instance ); break;
Ulrich Weigande8b02741998-11-08 12:07:36 +000071 }
Alexandre Julliardc192ba22000-05-29 21:25:10 +000072 ExitProcess(instance);
Marcus Meissner40978651999-02-14 11:32:18 +000073 }
Alexandre Julliard105b0f42001-01-06 01:55:49 +000074 CloseHandle( main_exe_file ); /* avoid file sharing problems */
Ulrich Weigande8b02741998-11-08 12:07:36 +000075
Ulrich Weigande8b02741998-11-08 12:07:36 +000076 /* Start message loop for desktop window */
77
Alexandre Julliard627c9072001-03-28 18:47:05 +000078 if (!(user32 = LoadLibraryA( "user32.dll" )))
79 {
80 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
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000087 while ( GetNumTasks16() > 1 && pGetMessageA( &msg, 0, 0, 0 ) )
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000088 {
Alexandre Julliardea2a9a82001-02-20 00:55:17 +000089 pTranslateMessage( &msg );
90 pDispatchMessageA( &msg );
Ulrich Weiganda1957c41999-05-24 08:10:46 +000091 }
Ulrich Weigandc75d0e11998-11-01 17:59:35 +000092
93 ExitProcess( 0 );
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000094}
95
96
97/**********************************************************************
98 * main
99 */
100int main( int argc, char *argv[] )
101{
Alexandre Julliard105b0f42001-01-06 01:55:49 +0000102 PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file );
Alexandre Julliardc192ba22000-05-29 21:25:10 +0000103 return 1; /* not reached */
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000104}