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