source: trunk/src/kernel32/winexelx.cpp

Last change on this file was 22053, checked in by dmik, 13 years ago

kernel32: Initialize console input/output mode for VIO (WINDOWCOMPAT) applications.

This matches the console applications in Windows terms.

File size: 4.1 KB
RevLine 
[10397]1/* $Id: winexelx.cpp,v 1.13 2004-01-15 10:39:10 sandervl Exp $ */
[956]2
3/*
4 * Win32 LX Exe class (compiled in OS/2 using Odin32 api)
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
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 */
[22053]16#define INCL_DOSMODULEMGR
17#define INCL_DOSSESMGR
[956]18#define INCL_WIN
19#include <os2wrap.h> //Odin32 OS/2 api wrappers
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
[21916]23#ifndef __GNUC__
[956]24#include <iostream.h>
25#include <fstream.h>
[21916]26#endif
[956]27#include <misc.h>
28#include <win32type.h>
[21916]29#include "winexelx.h"
[956]30#include <winconst.h>
[4244]31#include <win32api.h>
[956]32#include <wprocess.h>
33#include <odinlx.h>
34
35#include "exceptions.h"
36#include "exceptutil.h"
37
[22053]38#include "console.h"
39
[2802]40#define DBG_LOCALLOG DBG_winexelx
41#include "dbglocal.h"
42
[956]43//******************************************************************************
44//Create LX Exe object and call entrypoint
45//System dlls set EntryPoint to 0
46//******************************************************************************
[978]47BOOL WIN32API RegisterLxExe(WINMAIN EntryPoint, PVOID pResData)
[956]48{
49 APIRET rc;
50 PPIB ppib;
51 PTIB ptib;
52
[22010]53 if (fForceWin32TIB) {
54 fSwitchTIBSel = TRUE;
55 } else {
[21434]56 //Signal to TEB management that we're a real OS/2 app and don't
57 //require setting FS to our special win32 selector
58 fSwitchTIBSel = FALSE;
59 }
[9800]60
61 //We're an OS/2 app
[1221]62 fIsOS2Image = TRUE;
63
[956]64 if(WinExe != NULL) //should never happen
65 delete(WinExe);
66
67 rc = DosGetInfoBlocks(&ptib, &ppib);
68 if(rc) {
69 return FALSE;
70 }
71
72 Win32LxExe *winexe;
73
[978]74 winexe = new Win32LxExe(ppib->pib_hmte, pResData);
[956]75
76 if(winexe) {
[5567]77 InitCommandLine(FALSE);
[956]78 winexe->setEntryPoint((ULONG)EntryPoint);
79 winexe->start();
80 }
81 else {
82 eprintf(("Win32LxExe creation failed!\n"));
83 DebugInt3();
84 return FALSE;
85 }
86 return TRUE;
87}
88//******************************************************************************
89//******************************************************************************
[4236]90Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData)
[956]91 : Win32ImageBase(hInstance),
[978]92 Win32LxImage(hInstance, pResData),
[956]93 Win32ExeBase(hInstance)
94{
95 dprintf(("Win32LxExe ctor: %s", szModule));
[5567]96 hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);
[22053]97
98 PPIB ppib;
99 if (DosGetInfoBlocks(NULL, &ppib) == 0)
100 {
101 char buf[CCHMAXPATH];
102 if (DosQueryModuleName(ppib->pib_hmte, sizeof(buf), buf) == 0)
103 {
104 ULONG Flags;
105 if (DosQueryAppType(buf, &Flags) == 0)
106 {
107 dprintf(("Win32LxExe ctor: app type %x", Flags));
108 if ((Flags & 0x2) == FAPPTYP_WINDOWCOMPAT)
109 iConsoleInit(TRUE);
110 }
111 }
112 }
[956]113}
114//******************************************************************************
115//******************************************************************************
116//******************************************************************************
117//******************************************************************************
118Win32LxExe::~Win32LxExe()
119{
120}
121//******************************************************************************
122//******************************************************************************
123ULONG Win32LxExe::start()
124{
125 WINEXCEPTION_FRAME exceptFrame;
126 ULONG rc;
127
128 dprintf(("Start executable %X\n", WinExe));
129
130 fExeStarted = TRUE;
131
132 //Allocate TLS index for this module
133 tlsAlloc();
134 tlsAttachThread(); //setup TLS (main thread)
135
136 //Note: The Win32 exception structure references by FS:[0] is the same
137 // in OS/2
138 OS2SetExceptionHandler((void *)&exceptFrame);
139
140 SetWin32TIB();
[4244]141 rc = ((WINMAIN)entryPoint)(hinstance, 0, (LPSTR)GetCommandLineA(), SW_SHOWNORMAL_W);
[956]142 RestoreOS2TIB();
143
144 OS2UnsetExceptionHandler((void *)&exceptFrame);
145
[7567]146 ExitProcess(rc);
[956]147 return rc;
148}
149//******************************************************************************
150//******************************************************************************
Note: See TracBrowser for help on using the repository browser.