source: trunk/src/kernel32/winimagelx.cpp@ 3399

Last change on this file since 3399 was 2802, checked in by sandervl, 26 years ago

Added new logging feature

File size: 3.8 KB
Line 
1/* $Id: winimagelx.cpp,v 1.6 2000-02-16 14:22:12 sandervl 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#define DBG_LOCALLOG DBG_winimagelx
41#include "dbglocal.h"
42
43//******************************************************************************
44//******************************************************************************
45Win32LxImage::Win32LxImage(HINSTANCE hInstance, PVOID pResData)
46 : Win32ImageBase(hInstance)
47{
48 APIRET rc;
49
50 szFileName[0] = 0;
51
52 char *name = OSLibGetDllName(hinstance);
53 strcpy(szFileName, name);
54 strupr(szFileName);
55
56 setFullPath(szFileName);
57
58 //Pointer to PE resource tree generates by wrc (or NULL for system dlls)
59 pResDir = (PIMAGE_RESOURCE_DIRECTORY)pResData;
60
61 //ulRVAResourceSection contains the virtual address of the imagebase in the PE header
62 //for the resource section (images loaded by the pe.exe)
63 //For LX images, this is 0 as OffsetToData contains a relative offset
64 ulRVAResourceSection = 0;
65}
66//******************************************************************************
67//******************************************************************************
68Win32LxImage::~Win32LxImage()
69{
70}
71//******************************************************************************
72//******************************************************************************
73ULONG Win32LxImage::getApi(char *name)
74{
75 APIRET rc;
76 ULONG apiaddr;
77
78 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
79 if(rc)
80 {
81 if(rc == ERROR_INVALID_HANDLE)
82 {//handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
83 char szErrName[CCHMAXPATH];
84
85 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
86 if(!rc)
87 rc = DosQueryProcAddr(hinstance, 0, name, (PFN *)&apiaddr);
88 }
89 if(rc) return(0);
90 }
91 return(apiaddr);
92}
93//******************************************************************************
94//******************************************************************************
95ULONG Win32LxImage::getApi(int ordinal)
96{
97 APIRET rc;
98 ULONG apiaddr;
99
100 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
101 if(rc) {
102 if(rc == ERROR_INVALID_HANDLE)
103 {//SvL(?): handle invalid for some silly reason, so load module again (initterm entrypoint not called twice)
104 //KSO: AFAIK you'll have to load the module calling DosLoadModule to use it's handle in API calls.
105 // CPREF->DosGetResource->hmod: ... A value other than zero is a module handle that was returned by DosLoadModule.
106 // You may consider adding a DosLoadModule call during RegisterLxDll or somewhere.
107 char szErrName[CCHMAXPATH];
108
109 rc = DosLoadModule(szErrName, sizeof(szErrName), szFileName, &hinstance);
110 if(!rc)
111 rc = DosQueryProcAddr(hinstance, ordinal, NULL, (PFN *)&apiaddr);
112 }
113 if(rc) return(0);
114 }
115 return(apiaddr);
116}
117//******************************************************************************
118//******************************************************************************
119
Note: See TracBrowser for help on using the repository browser.