1 | /* $Id: winexelx.cpp,v 1.8 2000-09-12 19:02:00 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_WIN
|
---|
17 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
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 <win32type.h>
|
---|
25 | #include <winexelx.h>
|
---|
26 | #include <winconst.h>
|
---|
27 | #include <win32api.h>
|
---|
28 | #include <wprocess.h>
|
---|
29 | #include <odinlx.h>
|
---|
30 |
|
---|
31 | #include "exceptions.h"
|
---|
32 | #include "exceptutil.h"
|
---|
33 | #include "cio.h"
|
---|
34 |
|
---|
35 | #define DBG_LOCALLOG DBG_winexelx
|
---|
36 | #include "dbglocal.h"
|
---|
37 |
|
---|
38 | //******************************************************************************
|
---|
39 | //Create LX Exe object and call entrypoint
|
---|
40 | //System dlls set EntryPoint to 0
|
---|
41 | //******************************************************************************
|
---|
42 | BOOL WIN32API RegisterLxExe(WINMAIN EntryPoint, PVOID pResData)
|
---|
43 | {
|
---|
44 | APIRET rc;
|
---|
45 | PPIB ppib;
|
---|
46 | PTIB ptib;
|
---|
47 |
|
---|
48 | //Signal to TEB management that we're a real OS/2 app and don't
|
---|
49 | //require setting FS to our special win32 selector
|
---|
50 | fIsOS2Image = TRUE;
|
---|
51 |
|
---|
52 | if(WinExe != NULL) //should never happen
|
---|
53 | delete(WinExe);
|
---|
54 |
|
---|
55 | if(getenv("WIN32_IOPL2")) {
|
---|
56 | io_init1();
|
---|
57 | }
|
---|
58 |
|
---|
59 | rc = DosGetInfoBlocks(&ptib, &ppib);
|
---|
60 | if(rc) {
|
---|
61 | return FALSE;
|
---|
62 | }
|
---|
63 |
|
---|
64 | Win32LxExe *winexe;
|
---|
65 |
|
---|
66 | winexe = new Win32LxExe(ppib->pib_hmte, pResData);
|
---|
67 |
|
---|
68 | if(winexe) {
|
---|
69 | InitCommandLine(FALSE);
|
---|
70 | winexe->setEntryPoint((ULONG)EntryPoint);
|
---|
71 | winexe->start();
|
---|
72 | }
|
---|
73 | else {
|
---|
74 | eprintf(("Win32LxExe creation failed!\n"));
|
---|
75 | DebugInt3();
|
---|
76 | return FALSE;
|
---|
77 | }
|
---|
78 | return TRUE;
|
---|
79 | }
|
---|
80 | //******************************************************************************
|
---|
81 | //******************************************************************************
|
---|
82 | Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData)
|
---|
83 | : Win32ImageBase(hInstance),
|
---|
84 | Win32LxImage(hInstance, pResData),
|
---|
85 | Win32ExeBase(hInstance)
|
---|
86 | {
|
---|
87 | dprintf(("Win32LxExe ctor: %s", szModule));
|
---|
88 | }
|
---|
89 | //******************************************************************************
|
---|
90 | //******************************************************************************
|
---|
91 | //******************************************************************************
|
---|
92 | //******************************************************************************
|
---|
93 | Win32LxExe::~Win32LxExe()
|
---|
94 | {
|
---|
95 | }
|
---|
96 | //******************************************************************************
|
---|
97 | //******************************************************************************
|
---|
98 | ULONG Win32LxExe::start()
|
---|
99 | {
|
---|
100 | WINEXCEPTION_FRAME exceptFrame;
|
---|
101 | ULONG rc;
|
---|
102 |
|
---|
103 | if(getenv("WIN32_IOPL2")) {
|
---|
104 | io_init1();
|
---|
105 | }
|
---|
106 | dprintf(("Start executable %X\n", WinExe));
|
---|
107 |
|
---|
108 | fExeStarted = TRUE;
|
---|
109 |
|
---|
110 | //Allocate TLS index for this module
|
---|
111 | tlsAlloc();
|
---|
112 | tlsAttachThread(); //setup TLS (main thread)
|
---|
113 |
|
---|
114 | //Note: The Win32 exception structure references by FS:[0] is the same
|
---|
115 | // in OS/2
|
---|
116 | OS2SetExceptionHandler((void *)&exceptFrame);
|
---|
117 |
|
---|
118 | SetWin32TIB();
|
---|
119 | rc = ((WINMAIN)entryPoint)(hinstance, 0, (LPSTR)GetCommandLineA(), SW_SHOWNORMAL_W);
|
---|
120 | RestoreOS2TIB();
|
---|
121 |
|
---|
122 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
---|
123 |
|
---|
124 | return rc;
|
---|
125 | }
|
---|
126 | //******************************************************************************
|
---|
127 | //******************************************************************************
|
---|