| 1 | /* $Id: winexebase.cpp,v 1.4 2000-01-06 20:07:10 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 | BOOL fExeStarted = FALSE;
|
|---|
| 37 | Win32ExeBase *WinExe = NULL;
|
|---|
| 38 |
|
|---|
| 39 | //******************************************************************************
|
|---|
| 40 | //******************************************************************************
|
|---|
| 41 | BOOL IsExeStarted()
|
|---|
| 42 | {
|
|---|
| 43 | return fExeStarted;
|
|---|
| 44 | }
|
|---|
| 45 | //******************************************************************************
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | Win32ExeBase::Win32ExeBase(HINSTANCE hInstance)
|
|---|
| 48 | : Win32ImageBase(hInstance),
|
|---|
| 49 | fConsoleApp(FALSE),
|
|---|
| 50 | cmdLineA(NULL), cmdLineW(NULL)
|
|---|
| 51 | {
|
|---|
| 52 | WinExe = this;
|
|---|
| 53 | }
|
|---|
| 54 | //******************************************************************************
|
|---|
| 55 | //******************************************************************************
|
|---|
| 56 | Win32ExeBase::~Win32ExeBase()
|
|---|
| 57 | {
|
|---|
| 58 | Win32DllBase::deleteAll();
|
|---|
| 59 | WinExe = NULL;
|
|---|
| 60 | if(cmdLineA)
|
|---|
| 61 | free(cmdLineA);
|
|---|
| 62 | if(cmdLineW)
|
|---|
| 63 | free(cmdLineW);
|
|---|
| 64 | }
|
|---|
| 65 | //******************************************************************************
|
|---|
| 66 | //******************************************************************************
|
|---|
| 67 | ULONG Win32ExeBase::start()
|
|---|
| 68 | {
|
|---|
| 69 | WINEXCEPTION_FRAME exceptFrame;
|
|---|
| 70 | ULONG rc;
|
|---|
| 71 |
|
|---|
| 72 | if(getenv("WIN32_IOPL2")) {
|
|---|
| 73 | io_init1();
|
|---|
| 74 | }
|
|---|
| 75 | dprintf(("Start executable %X\n", WinExe));
|
|---|
| 76 |
|
|---|
| 77 | fExeStarted = TRUE;
|
|---|
| 78 |
|
|---|
| 79 | //Note: The Win32 exception structure references by FS:[0] is the same
|
|---|
| 80 | // in OS/2
|
|---|
| 81 | OS2SetExceptionHandler((void *)&exceptFrame);
|
|---|
| 82 | SetWin32TIB();
|
|---|
| 83 |
|
|---|
| 84 | //Allocate TLS index for this module
|
|---|
| 85 | tlsAlloc();
|
|---|
| 86 | tlsAttachThread(); //setup TLS (main thread)
|
|---|
| 87 |
|
|---|
| 88 | rc = ((WIN32EXEENTRY)entryPoint)(NULL);
|
|---|
| 89 | RestoreOS2TIB();
|
|---|
| 90 |
|
|---|
| 91 | OS2UnsetExceptionHandler((void *)&exceptFrame);
|
|---|
| 92 |
|
|---|
| 93 | return rc;
|
|---|
| 94 | }
|
|---|
| 95 | //******************************************************************************
|
|---|
| 96 | //******************************************************************************
|
|---|
| 97 | BOOL Win32ExeBase::isDll()
|
|---|
| 98 | {
|
|---|
| 99 | return FALSE;
|
|---|
| 100 | }
|
|---|
| 101 | //******************************************************************************
|
|---|
| 102 | //******************************************************************************
|
|---|
| 103 | void Win32ExeBase::setCommandLine(char *cline)
|
|---|
| 104 | {
|
|---|
| 105 | ULONG cmdlength = strlen(cline) + 1;
|
|---|
| 106 |
|
|---|
| 107 | cmdLineA = (LPSTR)malloc(cmdlength);
|
|---|
| 108 | strcpy(cmdLineA, cline);
|
|---|
| 109 | cmdLineW = (LPWSTR)malloc(cmdlength*sizeof(WCHAR));
|
|---|
| 110 | AsciiToUnicode(cmdLineA, cmdLineW);
|
|---|
| 111 | }
|
|---|
| 112 | //******************************************************************************
|
|---|
| 113 | //******************************************************************************
|
|---|