1 | /*
|
---|
2 | *
|
---|
3 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
4 | *
|
---|
5 | */
|
---|
6 | /*
|
---|
7 | * Win32 exe class
|
---|
8 | *
|
---|
9 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_DOSFILEMGR /* File Manager values */
|
---|
13 | #define INCL_DOSERRORS /* DOS Error values */
|
---|
14 | #define INCL_DOSPROCESS /* DOS Process values */
|
---|
15 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
---|
16 | #define INCL_WIN
|
---|
17 | #include <os2.h>
|
---|
18 | #include <stdio.h>
|
---|
19 | #include <string.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <iostream.h>
|
---|
22 | #include <fstream.h>
|
---|
23 | #include "misc.h"
|
---|
24 | #include "nameid.h"
|
---|
25 | #include "win32type.h"
|
---|
26 | #include <winexe.h>
|
---|
27 | #include "wprocess.h"
|
---|
28 | #include "pefile.h"
|
---|
29 | #include "cio.h"
|
---|
30 | #include "console2.h"
|
---|
31 |
|
---|
32 | Win32Exe *WinExe = NULL;
|
---|
33 |
|
---|
34 | //******************************************************************************
|
---|
35 | //******************************************************************************
|
---|
36 | Win32Exe::Win32Exe(char *szFileName) : Win32Image(szFileName), fConsoleApp(FALSE),
|
---|
37 | cmdline(NULL), OS2InstanceHandle(-1)
|
---|
38 | {
|
---|
39 | fConsoleApp = (oh.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI);
|
---|
40 | WinExe = this;
|
---|
41 |
|
---|
42 | dprintf(("Win32Exe ctor: %s", szFileName));
|
---|
43 |
|
---|
44 | HMInitialize(); /* store standard handles within HandleManager */
|
---|
45 | dprintf(("KERNEL32/WINEXE: HandleManager Initialized.\n"));
|
---|
46 | if(fConsoleApp) {
|
---|
47 | dprintf(("Console application!\n"));
|
---|
48 |
|
---|
49 | APIRET rc = ConsoleInit(); /* initialize console subsystem */
|
---|
50 | if (rc != NO_ERROR) /* check for errors */
|
---|
51 | dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
|
---|
52 | }
|
---|
53 | }
|
---|
54 | //******************************************************************************
|
---|
55 | //******************************************************************************
|
---|
56 | Win32Exe::Win32Exe(HINSTANCE hinstance, int NameTableId, int Win32TableId) :
|
---|
57 | Win32Image(hinstance, NameTableId, Win32TableId),
|
---|
58 | fConsoleApp(FALSE), cmdline(NULL), OS2InstanceHandle(-1)
|
---|
59 | {
|
---|
60 | HMInitialize(); /* store standard handles within HandleManager */
|
---|
61 | dprintf(("KERNEL32/WINEXE: HandleManager Initialized.\n"));
|
---|
62 |
|
---|
63 | if(GET_CONSOLE(Win32TableId) == 1) {//console app
|
---|
64 | dprintf(("Console application!\n"));
|
---|
65 |
|
---|
66 | fConsoleApp = TRUE;
|
---|
67 | APIRET rc = ConsoleInit(); /* initialize console subsystem */
|
---|
68 | if (rc != NO_ERROR) /* check for errors */
|
---|
69 | dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
|
---|
70 | }
|
---|
71 | WinExe = this;
|
---|
72 | }
|
---|
73 | //******************************************************************************
|
---|
74 | //******************************************************************************
|
---|
75 | Win32Exe::~Win32Exe()
|
---|
76 | {
|
---|
77 | Win32Dll::deleteAll();
|
---|
78 | WinExe = NULL;
|
---|
79 | }
|
---|
80 | //******************************************************************************
|
---|
81 | //******************************************************************************
|
---|
82 | ULONG Win32Exe::start()
|
---|
83 | {
|
---|
84 | if(getenv("WIN32_IOPL2")) {
|
---|
85 | io_init1();
|
---|
86 | }
|
---|
87 | dprintf(("Start executable %X\n", WinExe));
|
---|
88 |
|
---|
89 | fExeStarted = TRUE;
|
---|
90 | return ((WIN32EXEENTRY)entryPoint)();
|
---|
91 | }
|
---|
92 | //******************************************************************************
|
---|
93 | //******************************************************************************
|
---|
94 |
|
---|