- Timestamp:
- Jun 11, 2001, 12:00:04 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/peldr/pe.cpp
r5494 r5956 1 /* $Id: pe.cpp,v 1.2 7 2001-04-10 17:09:08sandervl Exp $ */1 /* $Id: pe.cpp,v 1.28 2001-06-10 22:00:04 sandervl Exp $ */ 2 2 3 3 /* 4 4 * PELDR main exe loader code 5 5 * 6 * Copyright 1998-200 0Sander van Leeuwen (sandervl@xs4all.nl)6 * Copyright 1998-2001 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 8 * Command line options: … … 19 19 #define INCL_DOSMISC /* DOS Miscellanous values */ 20 20 #define INCL_DOSMODULEMGR 21 #define INCL_DOSSESMGR 21 22 #define INCL_WIN 22 23 #include <os2.h> … … 43 44 char szNoKernel32Msg[] = "Can't load/find kernel32.dll (rc=%d, module %s)"; 44 45 char szDosInfoBlocks[] = "DosInfoBlocks failed!"; 46 char szErrDosStartSession[] = "Failed to start win16 session (rc=%d)"; 45 47 46 48 char fullpath[CCHMAXPATH]; … … 73 75 BOOL fConsoleApp = FALSE; 74 76 75 void AllocateExeMem(char *filename);77 BOOL AllocateExeMem(char *filename, BOOL *fNEExe); 76 78 77 79 //****************************************************************************** … … 84 86 char fullpath[CCHMAXPATH]; 85 87 char errorMod[CCHMAXPATH]; 88 char *pszErrorMsg = NULL; 86 89 APIRET rc; 87 90 HMODULE hmodPMWin = 0, hmodKernel32 = 0; … … 89 92 PPIB ppib; 90 93 char *cmdline, *win32cmdline, *peoptions, *newcmdline; 91 BOOL fQuote = FALSE, fVioConsole ;94 BOOL fQuote = FALSE, fVioConsole, fIsNEExe; 92 95 int nrTries = 1; 93 96 … … 162 165 else {//should never happen! 163 166 filenotfound: 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; 168 169 } 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 } 170 190 } 171 191 … … 227 247 if(hmodKernel32) DosFreeModule(hmodKernel32); 228 248 return(1); 249 250 failerror: 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; 229 269 } 230 270 //****************************************************************************** … … 233 273 // a very low virtual address. (which is exactly what we want) 234 274 //****************************************************************************** 235 void AllocateExeMem(char *filename)275 BOOL AllocateExeMem(char *filename, BOOL *fNEExe) 236 276 { 237 277 HFILE dllfile = 0; … … 248 288 ULONG diff, i, baseAddress; 249 289 ULONG ulSysinfo, flAllocMem = 0; 250 290 BOOL ret = FALSE; 291 292 *fNEExe = FALSE; 251 293 strcpy(szFileName, filename); 252 294 … … 291 333 } 292 334 if(doshdr.e_magic != IMAGE_DOS_SIGNATURE || signature != IMAGE_NT_SIGNATURE) { 335 if(LOWORD(signature) == IMAGE_OS2_SIGNATURE) { 336 *fNEExe = TRUE; 337 } 293 338 goto end; 294 339 } … … 312 357 } 313 358 else { 314 315 359 if(flAllocMem == 0) { 360 goto end; //no support for > 512 MB 316 361 } 317 362 } … … 346 391 DosFreeMem((PVOID)memallocs[i]); 347 392 } 393 ret = TRUE; 348 394 end: 349 395 if(dllfile) DosClose(dllfile); 350 return ;396 return ret; 351 397 } 352 398 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.