1 | /* $Id: resource.cpp,v 1.16 2000-05-28 16:45:12 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Misc resource procedures
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright 1998 Patrick Haller
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
11 | *
|
---|
12 | */
|
---|
13 | #include <os2win.h>
|
---|
14 | #include <unicode.h>
|
---|
15 | #include <winimagebase.h>
|
---|
16 | #include <winexebase.h>
|
---|
17 | #include <windllbase.h>
|
---|
18 |
|
---|
19 | #define DBG_LOCALLOG DBG_resource
|
---|
20 | #include "dbglocal.h"
|
---|
21 |
|
---|
22 | //******************************************************************************
|
---|
23 | //lpszName = integer id (high word 0), else string (name or "#237")
|
---|
24 | //Can lpszType contain a pointer to a default resource type name?
|
---|
25 | //******************************************************************************
|
---|
26 | HRSRC WIN32API FindResourceA(HINSTANCE hModule, LPCSTR lpszName, LPCSTR lpszType)
|
---|
27 | {
|
---|
28 | Win32ImageBase *module;
|
---|
29 |
|
---|
30 | module = Win32ImageBase::findModule(hModule);
|
---|
31 | if(module == NULL) {
|
---|
32 | dprintf(("FindResourceA Module %X not found (%x %d)", hModule, lpszName, lpszType));
|
---|
33 | return(NULL);
|
---|
34 | }
|
---|
35 | return module->findResourceA(lpszName, (LPSTR)lpszType);
|
---|
36 | }
|
---|
37 | //******************************************************************************
|
---|
38 | //******************************************************************************
|
---|
39 | HRSRC WIN32API FindResourceW(HINSTANCE hModule, LPCWSTR lpszName,
|
---|
40 | LPCWSTR lpszType)
|
---|
41 | {
|
---|
42 | Win32ImageBase *module;
|
---|
43 |
|
---|
44 | module = Win32ImageBase::findModule(hModule);
|
---|
45 | if(module == NULL) {
|
---|
46 | dprintf(("FindResourceW Module %X not found (%x %d)", hModule, lpszName, lpszType));
|
---|
47 | return(NULL);
|
---|
48 | }
|
---|
49 |
|
---|
50 | return module->findResourceW((LPWSTR)lpszName, (LPWSTR)lpszType);
|
---|
51 | }
|
---|
52 | /*****************************************************************************
|
---|
53 | * Name : HRSRC WIN32API FindResourceExA
|
---|
54 | * Purpose : The FindResourceExA function determines the location of the
|
---|
55 | * resource with the specified type, name, and language in the
|
---|
56 | * specified module.
|
---|
57 | * Parameters: HMODULE hModule resource-module handle
|
---|
58 | * LPCSTR lpType pointer to resource type
|
---|
59 | * LPCSTR lpName pointer to resource name
|
---|
60 | * WORD wLanguage resource language
|
---|
61 | * Variables :
|
---|
62 | * Result : If the function succeeds, the return value is a handle to the
|
---|
63 | * specified resource's info block. To obtain a handle to the
|
---|
64 | * resource, pass this handle to the LoadResource function.
|
---|
65 | * If the function fails, the return value is NULL
|
---|
66 | * Remark :
|
---|
67 | * Status : UNTESTED STUB
|
---|
68 | *
|
---|
69 | * Author : SvL
|
---|
70 | *****************************************************************************/
|
---|
71 |
|
---|
72 | HRSRC WIN32API FindResourceExA( HMODULE hModule, LPCSTR lpType,
|
---|
73 | LPCSTR lpName, WORD wLanguage)
|
---|
74 | {
|
---|
75 | Win32ImageBase *module;
|
---|
76 |
|
---|
77 | module = Win32ImageBase::findModule(hModule);
|
---|
78 | if(module == NULL) {
|
---|
79 | dprintf(("FindResourceExA Module %X not found (%x %d)", hModule, lpName, lpType));
|
---|
80 | return(NULL);
|
---|
81 | }
|
---|
82 |
|
---|
83 | return module->findResourceA((LPSTR)lpName, (LPSTR)lpType, wLanguage);
|
---|
84 | }
|
---|
85 |
|
---|
86 | /*****************************************************************************
|
---|
87 | * Name : HRSRC WIN32API FindResourceExA
|
---|
88 | * Purpose : The FindResourceExA function determines the location of the
|
---|
89 | * resource with the specified type, name, and language in the
|
---|
90 | * specified module.
|
---|
91 | * Parameters: HMODULE hModule resource-module handle
|
---|
92 | * LPCSTR lpType pointer to resource type
|
---|
93 | * LPCSTR lpName pointer to resource name
|
---|
94 | * WORD wLanguage resource language
|
---|
95 | * Variables :
|
---|
96 | * Result : If the function succeeds, the return value is a handle to the
|
---|
97 | * specified resource's info block. To obtain a handle to the
|
---|
98 | * resource, pass this handle to the LoadResource function.
|
---|
99 | * If the function fails, the return value is NULL
|
---|
100 | * Remark :
|
---|
101 | * Status : UNTESTED STUB
|
---|
102 | *
|
---|
103 | * Author : SvL
|
---|
104 | *****************************************************************************/
|
---|
105 |
|
---|
106 | HRSRC WIN32API FindResourceExW(HMODULE hModule,
|
---|
107 | LPCWSTR lpType,
|
---|
108 | LPCWSTR lpName,
|
---|
109 | WORD wLanguage)
|
---|
110 | {
|
---|
111 | Win32ImageBase *module;
|
---|
112 |
|
---|
113 | module = Win32ImageBase::findModule(hModule);
|
---|
114 | if(module == NULL) {
|
---|
115 | dprintf(("FindResourceExW Module %X not found (%x %d)", hModule, lpName, lpType));
|
---|
116 | return(NULL);
|
---|
117 | }
|
---|
118 | return module->findResourceW((LPWSTR)lpName, (LPWSTR)lpType, wLanguage);
|
---|
119 | }
|
---|
120 | //******************************************************************************
|
---|
121 | //hRes returned by LoadResource
|
---|
122 | //******************************************************************************
|
---|
123 | PVOID WIN32API LockResource(HGLOBAL hRes)
|
---|
124 | {
|
---|
125 | return (PVOID)hRes;
|
---|
126 | }
|
---|
127 | //******************************************************************************
|
---|
128 | //hRes == returned by FindResource(Ex) = PIMAGE_RESOURCE_DATA_ENTRY for resource
|
---|
129 | //******************************************************************************
|
---|
130 | HGLOBAL WIN32API LoadResource(HINSTANCE hModule, HRSRC hRes)
|
---|
131 | {
|
---|
132 | Win32ImageBase *module;
|
---|
133 |
|
---|
134 | /* @@@PH */
|
---|
135 | if(HIWORD(hRes) == NULL) {
|
---|
136 | dprintf(("ERROR: LoadResource %x: invalid hRes %x", hModule, hRes));
|
---|
137 | return 0;
|
---|
138 | }
|
---|
139 |
|
---|
140 | dprintf(("LoadResource %x %X\n", hModule, hRes));
|
---|
141 | if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
|
---|
142 | module = (Win32ImageBase *)WinExe;
|
---|
143 | }
|
---|
144 | else {
|
---|
145 | module = (Win32ImageBase *)Win32DllBase::findModule(hModule);
|
---|
146 | }
|
---|
147 |
|
---|
148 | return (HGLOBAL)module->getResourceAddr(hRes);
|
---|
149 | }
|
---|
150 | //******************************************************************************
|
---|
151 | //hRes == returned by FindResource(Ex)
|
---|
152 | //******************************************************************************
|
---|
153 | DWORD WIN32API SizeofResource(HINSTANCE hModule, HRSRC hRes)
|
---|
154 | {
|
---|
155 | Win32ImageBase *module;
|
---|
156 |
|
---|
157 | if(hRes == NULL) {
|
---|
158 | dprintf(("ERROR: SizeofResource %x: invalid hRes %x", hModule, hRes));
|
---|
159 | return(0);
|
---|
160 | }
|
---|
161 |
|
---|
162 | dprintf(("SizeofResource %x %x", hModule, hRes));
|
---|
163 |
|
---|
164 | if(hModule == 0 || hModule == -1 || (WinExe && hModule == WinExe->getInstanceHandle())) {
|
---|
165 | module = (Win32ImageBase *)WinExe;
|
---|
166 | }
|
---|
167 | else {
|
---|
168 | module = (Win32ImageBase *)Win32DllBase::findModule(hModule);
|
---|
169 | }
|
---|
170 |
|
---|
171 | return module->getResourceSize(hRes);
|
---|
172 | }
|
---|
173 | //******************************************************************************
|
---|
174 |
|
---|
175 |
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * The EnumResourceNames function searches a module for each
|
---|
179 | * resource of the specified type and passes the name of each
|
---|
180 | * resource it locates to an application-defined callback function
|
---|
181 | *
|
---|
182 | * @returns If the function succeeds, the return value is nonzero.
|
---|
183 | * If the function fails, the return value is zero
|
---|
184 | * @param hModule resource-module handling
|
---|
185 | * @param lpszType pointer to resource type
|
---|
186 | * @param lpEnumFunc pointer to callback function
|
---|
187 | * @param lParam application-defined parameter
|
---|
188 | * @status stub
|
---|
189 | * @author knut st. osmundsen
|
---|
190 | * @remark The EnumResourceNames function continues to enumerate resource
|
---|
191 | * names until the callback function returns FALSE or all resource
|
---|
192 | * names have been enumerated
|
---|
193 | */
|
---|
194 | BOOL WIN32API EnumResourceNamesA(HINSTANCE hModule,
|
---|
195 | LPCTSTR lpszType,
|
---|
196 | ENUMRESNAMEPROCA lpEnumFunc,
|
---|
197 | LONG lParam)
|
---|
198 | {
|
---|
199 | Win32ImageBase *pModule;
|
---|
200 |
|
---|
201 | dprintf(("KERNEL32:EnumResourceNamesA(%08x,%08x,%08x,%08x)",
|
---|
202 | hModule, lpszType, lpEnumFunc, lParam
|
---|
203 | ));
|
---|
204 |
|
---|
205 | pModule = Win32ImageBase::findModule(hModule);
|
---|
206 | if (pModule == NULL)
|
---|
207 | {
|
---|
208 | SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
|
---|
209 | return FALSE;
|
---|
210 | }
|
---|
211 |
|
---|
212 | return pModule->enumResourceNamesA(hModule, lpszType, lpEnumFunc, lParam);
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * The EnumResourceNames function searches a module for each
|
---|
218 | * resource of the specified type and passes the name of each
|
---|
219 | * resource it locates to an application-defined callback function
|
---|
220 | *
|
---|
221 | * @returns If the function succeeds, the return value is nonzero.
|
---|
222 | * If the function fails, the return value is zero
|
---|
223 | * @param hModule resource-module handling
|
---|
224 | * @param lpszType pointer to resource type
|
---|
225 | * @param lpEnumFunc pointer to callback function
|
---|
226 | * @param lParam application-defined parameter
|
---|
227 | * @status stub
|
---|
228 | * @author knut st. osmundsen
|
---|
229 | * @remark The EnumResourceNames function continues to enumerate resource
|
---|
230 | * names until the callback function returns FALSE or all resource
|
---|
231 | * names have been enumerated
|
---|
232 | */
|
---|
233 | BOOL WIN32API EnumResourceNamesW(HMODULE hModule,
|
---|
234 | LPCWSTR lpszType,
|
---|
235 | ENUMRESNAMEPROCW lpEnumFunc,
|
---|
236 | LONG lParam)
|
---|
237 | {
|
---|
238 | Win32ImageBase *pModule;
|
---|
239 |
|
---|
240 | dprintf(("KERNEL32:EnumResourceNamesW(%08x,%08x,%08x,%08x)\n",
|
---|
241 | hModule, lpszType, lpEnumFunc, lParam));
|
---|
242 |
|
---|
243 | pModule = Win32ImageBase::findModule(hModule);
|
---|
244 | if (pModule == NULL)
|
---|
245 | {
|
---|
246 | SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
|
---|
247 | return FALSE;
|
---|
248 | }
|
---|
249 |
|
---|
250 | return pModule->enumResourceNamesW(hModule, lpszType, lpEnumFunc, lParam);
|
---|
251 | }
|
---|
252 |
|
---|
253 | /*****************************************************************************
|
---|
254 | * Name : BOOL WIN32API EnumResourceLanguagesA
|
---|
255 | * Purpose : The EnumResourceLanguagesA function searches a module for each
|
---|
256 | * resource of the specified type and name and passes the language
|
---|
257 | * of each resource it locates to a defined callback function
|
---|
258 | * Parameters: HMODULE hModule resource-module handle
|
---|
259 | * LPCTSTR lpType pointer to resource type
|
---|
260 | * LPCTSTR lpName, pointer to resource name
|
---|
261 | * ENUMRESLANGPROC lpEnumFunc pointer to callback function
|
---|
262 | * LONG lParam application-defined parameter
|
---|
263 | * Variables :
|
---|
264 | * Result : If the function succeeds, the return value is nonzero.
|
---|
265 | * If the function fails, the return value is zero.
|
---|
266 | * Remark : The EnumResourceLanguages function continues to enumerate
|
---|
267 | * resource languages until the callback function returns FALSE
|
---|
268 | * or all resource languages have been enumerated.
|
---|
269 | * Status : UNTESTED STUB
|
---|
270 | *
|
---|
271 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
272 | *****************************************************************************/
|
---|
273 |
|
---|
274 | BOOL WIN32API EnumResourceLanguagesA(HMODULE hModule, LPCSTR lpType,
|
---|
275 | LPCSTR lpName,
|
---|
276 | ENUMRESLANGPROCA lpEnumFunc,
|
---|
277 | LONG lParam)
|
---|
278 | {
|
---|
279 |
|
---|
280 | dprintf(("KERNEL32:EnumResourceLanguagesA(%08x,%08x,%08x,%08x,%08x)\n not implemented",
|
---|
281 | hModule, lpType, lpName, lpEnumFunc, lParam
|
---|
282 | ));
|
---|
283 |
|
---|
284 | return (FALSE);
|
---|
285 | }
|
---|
286 |
|
---|
287 | /*****************************************************************************
|
---|
288 | * Name : BOOL WIN32API EnumResourceLanguagesW
|
---|
289 | * Purpose : The EnumResourceLanguagesW function searches a module for each
|
---|
290 | * resource of the specified type and name and passes the language
|
---|
291 | * of each resource it locates to a defined callback function
|
---|
292 | * Parameters: HMODULE hModule resource-module handle
|
---|
293 | * LPCTSTR lpType pointer to resource type
|
---|
294 | * LPCTSTR lpName, pointer to resource name
|
---|
295 | * ENUMRESLANGPROC lpEnumFunc pointer to callback function
|
---|
296 | * LONG lParam application-defined parameter
|
---|
297 | * Variables :
|
---|
298 | * Result : If the function succeeds, the return value is nonzero.
|
---|
299 | * If the function fails, the return value is zero.
|
---|
300 | * Remark : The EnumResourceLanguages function continues to enumerate
|
---|
301 | * resource languages until the callback function returns FALSE
|
---|
302 | * or all resource languages have been enumerated.
|
---|
303 | * Status : UNTESTED STUB
|
---|
304 | *
|
---|
305 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
306 | *****************************************************************************/
|
---|
307 |
|
---|
308 | BOOL WIN32API EnumResourceLanguagesW(HMODULE hModule, LPCWSTR lpType,
|
---|
309 | LPCWSTR lpName,
|
---|
310 | ENUMRESLANGPROCW lpEnumFunc,
|
---|
311 | LONG lParam)
|
---|
312 | {
|
---|
313 |
|
---|
314 | dprintf(("KERNEL32:EnumResourceLanguagesW(%08x,%08x,%08x,%08x,%08x)\n not implemented",
|
---|
315 | hModule, lpType, lpName, lpEnumFunc, lParam
|
---|
316 | ));
|
---|
317 |
|
---|
318 | return (FALSE);
|
---|
319 | }
|
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 | /*****************************************************************************
|
---|
324 | * Name : BOOL WIN32API EnumResourceTypesA
|
---|
325 | * Purpose : The EnumResourceTypesA function searches a module for resources
|
---|
326 | * and passes each resource type it finds to an application-defined
|
---|
327 | * callback function
|
---|
328 | * Parameters: HMODULE hModule, resource-module handle
|
---|
329 | * ENUMRESTYPEPROC lpEnumFunc pointer to callback function
|
---|
330 | * LONG lParam application-defined parameter
|
---|
331 | * Variables :
|
---|
332 | * Result : If the function succeeds, the return value is nonzero.
|
---|
333 | * If the function fails, the return value is zero
|
---|
334 | * Remark :
|
---|
335 | * Status : UNTESTED STUB
|
---|
336 | *
|
---|
337 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
338 | *****************************************************************************/
|
---|
339 |
|
---|
340 | BOOL WIN32API EnumResourceTypesA(HMODULE hModule,
|
---|
341 | ENUMRESTYPEPROCA lpEnumFunc, LONG lParam)
|
---|
342 | {
|
---|
343 | Win32ImageBase *pModule;
|
---|
344 |
|
---|
345 | dprintf(("KERNEL32:EnumResourceTypesA(%08x,%08x,%08x)\n",
|
---|
346 | hModule, lpEnumFunc, lParam));
|
---|
347 |
|
---|
348 | pModule = Win32ImageBase::findModule(hModule);
|
---|
349 | if (pModule == NULL)
|
---|
350 | {
|
---|
351 | SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
|
---|
352 | return FALSE;
|
---|
353 | }
|
---|
354 |
|
---|
355 | return pModule->enumResourceTypesA(hModule, lpEnumFunc, lParam);
|
---|
356 | }
|
---|
357 |
|
---|
358 | /*****************************************************************************
|
---|
359 | * Name : BOOL WIN32API EnumResourceTypesW
|
---|
360 | * Purpose : The EnumResourceTypesW function searches a module for resources
|
---|
361 | * and passes each resource type it finds to an application-defined
|
---|
362 | * callback function
|
---|
363 | * Parameters: HMODULE hModule, resource-module handle
|
---|
364 | * ENUMRESTYPEPROC lpEnumFunc pointer to callback function
|
---|
365 | * LONG lParam application-defined parameter
|
---|
366 | * Variables :
|
---|
367 | * Result : If the function succeeds, the return value is nonzero.
|
---|
368 | * If the function fails, the return value is zero
|
---|
369 | * Remark :
|
---|
370 | * Status : UNTESTED STUB
|
---|
371 | *
|
---|
372 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
373 | *****************************************************************************/
|
---|
374 |
|
---|
375 | BOOL WIN32API EnumResourceTypesW(HMODULE hModule,
|
---|
376 | ENUMRESTYPEPROCW lpEnumFunc, LONG lParam)
|
---|
377 | {
|
---|
378 | Win32ImageBase *pModule;
|
---|
379 |
|
---|
380 | dprintf(("KERNEL32:EnumResourceTypesW(%08x,%08x,%08x)\n",
|
---|
381 | hModule, lpEnumFunc, lParam));
|
---|
382 |
|
---|
383 | pModule = Win32ImageBase::findModule(hModule);
|
---|
384 | if (pModule == NULL)
|
---|
385 | {
|
---|
386 | SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND);
|
---|
387 | return FALSE;
|
---|
388 | }
|
---|
389 |
|
---|
390 | return pModule->enumResourceTypesW(hModule, lpEnumFunc, lParam);
|
---|
391 | }
|
---|