1 | /* $Id: winexelx.cpp,v 1.13 2004-01-15 10:39:10 sandervl Exp $ */
|
---|
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 */
|
---|
16 | #define INCL_DOSMODULEMGR
|
---|
17 | #define INCL_DOSSESMGR
|
---|
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>
|
---|
23 | #ifndef __GNUC__
|
---|
24 | #include <iostream.h>
|
---|
25 | #include <fstream.h>
|
---|
26 | #endif
|
---|
27 | #include <misc.h>
|
---|
28 | #include <win32type.h>
|
---|
29 | #include "winexelx.h"
|
---|
30 | #include <winconst.h>
|
---|
31 | #include <win32api.h>
|
---|
32 | #include <wprocess.h>
|
---|
33 | #include <odinlx.h>
|
---|
34 |
|
---|
35 | #include "exceptions.h"
|
---|
36 | #include "exceptutil.h"
|
---|
37 |
|
---|
38 | #include "console.h"
|
---|
39 |
|
---|
40 | #define DBG_LOCALLOG DBG_winexelx
|
---|
41 | #include "dbglocal.h"
|
---|
42 |
|
---|
43 | //******************************************************************************
|
---|
44 | //Create LX Exe object and call entrypoint
|
---|
45 | //System dlls set EntryPoint to 0
|
---|
46 | //******************************************************************************
|
---|
47 | BOOL WIN32API RegisterLxExe(WINMAIN EntryPoint, PVOID pResData)
|
---|
48 | {
|
---|
49 | APIRET rc;
|
---|
50 | PPIB ppib;
|
---|
51 | PTIB ptib;
|
---|
52 |
|
---|
53 | if (fForceWin32TIB) {
|
---|
54 | fSwitchTIBSel = TRUE;
|
---|
55 | } else {
|
---|
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 | }
|
---|
60 |
|
---|
61 | //We're an OS/2 app
|
---|
62 | fIsOS2Image = TRUE;
|
---|
63 |
|
---|
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 |
|
---|
74 | winexe = new Win32LxExe(ppib->pib_hmte, pResData);
|
---|
75 |
|
---|
76 | if(winexe) {
|
---|
77 | InitCommandLine(FALSE);
|
---|
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 | //******************************************************************************
|
---|
90 | Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData)
|
---|
91 | : Win32ImageBase(hInstance),
|
---|
92 | Win32LxImage(hInstance, pResData),
|
---|
93 | Win32ExeBase(hInstance)
|
---|
94 | {
|
---|
95 | dprintf(("Win32LxExe ctor: %s", szModule));
|
---|
96 | hinstance = (HINSTANCE)buildHeader(1, 0, IMAGE_SUBSYSTEM_WINDOWS_GUI);
|
---|
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 | }
|
---|
113 | }
|
---|
114 | //******************************************************************************
|
---|
115 | //******************************************************************************
|
---|
116 | //******************************************************************************
|
---|
117 | //******************************************************************************
|
---|
118 | Win32LxExe::~Win32LxExe()
|
---|
119 | {
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | ULONG 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();
|
---|
141 | rc = ((WINMAIN)entryPoint)(hinstance, 0, (LPSTR)GetCommandLineA(), SW_SHOWNORMAL_W);
|
---|
142 | RestoreOS2TIB();
|
---|
143 |
|
---|
144 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
145 |
|
---|
146 | ExitProcess(rc);
|
---|
147 | return rc;
|
---|
148 | }
|
---|
149 | //******************************************************************************
|
---|
150 | //******************************************************************************
|
---|