| 1 | /* $Id: winimagelx.cpp,v 1.5 1999-11-29 00:04:06 bird Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 LX Image base class
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #define INCL_DOSFILEMGR /* File Manager values */
|
|---|
| 13 | #define INCL_DOSMODULEMGR
|
|---|
| 14 | #define INCL_DOSERRORS /* DOS Error values */
|
|---|
| 15 | #define INCL_DOSPROCESS /* DOS Process values */
|
|---|
| 16 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
|---|
| 17 | #define INCL_WIN
|
|---|
| 18 | #define INCL_BASE
|
|---|
| 19 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 20 |
|
|---|
| 21 | #include <stdio.h>
|
|---|
| 22 | #include <string.h>
|
|---|
| 23 | #include <stdlib.h>
|
|---|
| 24 |
|
|---|
| 25 | #include <assert.h>
|
|---|
| 26 | #include <misc.h>
|
|---|
| 27 | #include <win32type.h>
|
|---|
| 28 | #include <winimagebase.h>
|
|---|
| 29 | #include <winimagelx.h>
|
|---|
| 30 | #include <windllbase.h>
|
|---|
| 31 | #include <winexebase.h>
|
|---|
| 32 | #include <winexelx.h>
|
|---|
| 33 | #include <pefile.h>
|
|---|
| 34 | #include <unicode.h>
|
|---|
| 35 | #include <winres.h>
|
|---|
| 36 | #include "oslibmisc.h"
|
|---|
| 37 | #include "initterm.h"
|
|---|
| 38 | #include <win\virtual.h>
|
|---|
| 39 |
|
|---|
| 40 | //******************************************************************************
|
|---|
| 41 | //******************************************************************************
|
|---|
| 42 | Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData)
|
|---|
| 43 | : Win32ImageBase(hInstance)
|
|---|
| 44 | {
|
|---|
| 45 | APIRET rc;
|
|---|
| 46 |
|
|---|
| 47 | szFileName[0] = 0;
|
|---|
| 48 |
|
|---|
| 49 | char *name = OSLibGetDllName(hinstance);
|
|---|
| 50 | strcpy(szFileName, name);
|
|---|
| 51 | strupr(szFileName);
|
|---|
| 52 |
|
|---|
| 53 | setFullPath(szFileName);
|
|---|
| 54 |
|
|---|
| 55 | //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
|
|---|
| 56 | pResDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
|
|---|
| 57 |
|
|---|
| 58 | //ulRVAResourceSection contains the virtual address of the imagebase in the PE header
|
|---|
| 59 | //for the resource section (images loaded by the pe.exe)
|
|---|
| 60 | //For LX images, this is 0 as OffsetToData contains a relative offset
|
|---|
| 61 | ulRVAResourceSection = 0;
|
|---|
| 62 | }
|
|---|
| 63 | //******************************************************************************
|
|---|
| 64 | //******************************************************************************
|
|---|
| 65 | Win32LxImage::~Win32LxImage()
|
|---|
| 66 | {
|
|---|
| 67 | }
|
|---|
| 68 | //******************************************************************************
|
|---|
| 69 | //******************************************************************************
|
|---|
| 70 | ULONG Win32LxImage::getApi(char *name)
|
|---|
| 71 | {
|
|---|
| 72 | APIRET rc;
|
|---|
| 73 | ULONG apiaddr;
|
|---|
| 74 |
|
|---|
| 75 | rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
|
|---|
| 76 | if(rc)
|
|---|
| 77 | {
|
|---|
| 78 | if(rc == ERROR_INVALID_HANDLE)
|
|---|
| 79 | {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
|
|---|
| 80 | char szErrName[CCHMAXPATH];
|
|---|
| 81 |
|
|---|
| 82 | rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
|
|---|
| 83 | if(!rc)
|
|---|
| 84 | rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
|
|---|
| 85 | }
|
|---|
| 86 | if(rc) return(0);
|
|---|
| 87 | }
|
|---|
| 88 | return(apiaddr);
|
|---|
| 89 | }
|
|---|
| 90 | //******************************************************************************
|
|---|
| 91 | //******************************************************************************
|
|---|
| 92 | ULONG Win32LxImage::getApi(int ordinal)
|
|---|
| 93 | {
|
|---|
| 94 | APIRET rc;
|
|---|
| 95 | ULONG apiaddr;
|
|---|
| 96 |
|
|---|
| 97 | rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
|
|---|
| 98 | if(rc) {
|
|---|
| 99 | if(rc == ERROR_INVALID_HANDLE)
|
|---|
| 100 | {//SvL(?): handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
|
|---|
| 101 | //KSO: AFAIK you'll have to load the module calling DosLoadModule to use it's handle in API calls.
|
|---|
| 102 | // CPREF->DosGetResource->hmod: ... A value other than zero is a module handle that was returned by DosLoadModule.
|
|---|
| 103 | // You may consider adding a DosLoadModule call during RegisterLxDll or somewhere.
|
|---|
| 104 | char szErrName[CCHMAXPATH];
|
|---|
| 105 |
|
|---|
| 106 | rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
|
|---|
| 107 | if(!rc)
|
|---|
| 108 | rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
|
|---|
| 109 | }
|
|---|
| 110 | if(rc) return(0);
|
|---|
| 111 | }
|
|---|
| 112 | return(apiaddr);
|
|---|
| 113 | }
|
|---|
| 114 | //******************************************************************************
|
|---|
| 115 | //******************************************************************************
|
|---|
| 116 |
|
|---|