Changeset 550 for trunk/src


Ignore:
Timestamp:
Aug 18, 1999, 7:18:01 PM (26 years ago)
Author:
sandervl
Message:

PE loader changes

Location:
trunk/src/kernel32
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/KERNEL32.CPP

    r532 r550  
    1 /* $Id: KERNEL32.CPP,v 1.14 1999-08-17 17:04:51 sandervl Exp $ */
     1/* $Id: KERNEL32.CPP,v 1.15 1999-08-18 17:17:59 sandervl Exp $ */
    22
    33/*
     
    6262  return HMCloseHandle(hHandle);
    6363}
    64 
    65 
    66 //******************************************************************************
    67 HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
    68 {
    69  HANDLE hMod;
    70 
    71   hMod = OS2iGetModuleHandleA( (PSZ) lpszModule);
    72   eprintf(("KERNEL32:  GetModuleHandle %s returned %X\n", lpszModule, hMod));
    73   return(hMod);
    74 }
    75 //******************************************************************************
    76 //******************************************************************************
    77 HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
    78 {
    79  HMODULE rc;
    80  char   *astring;
    81 
    82     astring = UnicodeToAsciiString((LPWSTR)arg1);
    83     rc = O32_GetModuleHandle(astring);
    84     dprintf(("KERNEL32:  OS2GetModuleHandleW %s returned %X\n", astring, rc));
    85     FreeAsciiString(astring);
    86     return(rc);
    87 }
    88 //******************************************************************************
    8964//******************************************************************************
    9065HANDLE WIN32API GetStdHandle(DWORD fdwDevice)
  • trunk/src/kernel32/KERNEL32.DEF

    r546 r550  
    1 ; $Id: KERNEL32.DEF,v 1.21 1999-08-18 13:23:41 phaller Exp $
     1; $Id: KERNEL32.DEF,v 1.22 1999-08-18 17:18:00 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    935935
    936936    ConvertNameId                 = ConvertNameId                 @1200
    937     UpCase                        = UpCase                        @1201
    938937    WriteLog                      = WriteLog                      @1202
    939938    WriteLogError                 = WriteLogError                 @1214
  • trunk/src/kernel32/kernel32exp.def

    r320 r550  
    1 ; $Id: kernel32exp.def,v 1.9 1999-07-17 09:18:38 sandervl Exp $
     1; $Id: kernel32exp.def,v 1.10 1999-08-18 17:18:00 sandervl Exp $
    22
    33;Created by BLAST for IBM's compiler
     
    803803OS2memmove                    @906
    804804ConvertNameId                  @1200
    805 UpCase                         @1201
     805
    806806WriteLog                       @1202
    807807WriteLogError                  @1214
  • trunk/src/kernel32/nameid.cpp

    r120 r550  
    1 /* $Id: nameid.cpp,v 1.5 1999-06-19 10:54:42 sandervl Exp $ */
     1/* $Id: nameid.cpp,v 1.6 1999-08-18 17:18:00 sandervl Exp $ */
    22
    3 /*
    4  *
    5  * Project Odin Software License can be found in LICENSE.TXT
    6  *
    7  */
    83/*
    94 * Resource id to name id conversion procedures
    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 */
     
    2725#include <winexe.h>
    2826#include "os2util.h"
    29 
    30 void UpCase(char *mixedcase);
    3127
    3228/******************************************************************************/
     
    5753//******************************************************************************
    5854//******************************************************************************
    59 void SYSTEM EXPORT UpCase(char *mixedcase)
     55char *StripPath(char *path)
    6056{
    61  int i;
    62 
    63   for(i=0;i<strlen(mixedcase);i++) {
    64         if(mixedcase[i] >= 'a' && mixedcase[i] <= 'z') {
    65                 mixedcase[i] += 'A' - 'a';
    66         }
    67   }
     57  /* @@@PH what does this function do ? Strip the path from a FQFN name ? */
     58  char *pszFilename;
     59 
     60  pszFilename = strrchr(path, '\\');                 /* find rightmost slash */
     61  if (pszFilename != NULL)
     62    return (pszFilename++);              /* return pointer to next character */
     63 
     64  pszFilename = strrchr(path, '/');                  /* find rightmost slash */
     65  if (pszFilename != NULL)
     66    return (pszFilename++);              /* return pointer to next character */
     67 
     68  return (path);                                     /* default return value */
    6869}
    69 /******************************************************************************/
    70 /******************************************************************************/
     70//******************************************************************************
     71//******************************************************************************
    7172ULONG GetOS2ModuleHandle(ULONG hmod)
    7273{
  • trunk/src/kernel32/os2util.cpp

    r492 r550  
    1 /* $Id: os2util.cpp,v 1.7 1999-08-13 17:07:24 sandervl Exp $ */
     1/* $Id: os2util.cpp,v 1.8 1999-08-18 17:18:00 sandervl Exp $ */
    22
    33/*
     
    299299//******************************************************************************
    300300//******************************************************************************
    301 
  • trunk/src/kernel32/os2util.h

    r125 r550  
    1 /* $Id: os2util.h,v 1.5 1999-06-19 17:58:33 sandervl Exp $ */
     1/* $Id: os2util.h,v 1.6 1999-08-18 17:18:00 sandervl Exp $ */
    22
    33/*
     
    3232
    3333char *OS2GetDllName(ULONG hModule);
     34
     35char *StripPath(char *path);
    3436
    3537HMODULE OS2iGetModuleHandleA(PSZ pszModule);
  • trunk/src/kernel32/windll.cpp

    r544 r550  
    1 /* $Id: windll.cpp,v 1.9 1999-08-18 12:24:16 sandervl Exp $ */
     1/* $Id: windll.cpp,v 1.10 1999-08-18 17:18:00 sandervl Exp $ */
    22
    33/*
     
    2929#include <wprocess.h>
    3030#include "cio.h"
    31 #include "os2util.h"
    3231
    3332/***********************************
     
    4746  head = this;
    4847
    49   strcpy(szModule, StripPath(szFileName));
    50   UpCase(szModule);
    51   char *dot = strstr(szModule, ".");
    52   while(dot) {
    53         char *newdot = strstr(dot+1, ".");
    54         if(newdot == NULL)      break;
    55         dot = newdot;
    56   }
    57   if(dot)
    58         *dot = 0;
    5948  dprintf(("Win32Dll::Win32Dll %s %s", szFileName, szModule));
    6049}
     
    7160  head = this;
    7261
    73   char *name = OS2GetDllName(hinstance);
    74   strcpy(szModule, name);
    75   UpCase(szModule);
    76   char *dot = strstr(szModule, ".");
    77   while(dot) {
    78         char *newdot = strstr(dot+1, ".");
    79         if(newdot == NULL)      break;
    80         dot = newdot;
    81   }
    82   if(dot)
    83         *dot = 0;
    84 
    8562  dprintf(("Win32Dll::Win32Dll %s", szModule));
    8663}
     
    9269  dllEntryPoint = DllEntryPoint;
    9370  fUnloaded     = FALSE;
    94 
    95   char *name = OS2GetDllName(hinstance);
    96   strcpy(szModule, name);
    97   UpCase(szModule);
    98   char *dot = strstr(szModule, ".");
    99   while(dot) {
    100         char *newdot = strstr(dot+1, ".");
    101         if(newdot == NULL)      break;
    102         dot = newdot;
    103   }
    104   if(dot)
    105         *dot = 0;
    10671
    10772  Win32Image::OS2ImageInit(hinstance, NameTableId, Win32TableId);
     
    208173
    209174  strcpy(szModule, szFileName);
    210   UpCase(szModule);
     175  strupr(szModule);
    211176  dot = strstr(szModule, ".");
    212177  if(dot)
     
    427392 Win32Dll *dll = head;
    428393 char szDllName[CCHMAXPATH];
    429  char *dot;
     394 char *dot, *temp;
    430395
    431396  dprintf(("findModule %s", dllname));
    432   strcpy(szDllName, dllname);
    433   UpCase(szDllName);
     397
     398  strcpy(szDllName, StripPath(dllname));
     399  strupr(szDllName);
    434400  dot = strstr(szDllName, ".");
    435401  if(dot)
     
    476442//******************************************************************************
    477443//******************************************************************************
    478 char *Win32Dll::StripPath(char *path)
    479 {
    480   /* @@@PH what does this function do ? Strip the path from a FQFN name ? */
    481   char *pszFilename;
    482  
    483   pszFilename = strrchr(path, '\\');                 /* find rightmost slash */
    484   if (pszFilename != NULL)
    485     return (pszFilename++);              /* return pointer to next character */
    486  
    487   pszFilename = strrchr(path, '/');                  /* find rightmost slash */
    488   if (pszFilename != NULL)
    489     return (pszFilename++);              /* return pointer to next character */
    490  
    491   return (path);                                     /* default return value */
    492  
    493 #if 0
    494   char *fname = path, *prevname = path-1;
    495  
    496   while(TRUE)
    497   {
    498     @@@PH causes endless loop here !
    499     fname = strchr(fname, '\\');
    500     if(fname == NULL)
    501       break;
    502    
    503     prevname = fname;
    504   }
    505   return(prevname+1);
    506 #endif
    507 }
    508 /******************************************************************************/
    509 /******************************************************************************/
    510444Win32Dll *Win32Dll::head = NULL;
  • trunk/src/kernel32/winimage.cpp

    r544 r550  
    1 /* $Id: winimage.cpp,v 1.10 1999-08-18 12:24:16 sandervl Exp $ */
     1/* $Id: winimage.cpp,v 1.11 1999-08-18 17:18:01 sandervl Exp $ */
    22
    33/*
     
    66 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
    77 * Copyright 1998 Knut St. Osmundsen
    8  *
    98 *
    109 * Project Odin Software License can be found in LICENSE.TXT
     
    3534#include "unicode.h"
    3635#include "winres.h"
     36#include "os2util.h"
    3737
    3838char szErrorTitle[]     = "Win32 for OS/2";
     
    5858Win32Image::Win32Image(char *szFileName) :
    5959    errorState(NO_ERROR), entryPoint(0), nrsections(0), imageSize(0),
    60     imageVirtBase(-1), baseAddress(0), realBaseAddress(0), imageVirtEnd(0),
     60    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    6161    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    6262    szFileName(NULL), NameTable(NULL), Win32Table(NULL), fullpath(NULL),
     
    7373    foutInit = TRUE;
    7474  }
    75   hinstance = (HINSTANCE)this;
    7675  this->szFileName = szFileName;
     76
     77  strcpy(szModule, StripPath(szFileName));
     78  strupr(szModule);
     79  char *dot = strstr(szModule, ".");
     80  while(dot) {
     81        char *newdot = strstr(dot+1, ".");
     82        if(newdot == NULL)      break;
     83        dot = newdot;
     84  }
     85  if(dot)
     86        *dot = 0;
     87
    7788#ifdef DEBUG
    7889  magic = MAGIC_WINIMAGE;
     
    8394Win32Image::Win32Image(HINSTANCE hinstance, int NameTableId, int Win32TableId) :
    8495    errorState(NO_ERROR), entryPoint(0), nrsections(0), imageSize(0),
    85     imageVirtBase(-1), baseAddress(0), realBaseAddress(0), imageVirtEnd(0),
     96    imageVirtBase(-1), realBaseAddress(0), imageVirtEnd(0),
    8697    nrNameExports(0), nrOrdExports(0), nameexports(NULL), ordexports(NULL),
    8798    szFileName(NULL), NameTable(NULL), Win32Table(NULL), fullpath(NULL),
     
    93104#endif
    94105  OS2ImageInit(hinstance, NameTableId, Win32TableId);
     106
     107  char *name = OS2GetDllName(hinstance);
     108  strcpy(szModule, name);
     109  strupr(szModule);
     110  char *dot = strstr(szModule, ".");
     111  while(dot) {
     112        char *newdot = strstr(dot+1, ".");
     113        if(newdot == NULL)      break;
     114        dot = newdot;
     115  }
     116  if(dot)
     117        *dot = 0;
    95118}
    96119//******************************************************************************
     
    378401  }
    379402  fout << "*************************PE SECTIONS END **************************" << endl;
    380   imageSize += (imageVirtBase - oh.ImageBase);
     403  imageSize += imageVirtBase - oh.ImageBase;
    381404  fout << "Total size of Image " << imageSize << endl;
    382405  fout << "imageVirtBase       " << imageVirtBase << endl;
    383406  fout << "imageVirtEnd        " << imageVirtEnd << endl;
    384407
     408  //In case there are any gaps between sections, adjust size
    385409  if(imageSize != imageVirtEnd - oh.ImageBase) {
    386410        fout << "imageSize != imageVirtEnd - oh.ImageBase!" << endl;
     
    391415        return(FALSE);
    392416  }
    393   fout << "OS/2 base address " << baseAddress << endl;
    394   if(storeSections() == FALSE) {
     417  fout << "OS/2 base address " << realBaseAddress << endl;
     418  if(storeSections((char *)win32file) == FALSE) {
    395419        fout << "Failed to store sections, rc " << errorState << endl;
    396420        return(FALSE);
    397421  }
    398   entryPoint = baseAddress + oh.AddressOfEntryPoint;
     422  entryPoint = realBaseAddress + oh.AddressOfEntryPoint;
    399423
    400424  if(tlsDir != NULL) {
     
    447471        pResDir = (PIMAGE_RESOURCE_DIRECTORY)ImageDirectoryOffset(win32file, IMAGE_DIRECTORY_ENTRY_RESOURCE);
    448472  }
     473
     474  //SvL: Use pointer to image header as module handle now. Some apps needs this
     475  hinstance = (HINSTANCE)realBaseAddress;
     476
    449477  //set final memory protection flags (storeSections sets them to read/write)
    450478  if(setMemFlags() == FALSE) {
     
    474502  virtsize   = ((virtsize - 1) & ~0xFFF) + PAGE_SIZE;
    475503  imageSize += virtsize;
    476   section[nrsections].virtualsize    = virtsize;
     504  section[nrsections].virtualsize = virtsize;
    477505
    478506  if(virtaddress < imageVirtBase)
    479507        imageVirtBase = virtaddress;
    480508  if(virtaddress + virtsize > imageVirtEnd)
    481         imageVirtEnd = virtaddress + virtsize;
     509        imageVirtEnd  = virtaddress + virtsize;
    482510
    483511  nrsections++;
     
    488516{
    489517 APIRET rc;
     518 ULONG  baseAddress;
    490519
    491520  if(fh.Characteristics & IMAGE_FILE_RELOCS_STRIPPED) {
     
    525554//******************************************************************************
    526555#define FALLOC_SIZE (1024*1024)
     556//NOTE: Needs testing (while loop)
     557//TODO: Free unused (parts of) reservedMem
    527558//******************************************************************************
    528559BOOL Win32Image::allocFixedMem(ULONG reservedMem)
    529560{
    530561 ULONG  address = 0;
    531  ULONG  lastaddress = 0;
    532  ULONG  firstaddress = 0;
    533  ULONG  diff, i;
     562 ULONG  *memallocs;
     563 ULONG  alloccnt = 0;
     564 ULONG  diff, i, baseAddress;
    534565 APIRET rc;
    535566
    536   baseAddress = realBaseAddress = 0;
     567  realBaseAddress = 0;
    537568 
    538569  if(reservedMem && reservedMem <= oh.ImageBase &&
     
    541572        //ok, it fits perfectly
    542573        realBaseAddress = oh.ImageBase;
    543         baseAddress = oh.ImageBase;
    544574        return TRUE;
     575  }
     576
     577  //Reserve enough space to store 4096 pointers to 1MB memory chunks
     578  memallocs = (ULONG *)malloc(4096*sizeof(ULONG *));
     579  if(memallocs == NULL) {
     580        fout << "allocFixedMem: MALLOC FAILED for memallocs" << endl;
     581        return FALSE;
    545582  }
    546583
     
    548585        rc = DosAllocMem((PPVOID)&address, FALLOC_SIZE, PAG_READ);
    549586        if(rc) break;
    550 
    551         if(firstaddress == 0)
    552                 firstaddress = address;
    553587
    554588        fout << "DosAllocMem returned " << address << endl;
     
    556590                if(address > oh.ImageBase) {//we've passed it!
    557591                        DosFreeMem((PVOID)address);
    558                         return(FALSE);
     592                        break;
    559593                }
    560594                //found the right address
    561595                DosFreeMem((PVOID)address);
    562                 //align at 64 kb boundary
    563                 realBaseAddress = oh.ImageBase & 0xFFFF0000;
    564                 diff = realBaseAddress - address;
     596
     597                diff = address - oh.ImageBase;
    565598                if(diff) {
    566599                        rc = DosAllocMem((PPVOID)&address, diff, PAG_READ);
     
    570603                if(rc) break;
    571604
    572                 if(baseAddress != realBaseAddress) {
    573                         fout << "baseAddress != realBaseAddress!!" << endl;
    574                         break;
    575                 }
    576605                if(diff) DosFreeMem((PVOID)address);
    577606
    578                 address = realBaseAddress;
    579607                realBaseAddress = baseAddress;
    580                 baseAddress = oh.ImageBase;
    581608                break;
    582609        }
    583         lastaddress = address;
    584   }
    585   while(firstaddress <= lastaddress) {
    586         DosFreeMem((PVOID)firstaddress);
    587         firstaddress += FALLOC_SIZE;
    588   }
    589   if(baseAddress == 0) //Let me guess.. MS Office app?
     610        memallocs[alloccnt++] = address;
     611  }
     612  for(i=0;i<alloccnt;i++) {
     613        DosFreeMem((PVOID)memallocs[i]);
     614  }
     615  free(memallocs);
     616
     617  if(realBaseAddress == 0) //Let me guess.. MS Office app?
    590618        return(FALSE);
    591619
     
    594622//******************************************************************************
    595623//******************************************************************************
    596 BOOL Win32Image::storeSections()
     624BOOL Win32Image::storeSections(char *win32file)
    597625{
    598626 int i;
    599627 APIRET rc;
    600628 ULONG  pagFlags = PAG_COMMIT;
    601 
     629 ULONG  headersize;
     630 WINIMAGE_LOOKUP *imgLookup;
     631
     632  //Commit memory for image header
     633  headersize = sizeof(IMAGE_DOS_HEADER) + sizeof(IMAGE_NT_HEADERS) +
     634               sizeof(IMAGE_SECTION_HEADER) * fh.NumberOfSections;
     635
     636  if(headersize + sizeof(WINIMAGE_LOOKUP) < PAGE_SIZE) {
     637        headersize = PAGE_SIZE;
     638  }
     639  else {//ooops, just in case this doesn't work
     640        fout << "ERROR: storeSections: header too big!!!!!! Fatal error" << endl;
     641        return FALSE;
     642  }
     643
     644  rc = DosSetMem((PVOID)realBaseAddress, headersize, pagFlags | PAG_WRITE | PAG_READ);
     645  if(rc) {
     646        fout << "DosSetMem failed for Image header! " << rc << endl;
     647        return FALSE;
     648  }
     649  // Store the NT header at the load addr
     650  memcpy((char *)realBaseAddress, win32file, sizeof(IMAGE_DOS_HEADER));
     651  memcpy((char *)PE_HEADER(realBaseAddress), PE_HEADER(win32file), sizeof(IMAGE_NT_HEADERS));
     652  memcpy(PE_SECTIONS(realBaseAddress), PE_SECTIONS(win32file),
     653         sizeof(IMAGE_SECTION_HEADER) * fh.NumberOfSections );
     654
     655  imgLookup = WINIMAGE_LOOKUPADDR(realBaseAddress);
     656  imgLookup->image = this;
     657  imgLookup->magic = MAGIC_WINIMAGE;
     658
     659  // Process all the image sections
    602660  for(i=0;i<nrsections;i++) {
    603         section[i].realvirtaddr = baseAddress + (section[i].virtaddr - oh.ImageBase);
     661        section[i].realvirtaddr = realBaseAddress + (section[i].virtaddr - oh.ImageBase);
    604662  }
    605663  for(i=0;i<nrsections;i++) {
     
    735793 ULONG *fixup;
    736794
    737   fixup   = (ULONG *)(fixupaddr - oh.ImageBase + baseAddress);
     795  fixup   = (ULONG *)(fixupaddr - oh.ImageBase + realBaseAddress);
    738796  orgaddr = *fixup;
    739   *fixup  = baseAddress + (*fixup - oh.ImageBase);
     797  *fixup  = realBaseAddress + (*fixup - oh.ImageBase);
    740798}
    741799//******************************************************************************
     
    746804 USHORT *fixup;
    747805
    748   fixup   = (USHORT *)(fixupaddr - oh.ImageBase + baseAddress);
     806  fixup   = (USHORT *)(fixupaddr - oh.ImageBase + realBaseAddress);
    749807  orgaddr = *fixup;
    750808  if(fHighFixup) {
    751         *fixup  += (USHORT)((baseAddress - oh.ImageBase) >> 16);
     809        *fixup  += (USHORT)((realBaseAddress - oh.ImageBase) >> 16);
    752810  }
    753811  else {
    754         *fixup  += (USHORT)((baseAddress - oh.ImageBase) & 0xFFFF);
     812        *fixup  += (USHORT)((realBaseAddress - oh.ImageBase) & 0xFFFF);
    755813  }
    756814}
     
    762820 ULONG  apiaddr;
    763821
    764   import  = (ULONG *)(impaddr - oh.ImageBase + baseAddress);
     822  import  = (ULONG *)(impaddr - oh.ImageBase + realBaseAddress);
    765823  apiaddr = WinDll->getApi(ordinal);
    766824  if(apiaddr == 0) {
     
    777835 ULONG  apiaddr;
    778836
    779   import = (ULONG *)(impaddr - oh.ImageBase + baseAddress);
     837  import = (ULONG *)(impaddr - oh.ImageBase + realBaseAddress);
    780838  apiaddr = WinDll->getApi(impname);
    781839  if(apiaddr == 0) {
     
    893951        free(tmp);
    894952  }
    895   curnameexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
     953  curnameexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
    896954  curnameexport->ordinal  = ordinal;
    897955  *(ULONG *)curnameexport->name = 0;
     
    912970        curordexport = ordexports;
    913971  }
    914   curordexport->virtaddr = baseAddress + (virtaddr - oh.ImageBase);
     972  curordexport->virtaddr = realBaseAddress + (virtaddr - oh.ImageBase);
    915973  curordexport->ordinal  = ordinal;
    916974  curordexport++;
     
    12411299  return(0);
    12421300}
    1243 //******************************************************************************
    1244 //******************************************************************************
     1301/******************************************************************************/
     1302/******************************************************************************/
    12451303/*heximal(decimal) KSO Sun 24.05.1998*/
    12461304char szHexBuffer[30];
  • trunk/src/kernel32/winmod.cpp

    r120 r550  
    1 /* $Id: winmod.cpp,v 1.5 1999-06-19 10:54:44 sandervl Exp $ */
     1/* $Id: winmod.cpp,v 1.6 1999-08-18 17:18:01 sandervl Exp $ */
    22
    33/*
     
    7171  upname = (char *)malloc(strlen(lpszName)+1); //CB: Trap with MFC Toolbar/UpDown samples
    7272  strcpy(upname, lpszName);
    73   UpCase(upname);
     73  strupr(upname);
    7474  dprintf(("Convert %s to id\n", upname));
    7575  curnid     = (NameId *)((int)NameTable + sizeof(USHORT));;
  • trunk/src/kernel32/wprocess.cpp

    r544 r550  
    1 /* $Id: wprocess.cpp,v 1.21 1999-08-18 12:24:17 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.22 1999-08-18 17:18:01 sandervl Exp $ */
    22
    33/*
     
    440440  return hDll;
    441441}
    442 
    443 
    444442//******************************************************************************
    445443//******************************************************************************
     
    452450  hDll = O32_LoadLibrary(lpszLibFile);
    453451  if(hDll) {
    454     return hDll;    //converted dll or win32k took care of it
     452        return hDll;    //converted dll or win32k took care of it
    455453  }
    456454
     
    597595    if(rc)      AsciiToUnicode(asciifilename, lpFileName);
    598596    free(asciifilename);
     597    return(rc);
     598}
     599//******************************************************************************
     600//NOTE: GetModuleHandleA does NOT support files with multiple dots (i.e.
     601//      very.weird.exe)
     602//******************************************************************************
     603HANDLE WIN32API GetModuleHandleA(LPCTSTR lpszModule)
     604{
     605 HANDLE    hMod;
     606 Win32Dll *windll;
     607 char      szModule[CCHMAXPATH];
     608 BOOL      fDllModule = FALSE;
     609
     610  if(lpszModule == NULL) {
     611        hMod = WinExe->getInstanceHandle();
     612  }
     613  else {
     614        strcpy(szModule, StripPath((char *)lpszModule));
     615        strupr(szModule);
     616        if(strstr(szModule, ".DLL")) {
     617                fDllModule = TRUE;
     618        }
     619        else {
     620                if(!strstr(szModule, ".")) {
     621                        //if there's no extension or trainling dot, we
     622                        //assume it's a dll (see Win32 SDK docs)
     623                        fDllModule = TRUE;
     624                }
     625        }
     626        char *dot = strstr(szModule, ".");
     627        if(dot)
     628                *dot = 0;
     629
     630        if(!fDllModule && !strcmpi(lpszModule, WinExe->getModuleName())) {
     631                hMod = WinExe->getInstanceHandle();
     632        }
     633        else {
     634                windll = Win32Dll::findModule(szModule);
     635                if(windll) {
     636                        hMod = windll->getInstanceHandle();
     637                }
     638                else    hMod = OS2iGetModuleHandleA( (PSZ) lpszModule);
     639        }
     640  }
     641
     642  eprintf(("KERNEL32:  GetModuleHandle %s returned %X\n", lpszModule, hMod));
     643  return(hMod);
     644}
     645//******************************************************************************
     646//******************************************************************************
     647HMODULE WIN32API GetModuleHandleW(LPCWSTR arg1)
     648{
     649 HMODULE rc;
     650 char   *astring;
     651
     652    astring = UnicodeToAsciiString((LPWSTR)arg1);
     653    rc = GetModuleHandleA(astring);
     654    dprintf(("KERNEL32:  OS2GetModuleHandleW %s returned %X\n", astring, rc));
     655    FreeAsciiString(astring);
    599656    return(rc);
    600657}
Note: See TracChangeset for help on using the changeset viewer.