source: trunk/src/kernel32/winexepe2lx.cpp@ 4502

Last change on this file since 4502 was 4502, checked in by sandervl, 25 years ago

basic support for VIO console command line apps added + FormatMessage addition

File size: 4.7 KB
Line 
1/* $Id: winexepe2lx.cpp,v 1.8 2000-10-20 11:46:48 sandervl Exp $ */
2
3/*
4 * Win32 PE2LX Exe class
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13/*******************************************************************************
14* Defined Constants And Macros *
15*******************************************************************************/
16#define INCL_DOSERRORS /* DOS Error values */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <os2wrap.h> //Odin32 OS/2 api wrappers
23
24#include <stdlib.h> //getenv
25
26#include <misc.h>
27#include <win32type.h>
28#include <winexepe2lx.h>
29
30#include "cio.h" // I/O
31#include "oslibmisc.h" // OSLibGetDllName
32#include "conwin.h" // Windows Header for console only
33#include "console.h"
34
35#define DBG_LOCALLOG DBG_winexepe2lx
36#include "dbglocal.h"
37
38
39/**
40 * Register a Pe2Lx Executable module.
41 * This is called from the TIBFix code in the Pe2Lx exe. It creates the WinExe object from
42 * the instance handle passed in.
43 * @param ulPe2LxVersion Pe2Lx version number.
44 * @param hinstance Module handle.
45 * @param ulReserved Reserved.
46 * @sketch I/O init.
47 * Check that pe2lx version matches the version of kernel32.dll.
48 * Frees WinExe if is not NULL - should never happen!
49 * Write info to the log.
50 * Create Pe2Lx Exe object.
51 * Call start (which calls the entry point).
52 * @status completely implemented.
53 * @author Sander van Leeuwen, knut st. osmundsen
54 */
55void WIN32API RegisterPe2LxExe(ULONG ulPe2LxVersion, HINSTANCE hinstance, ULONG ulReserved)
56{
57 Win32Pe2LxExe *pWinPe2LxExe;
58
59 /* I/O init. */
60 if (getenv("WIN32_IOPL2"))
61 io_init1();
62
63 /* Check that pe2lx version matches the version of kernel32.dll. */
64 CheckVersion(ulPe2LxVersion & ~0x80000000UL, OSLibGetDllName(hinstance));
65
66 /* Frees WinExe if is not NULL - should never happen! */
67 if (WinExe != NULL)
68 {
69 dprintf(("RegisterPe2LxExe: WinExe != NULL\n"));
70 delete(WinExe);
71 }
72
73 /* Write info to the log. */
74 dprintf(("RegisterPe2LxExe: ulPe2LxVersion = %#x\n", ulPe2LxVersion));
75 dprintf(("RegisterPe2LxExe: hinstance = %#x\n", hinstance));
76 dprintf(("RegisterPe2LxExe: ulReserved = %#x\n", ulReserved));
77 dprintf(("RegisterPe2LxExe: name = %s\n", OSLibGetDllName(hinstance)));
78
79 /* Create Pe2Lx Exe object. */
80 pWinPe2LxExe = new Win32Pe2LxExe(hinstance, (ulPe2LxVersion & 0x80000000UL) == 0x80000000UL);
81 if (pWinPe2LxExe == NULL)
82 {
83 eprintf(("RegisterPe2LxExe: new returned a NULL-pointer\n"));
84 return;
85 }
86 if (!pWinPe2LxExe->init())
87 {
88 eprintf(("RegisterPe2LxExe: init-method failed.\n"));
89 delete pWinPe2LxExe;
90 return;
91 }
92
93 /* Call start (which calls the entry point). */
94 /*DebugInt3();*/
95 pWinPe2LxExe->start();
96}
97
98
99/**
100 * Constructor - creates an pe2lx exe object from a module handle to a pe2lx exe module.
101 * @param hinstance Module handle.
102 * @param fWin32k TRUE: Win32k module.
103 * FALSE: Pe2Lx module.
104 * @status completely implmented.
105 * @author Sander van Leeuwen, knut st. osmundsen
106 * @remark Win32Pe2LxImage may throw an exception!
107 */
108Win32Pe2LxExe::Win32Pe2LxExe(HINSTANCE hinstance, BOOL fWin32k)
109 : Win32ImageBase(hinstance),
110 Win32ExeBase(hinstance),
111 Win32Pe2LxImage(hinstance, fWin32k)
112{
113}
114
115
116/**
117 * Destructor - does nothing.
118 * @status completely implemented.
119 * @author Sander van Leeuwen
120 */
121Win32Pe2LxExe::~Win32Pe2LxExe()
122{
123
124}
125
126
127/**
128 * Init object.
129 * Must be called immedeately after the object construction.
130 * @returns Success indicator. (TRUE == success)
131 * @sketch
132 * @status completely implemented.
133 * @author knut st. osmundsen
134 */
135BOOL Win32Pe2LxExe::init()
136{
137 if (Win32Pe2LxImage::init())
138 {
139 fConsoleApp = pNtHdrs->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI;
140
141 /* console app? */
142 if (fConsoleApp)
143 {
144 APIRET rc;
145
146 dprintf(("Console application!\n"));
147
148 rc = iConsoleInit(FALSE); /* initialize console subsystem */
149 if (rc != NO_ERROR) /* check for errors */
150 dprintf(("KERNEL32:Win32Image:Init ConsoleInit failed with %u.\n", rc));
151 }
152 }
153 else
154 return FALSE;
155 return TRUE;
156}
157
Note: See TracBrowser for help on using the repository browser.