source: trunk/src/kernel32/winimagepe2lx.cpp@ 1036

Last change on this file since 1036 was 956, checked in by sandervl, 26 years ago

Rewrite for new win32 image classes

File size: 4.6 KB
Line 
1/* $Id: winimagepe2lx.cpp,v 1.1 1999-09-15 23:39:08 sandervl Exp $ */
2
3/*
4 * Win32 PE2LX Image base class
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1998 Knut St. Osmundsen
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12
13#define INCL_DOSFILEMGR /* File Manager values */
14#define INCL_DOSMODULEMGR
15#define INCL_DOSERRORS /* DOS Error values */
16#define INCL_DOSPROCESS /* DOS Process values */
17#define INCL_DOSMISC /* DOS Miscellanous values */
18#define INCL_WIN
19#define INCL_BASE
20#include <os2wrap.h> //Odin32 OS/2 api wrappers
21
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25
26#include <assert.h>
27#include <misc.h>
28#include <win32type.h>
29#include <winimagebase.h>
30#include <winimagepe2lx.h>
31#include <windllbase.h>
32#include <winexebase.h>
33#include <winexepe2lx.h>
34#include <pefile.h>
35#include <unicode.h>
36#include <winres.h>
37#include "oslibmisc.h"
38#include "initterm.h"
39#include <win\virtual.h>
40
41//******************************************************************************
42//******************************************************************************
43Win32Pe2LxImage::Win32Pe2LxImage(HINSTANCE hinstance, int NameTableId, int Win32TableId)
44 : Win32ImageBase(hinstance),
45 NameTable(NULL), Win32Table(NULL), VersionId(0)
46{
47 APIRET rc;
48
49 szFileName[0] = 0;
50
51 char *name = OSLibGetDllName(hinstance);
52 strcpy(szFileName, name);
53 strupr(szFileName);
54 char *dot = strstr(szFileName, ".");
55 while(dot) {
56 char *newdot = strstr(dot+1, ".");
57 if(newdot == NULL) break;
58 dot = newdot;
59 }
60 if(dot)
61 *dot = 0;
62
63 this->NameTableId = NameTableId;
64 this->Win32TableId = Win32TableId;
65
66 if(NameTableId != NO_NAMETABLE) {
67 //Load name table resource
68 rc = DosGetResource(hinstance, RT_RCDATA, NameTableId, (PPVOID)&NameTable);
69 if(rc) {
70 eprintf(("Can't find converted name resource (rc %d)!!\n", rc));
71 return;
72 }
73 }
74 else this->NameTableId = 0;
75
76 //Load win32 id table resource
77 if((Win32TableId & 0xFFFFFF) != NO_LOOKUPTABLE) {
78 rc = DosGetResource(hinstance, RT_RCDATA, Win32TableId, (PPVOID)&Win32Table);
79 if(rc) {
80 eprintf(("Can't find win32 id resource (rc %d)!!\n", rc));
81 return;
82 }
83 }
84 else this->Win32TableId = 0;
85
86}
87//******************************************************************************
88//******************************************************************************
89Win32Pe2LxImage::~Win32Pe2LxImage()
90{
91 Win32Resource *res;
92
93 if(NameTable)
94 DosFreeResource((PVOID)NameTable);
95
96 if(Win32Table)
97 DosFreeResource((PVOID)Win32Table);
98}
99//******************************************************************************
100//******************************************************************************
101int Win32Pe2LxImage::getWin32ResourceId(int id)
102{
103 int nrres, i;
104
105 if(Win32Table == NULL)
106 return(-1);
107
108 nrres = *Win32Table;
109 for(i=1;i<=nrres;i++) {
110 if(id == (Win32Table[i] >> 16)) {
111 dprintf(("OS/2 id -> Win32 id = %d -> %d\n", id, Win32Table[i] & 0xFFFF));
112 return(Win32Table[i] & 0xFFFF);
113 }
114 }
115 dprintf(("Original resource not found!!\n"));
116 return(-1);
117}
118//******************************************************************************
119//******************************************************************************
120int Win32Pe2LxImage::convertNameId(char *lpszName)
121{
122 NameId *curnid;
123 int nrcvtnames, i;
124 char *upname;
125
126 if(NameTable == NULL)
127 return(0);
128
129 nrcvtnames = *(USHORT *)NameTable;
130 curnid = (NameId *)((int)NameTable + sizeof(USHORT));;
131 for(i=0;i<nrcvtnames;i++) {
132 if(strcmp(lpszName, curnid->name) == 0) {
133 return(curnid->id);
134 }
135 curnid = (NameId *)((char *)curnid + sizeof(NameId) + strlen(curnid->name));
136 }
137
138 //try upper case search
139 //SvL: Copy it, since string might be located in readonly object
140
141 upname = (char *)malloc(strlen(lpszName)+1); //CB: Trap with MFC Toolbar/UpDown samples
142 strcpy(upname, lpszName);
143 strupr(upname);
144 dprintf(("Convert %s to id\n", upname));
145 curnid = (NameId *)((int)NameTable + sizeof(USHORT));;
146 for(i=0;i<nrcvtnames;i++) {
147 if(strcmp(upname, curnid->name) == 0) {
148 free(upname);
149 return(curnid->id);
150 }
151 curnid = (NameId *)((char *)curnid + sizeof(NameId) + strlen(curnid->name));
152 }
153 dprintf(("Converted name NOT found!\n"));
154 free(upname);
155
156 return(0);
157}
158//******************************************************************************
159//******************************************************************************
160
Note: See TracBrowser for help on using the repository browser.