source: trunk/src/kernel32/winexebase.cpp@ 3005

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

DosOpen (file handle error) & dll destruction bugfixes

File size: 3.6 KB
Line 
1/* $Id: winexebase.cpp,v 1.6 2000-03-04 19:52:36 sandervl Exp $ */
2
3/*
4 * Win32 exe base class
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 <winexebase.h>
26#include <windllbase.h>
27#include <wprocess.h>
28#include <pefile.h>
29#include "exceptions.h"
30#include "exceptutil.h"
31#include "cio.h"
32
33#include "conwin.h" // Windows Header for console only
34#include "console.h"
35
36#define DBG_LOCALLOG DBG_winexebase
37#include "dbglocal.h"
38
39BOOL fExeStarted = FALSE;
40Win32ExeBase *WinExe = NULL;
41
42//******************************************************************************
43//******************************************************************************
44BOOL IsExeStarted()
45{
46 return fExeStarted;
47}
48//******************************************************************************
49//******************************************************************************
50Win32ExeBase::Win32ExeBase(HINSTANCE hInstance)
51 : Win32ImageBase(hInstance),
52 fConsoleApp(FALSE),
53 cmdLineA(NULL), cmdLineW(NULL)
54{
55 WinExe = this;
56}
57//******************************************************************************
58//******************************************************************************
59Win32ExeBase::~Win32ExeBase()
60{
61 //First delete all dlls that were loaded by the exe or dlls
62 //Then delete all dlls loaded by LoadLibrary (to avoid that we
63 //delete some dlls before the dll, that loaded it, is destroyed)
64 Win32DllBase::deleteAll();
65 Win32DllBase::deleteAll(TRUE);
66
67 WinExe = NULL;
68 if(cmdLineA)
69 free(cmdLineA);
70 if(cmdLineW)
71 free(cmdLineW);
72}
73//******************************************************************************
74//******************************************************************************
75ULONG Win32ExeBase::start()
76{
77 WINEXCEPTION_FRAME exceptFrame;
78 ULONG rc;
79
80 if(getenv("WIN32_IOPL2")) {
81 io_init1();
82 }
83 dprintf(("Start executable %X\n", WinExe));
84
85 fExeStarted = TRUE;
86
87 //Note: The Win32 exception structure references by FS:[0] is the same
88 // in OS/2
89 OS2SetExceptionHandler((void *)&exceptFrame);
90 SetWin32TIB();
91
92 //Allocate TLS index for this module
93 tlsAlloc();
94 tlsAttachThread(); //setup TLS (main thread)
95
96 rc = ((WIN32EXEENTRY)entryPoint)(NULL);
97 RestoreOS2TIB();
98
99 OS2UnsetExceptionHandler((void *)&exceptFrame);
100
101 return rc;
102}
103//******************************************************************************
104//******************************************************************************
105BOOL Win32ExeBase::isDll()
106{
107 return FALSE;
108}
109//******************************************************************************
110//******************************************************************************
111void Win32ExeBase::setCommandLine(char *cline)
112{
113 ULONG cmdlength = strlen(cline) + 1;
114
115 cmdLineA = (LPSTR)malloc(cmdlength);
116 strcpy(cmdLineA, cline);
117 cmdLineW = (LPWSTR)malloc(cmdlength*sizeof(WCHAR));
118 AsciiToUnicode(cmdLineA, cmdLineW);
119}
120//******************************************************************************
121//******************************************************************************
Note: See TracBrowser for help on using the repository browser.