Changeset 506 for trunk/src/peldr/pe.cpp


Ignore:
Timestamp:
Aug 16, 1999, 3:56:54 PM (26 years ago)
Author:
sandervl
Message:

* empty log message *

File:
1 edited

Legend:

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

    r131 r506  
    1 /* $Id: pe.cpp,v 1.4 1999-06-20 14:02:13 sandervl Exp $ */
     1/* $Id: pe.cpp,v 1.5 1999-08-16 13:54:07 sandervl Exp $ */
    22
    3 /*
    4  *
    5  * Project Odin Software License can be found in LICENSE.TXT
    6  *
    7  */
    83/*
    94 * PELDR main exe loader code
    105 *
    116 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
     7 *
     8 *
     9 * Project Odin Software License can be found in LICENSE.TXT
    1210 *
    1311 */
     
    1614#define INCL_DOSPROCESS          /* DOS Process values       */
    1715#define INCL_DOSMISC             /* DOS Miscellanous values  */
     16#define INCL_DOSMODULEMGR
    1817#define INCL_WIN
    19 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
     18#include <os2.h>
     19#include <bseord.h>
    2020#include <stdio.h>
    2121#include <string.h>
     
    2828#include <windll.h>
    2929#include <wprocess.h>
     30#include "pe.h"
    3031
    3132char INFO_BANNER[]      = "Usage: PE winexe commandline";
     
    4041char fullpath[CCHMAXPATH];
    4142
    42 void UpCase(char *mixedcase);
     43typedef HAB  (* APIENTRY WININITIALIZEPROC)(ULONG flOptions);
     44typedef BOOL (* APIENTRY WINTERMINATEPROC)(HAB hab);
     45typedef HMQ  (* APIENTRY WINCREATEMSGQUEUEPROC) (HAB hab, LONG cmsg);
     46typedef BOOL (* APIENTRY WINDESTROYMSGQUEUEPROC) (HMQ hmq);
     47typedef ULONG (* APIENTRY WINMESSAGEBOXPROC) (HWND hwndParent,
     48                                              HWND hwndOwner,
     49                                              PCSZ  pszText,
     50                                              PCSZ  pszCaption,
     51                                              ULONG idWindow,
     52                                              ULONG flStyle);
     53
     54WININITIALIZEPROC      MyWinInitialize      = 0;
     55WINTERMINATEPROC       MyWinTerminate       = 0;
     56WINCREATEMSGQUEUEPROC  MyWinCreateMsgQueue  = 0;
     57WINDESTROYMSGQUEUEPROC MyWinDestroyMsgQueue = 0;
     58WINMESSAGEBOXPROC      MyWinMessageBox      = 0;
     59
     60WIN32CTOR              CreateWin32Exe       = 0;
    4361
    4462int main(int argc, char *argv[])
     
    5169 PTIB   ptib;
    5270 Win32Exe *WinExe;
    53  APIRET rc;
     71 APIRET  rc;
     72 HMODULE hmodPMWin, hmodKernel32;
    5473
    55   if ((hab = WinInitialize(0)) == 0L) /* Initialize PM     */
    56         return(1);
     74  printf("memory allocated at %X\n", ReserveMem());
    5775
    58   hmq = WinCreateMsgQueue(hab, 0);
     76  rc = DosLoadModule(exeName, sizeof(exeName), "PMWIN.DLL", &hmodPMWin);
     77  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32INITIALIZE, NULL, (PFN *)&MyWinInitialize);
     78  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32TERMINATE, NULL, (PFN *)&MyWinTerminate);
     79  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32CREATEMSGQUEUE, NULL, (PFN *)&MyWinCreateMsgQueue);
     80  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32DESTROYMSGQUEUE, NULL, (PFN *)&MyWinDestroyMsgQueue);
     81  rc = DosQueryProcAddr(hmodPMWin, ORD_WIN32MESSAGEBOX, NULL, (PFN *)&MyWinMessageBox);
    5982
     83  rc = DosLoadModule(exeName, sizeof(exeName), "KERNEL32.DLL", &hmodKernel32);
     84  rc = DosQueryProcAddr(hmodKernel32, 0, "CreateWin32Exe", (PFN *)&CreateWin32Exe);
     85
     86  if ((hab = MyWinInitialize(0)) == 0L) /* Initialize PM     */
     87        return(1);
     88
     89  hmq = MyWinCreateMsgQueue(hab, 0);
     90 
    6091  if(argc < 2) {
    61         WinMessageBox(HWND_DESKTOP, NULL, INFO_BANNER, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    62         return(0);
     92        MyWinMessageBox(HWND_DESKTOP, NULL, INFO_BANNER, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     93        return(0);
    6394  }
    6495
    6596  strcpy(exeName, argv[1]);
    66   UpCase(exeName);
     97  strupr(exeName);
    6798  if(strstr(exeName, ".EXE") == NULL) {
    6899        strcat(exeName, ".EXE");
    69100  }
    70   WinExe = new Win32Exe(exeName);
     101  WinExe = CreateWin32Exe(exeName);
    71102  if(WinExe == NULL) {
    72         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     103        MyWinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szMemErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    73104        return(1);
    74105  }
    75106  rc = DosGetInfoBlocks(&ptib, &ppib);
    76107  if(rc) {
    77         WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
     108        MyWinMessageBox(HWND_DESKTOP, HWND_DESKTOP, szInteralErrorMsg, szErrorTitle, 0, MB_OK | MB_ERROR | MB_MOVEABLE);
    78109        delete WinExe;
    79110        return(1);
     
    107138  delete WinExe;
    108139
    109   if(hmq) WinDestroyMsgQueue( hmq );             /* Tidy up...                   */
    110   WinTerminate( hab );                   /* Terminate the application    */
     140  if(hmq) MyWinDestroyMsgQueue( hmq );             /* Tidy up...                   */
     141  MyWinTerminate( hab );                   /* Terminate the application    */
     142
     143  DosFreeModule(hmodPMWin);
     144  DosFreeModule(hmodKernel32);
    111145  return(0);
    112146}
    113147//******************************************************************************
    114148//******************************************************************************
    115 void UpCase(char *mixedcase)
    116 {
    117  int i;
    118 
    119   for(i=0;i<strlen(mixedcase);i++) {
    120         if(mixedcase[i] >= 'a' && mixedcase[i] <= 'z') {
    121                 mixedcase[i] += 'A' - 'a';
    122         }
    123   }
    124 }
    125 //******************************************************************************
    126 //******************************************************************************
Note: See TracChangeset for help on using the changeset viewer.