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

Last change on this file since 3721 was 3625, checked in by sandervl, 25 years ago

resource handling changes

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