Changeset 5956 for trunk/src


Ignore:
Timestamp:
Jun 11, 2001, 12:00:04 AM (24 years ago)
Author:
sandervl
Message:

Launch win16 loader for NE apps

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/peldr/pe.cpp

    r5494 r5956  
    1 /* $Id: pe.cpp,v 1.27 2001-04-10 17:09:08 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.28 2001-06-10 22:00:04 sandervl Exp $ */
    22
    33/*
    44 * PELDR main exe loader code
    55 *
    6  * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
     6 * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl)
    77 *
    88 * Command line options:
     
    1919#define INCL_DOSMISC             /* DOS Miscellanous values  */
    2020#define INCL_DOSMODULEMGR
     21#define INCL_DOSSESMGR
    2122#define INCL_WIN
    2223#include <os2.h>
     
    4344char szNoKernel32Msg[]  = "Can't load/find kernel32.dll (rc=%d, module %s)";
    4445char szDosInfoBlocks[]  = "DosInfoBlocks failed!";
     46char szErrDosStartSession[] = "Failed to start win16 session (rc=%d)";
    4547
    4648char fullpath[CCHMAXPATH];
     
    7375BOOL        fConsoleApp          = FALSE;
    7476
    75 void AllocateExeMem(char *filename);
     77BOOL AllocateExeMem(char *filename, BOOL *fNEExe);
    7678
    7779//******************************************************************************
     
    8486 char   fullpath[CCHMAXPATH];
    8587 char   errorMod[CCHMAXPATH];
     88 char  *pszErrorMsg = NULL;
    8689 APIRET  rc;
    8790 HMODULE hmodPMWin = 0, hmodKernel32 = 0;
     
    8992 PPIB   ppib;
    9093 char  *cmdline, *win32cmdline, *peoptions, *newcmdline;
    91  BOOL   fQuote = FALSE, fVioConsole;
     94 BOOL   fQuote = FALSE, fVioConsole, fIsNEExe;
    9295 int    nrTries = 1;
    9396
     
    162165        else {//should never happen!
    163166filenotfound:
    164                 rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
    165                 rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32MESSAGEBOX, NULL, (PFN *)&MyWinMessageBox);
    166                 MyWinMessageBox(HWND_DESKTOP, NULL, szDosInfoBlocks, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    167                 goto fail;
     167                pszErrorMsg = szDosInfoBlocks;
     168                goto failerror;
    168169        }
    169         AllocateExeMem(exeName);
     170        AllocateExeMem(exeName, &fIsNEExe);
     171        if(fIsNEExe) {
     172            STARTDATA sdata = {0};
     173            ULONG idSession;
     174            PID   pid;
     175            sdata.Length    = sizeof(sdata);
     176            sdata.PgmName   = "w16odin.exe";
     177            strcpy(fullpath, exeName);
     178            strcat(fullpath, " ");
     179            strcat(fullpath, win32cmdline);
     180            sdata.PgmInputs = fullpath;
     181            sdata.SessionType = SSF_TYPE_WINDOWEDVDM;
     182            rc = DosStartSession(&sdata, &idSession, &pid);
     183            if(rc) {
     184                sprintf(fullpath, szErrDosStartSession, rc);
     185                pszErrorMsg = fullpath;
     186                goto failerror;
     187            }
     188            return 0;
     189        }
    170190  }
    171191
     
    227247  if(hmodKernel32)      DosFreeModule(hmodKernel32);
    228248  return(1);
     249
     250failerror:
     251  rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
     252  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
     253  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32TERMINATE, NULL, (PFN *)&MyWinTerminate);
     254  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32CREATEMSGQUEUE, NULL, (PFN *)&MyWinCreateMsgQueue);
     255  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32DESTROYMSGQUEUE, NULL, (PFN *)&MyWinDestroyMsgQueue);
     256  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32MESSAGEBOX, NULL, (PFN *)&MyWinMessageBox);
     257  if(rc == 0) {
     258      if ((hab = MyWinInitialize(0)) == 0L) /* Initialize PM     */
     259        goto fail;
     260
     261      hmq = MyWinCreateMsgQueue(hab, 0);
     262
     263      MyWinMessageBox(HWND_DESKTOP, NULL, pszErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     264  }
     265  if(hmq) MyWinDestroyMsgQueue( hmq );             /* Tidy up...                   */
     266  if(hab) MyWinTerminate( hab );                   /* Terminate the application    */
     267  if(hmodPMWin)         DosFreeModule(hmodPMWin);
     268  return 1;
    229269}
    230270//******************************************************************************
     
    233273//     a very low virtual address. (which is exactly what we want)
    234274//******************************************************************************
    235 void AllocateExeMem(char *filename)
     275BOOL AllocateExeMem(char *filename, BOOL *fNEExe)
    236276{
    237277 HFILE  dllfile = 0;
     
    248288 ULONG  diff, i, baseAddress;
    249289 ULONG  ulSysinfo, flAllocMem = 0;
    250 
     290 BOOL   ret = FALSE;
     291
     292  *fNEExe = FALSE;
    251293  strcpy(szFileName, filename);
    252294
     
    291333  }
    292334  if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) {
     335        if(LOWORD(signature) == IMAGE_OS2_SIGNATURE) {
     336            *fNEExe = TRUE;
     337        }
    293338        goto end;
    294339  }
     
    312357  }
    313358  else {
    314         if(flAllocMem == 0) {
    315                 goto end; //no support for > 512 MB
     359        if(flAllocMem == 0) {
     360            goto end; //no support for > 512 MB
    316361        }
    317362  }
     
    346391        DosFreeMem((PVOID)memallocs[i]);
    347392  }
     393  ret = TRUE;
    348394end:
    349395  if(dllfile) DosClose(dllfile);
    350   return;
     396  return ret;
    351397}
    352398//******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.