source: trunk/src/kernel32/winexelx.cpp@ 3375

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

GetFileAttributes, pe loader & command line fixes

File size: 3.8 KB
Line 
1/* $Id: winexelx.cpp,v 1.6 2000-04-14 22:35:27 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 <wprocess.h>
28#include <odinlx.h>
29
30#include "exceptions.h"
31#include "exceptutil.h"
32#include "cio.h"
33
34#define DBG_LOCALLOG DBG_winexelx
35#include "dbglocal.h"
36
37//******************************************************************************
38//Create LX Exe object and call entrypoint
39//System dlls set EntryPoint to 0
40//******************************************************************************
41BOOL WIN32API RegisterLxExe(WINMAIN EntryPoint, PVOID pResData)
42{
43 APIRET rc;
44 PPIB ppib;
45 PTIB ptib;
46
47 //Signal to TEB management that we're a real OS/2 app and don't
48 //require setting FS to our special win32 selector
49 fIsOS2Image = TRUE;
50
51 if(WinExe != NULL) //should never happen
52 delete(WinExe);
53
54 if(getenv("WIN32_IOPL2")) {
55 io_init1();
56 }
57
58 rc = DosGetInfoBlocks(&ptib, &ppib);
59 if(rc) {
60 return FALSE;
61 }
62
63 Win32LxExe *winexe;
64
65 winexe = new Win32LxExe(ppib->pib_hmte, pResData);
66
67 if(winexe) {
68 char *cmdline;
69 int cmdlen = strlen(ppib->pib_pchcmd);
70
71 cmdlen += strlen(ppib->pib_pchcmd+cmdlen+1);
72 cmdline = (char *)malloc(cmdlen+2); //term. 0 + space
73 strcpy(cmdline, ppib->pib_pchcmd);
74 strcat(cmdline, " ");
75 strcat(cmdline, ppib->pib_pchcmd+strlen(ppib->pib_pchcmd)+1);
76 winexe->setCommandLine(cmdline);
77 free(cmdline);
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//******************************************************************************
90Win32LxExe::Win32LxExe(HINSTANCE hInstance, PVOID pResData)
91 : Win32ImageBase(hInstance),
92 Win32LxImage(hInstance, pResData),
93 Win32ExeBase(hInstance)
94{
95 dprintf(("Win32LxExe ctor: %s", szModule));
96}
97//******************************************************************************
98//******************************************************************************
99//******************************************************************************
100//******************************************************************************
101Win32LxExe::~Win32LxExe()
102{
103}
104//******************************************************************************
105//******************************************************************************
106ULONG Win32LxExe::start()
107{
108 WINEXCEPTION_FRAME exceptFrame;
109 ULONG rc;
110
111 if(getenv("WIN32_IOPL2")) {
112 io_init1();
113 }
114 dprintf(("Start executable %X\n", WinExe));
115
116 fExeStarted = TRUE;
117
118 //Allocate TLS index for this module
119 tlsAlloc();
120 tlsAttachThread(); //setup TLS (main thread)
121
122 //Note: The Win32 exception structure references by FS:[0] is the same
123 // in OS/2
124 OS2SetExceptionHandler((void *)&exceptFrame);
125
126 SetWin32TIB();
127 rc = ((WINMAIN)entryPoint)(hinstance, 0, cmdLineA, SW_SHOWNORMAL_W);
128 RestoreOS2TIB();
129
130 OS2UnsetExceptionHandler((void *)&exceptFrame);
131
132 return rc;
133}
134//******************************************************************************
135//******************************************************************************
Note: See TracBrowser for help on using the repository browser.