source: trunk/src/kernel32/resource.cpp@ 21916

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 16.0 KB
Line 
1/* $Id: resource.cpp,v 1.19 2002-03-22 12:51:35 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//******************************************************************************
24//lpszName = integer id (high word 0), else string (name or "#237")
25//Can lpszType contain a pointer to a default resource type name?
26//******************************************************************************
27HRSRC WIN32API FindResourceA(HINSTANCE hModule, LPCSTR lpszName, LPCSTR lpszType)
28{
29 Win32ImageBase *module;
30 WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
31
32 module = Win32ImageBase::findModule(hModule);
33 if(module == NULL) {
34 dprintf(("FindResourceA Module %X not found (%x %d)", hModule, lpszName, lpszType));
35 return(NULL);
36 }
37 return module->findResourceA(lpszName, (LPSTR)lpszType, wLanguage);
38}
39//******************************************************************************
40//******************************************************************************
41HRSRC WIN32API FindResourceW(HINSTANCE hModule, LPCWSTR lpszName,
42 LPCWSTR lpszType)
43{
44 Win32ImageBase *module;
45 WORD wLanguage = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL);
46
47 module = Win32ImageBase::findModule(hModule);
48 if(module == NULL) {
49 dprintf(("FindResourceW Module %X not found (%x %d)", hModule, lpszName, lpszType));
50 return(NULL);
51 }
52 return module->findResourceW((LPWSTR)lpszName, (LPWSTR)lpszType, wLanguage);
53}
54/*****************************************************************************
55 * Name : HRSRC WIN32API FindResourceExA
56 * Purpose : The FindResourceExA function determines the location of the
57 * resource with the specified type, name, and language in the
58 * specified module.
59 * Parameters: HMODULE hModule resource-module handle
60 * LPCSTR lpType pointer to resource type
61 * LPCSTR lpName pointer to resource name
62 * WORD wLanguage resource language
63 * Variables :
64 * Result : If the function succeeds, the return value is a handle to the
65 * specified resource's info block. To obtain a handle to the
66 * resource, pass this handle to the LoadResource function.
67 * If the function fails, the return value is NULL
68 * Remark :
69 * Status : fully implemented
70 *
71 * Author : SvL
72 *****************************************************************************/
73
74HRSRC WIN32API FindResourceExA( HMODULE hModule, LPCSTR lpType,
75 LPCSTR lpName, WORD wLanguage)
76{
77 Win32ImageBase *module;
78
79 module = Win32ImageBase::findModule(hModule);
80 if(module == NULL) {
81 dprintf(("FindResourceExA Module %X not found (%x %d)", hModule, lpName, lpType));
82 return(NULL);
83 }
84
85 return module->findResourceA((LPSTR)lpName, (LPSTR)lpType, wLanguage);
86}
87
88/*****************************************************************************
89 * Name : HRSRC WIN32API FindResourceExA
90 * Purpose : The FindResourceExA function determines the location of the
91 * resource with the specified type, name, and language in the
92 * specified module.
93 * Parameters: HMODULE hModule resource-module handle
94 * LPCSTR lpType pointer to resource type
95 * LPCSTR lpName pointer to resource name
96 * WORD wLanguage resource language
97 * Variables :
98 * Result : If the function succeeds, the return value is a handle to the
99 * specified resource's info block. To obtain a handle to the
100 * resource, pass this handle to the LoadResource function.
101 * If the function fails, the return value is NULL
102 * Remark :
103 * Status : fully implemented
104 *
105 * Author : SvL
106 *****************************************************************************/
107
108HRSRC WIN32API FindResourceExW(HMODULE hModule, LPCWSTR lpType,
109 LPCWSTR lpName, 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//******************************************************************************
123PVOID WIN32API LockResource(HGLOBAL hRes)
124{
125 return (PVOID)hRes;
126}
127//******************************************************************************
128//hRes == returned by FindResource(Ex) = PIMAGE_RESOURCE_DATA_ENTRY for resource
129//******************************************************************************
130HGLOBAL 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//******************************************************************************
153DWORD 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 fully implemented
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 */
194BOOL 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); //todo: right error????
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 fully implemented
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 */
233BOOL 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); //todo: right error????
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 : fully implemented
270 *
271 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
272 *****************************************************************************/
273
274BOOL WIN32API EnumResourceLanguagesA(HMODULE hModule, LPCSTR lpType,
275 LPCSTR lpName,
276 ENUMRESLANGPROCA lpEnumFunc,
277 LONG lParam)
278{
279 Win32ImageBase *pModule;
280
281 dprintf(("KERNEL32:EnumResourceLanguagesA(%08x,%08x,%08x,%08x,%08x)",
282 hModule, lpType, lpName, lpEnumFunc, lParam));
283
284 pModule = Win32ImageBase::findModule(hModule);
285 if (pModule == NULL)
286 {
287 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); //todo: right error????
288 return FALSE;
289 }
290
291 return pModule->enumResourceLanguagesA(hModule, lpType, lpName, lpEnumFunc, lParam);
292}
293
294/*****************************************************************************
295 * Name : BOOL WIN32API EnumResourceLanguagesW
296 * Purpose : The EnumResourceLanguagesW function searches a module for each
297 * resource of the specified type and name and passes the language
298 * of each resource it locates to a defined callback function
299 * Parameters: HMODULE hModule resource-module handle
300 * LPCTSTR lpType pointer to resource type
301 * LPCTSTR lpName, pointer to resource name
302 * ENUMRESLANGPROC lpEnumFunc pointer to callback function
303 * LONG lParam application-defined parameter
304 * Variables :
305 * Result : If the function succeeds, the return value is nonzero.
306 * If the function fails, the return value is zero.
307 * Remark : The EnumResourceLanguages function continues to enumerate
308 * resource languages until the callback function returns FALSE
309 * or all resource languages have been enumerated.
310 * Status : fully implemented
311 *
312 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
313 *****************************************************************************/
314
315BOOL WIN32API EnumResourceLanguagesW(HMODULE hModule, LPCWSTR lpType,
316 LPCWSTR lpName,
317 ENUMRESLANGPROCW lpEnumFunc,
318 LONG lParam)
319{
320 Win32ImageBase *pModule;
321
322 dprintf(("KERNEL32:EnumResourceLanguagesW(%08x,%08x,%08x,%08x,%08x)",
323 hModule, lpType, lpName, lpEnumFunc, lParam));
324
325 pModule = Win32ImageBase::findModule(hModule);
326 if (pModule == NULL)
327 {
328 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); //todo: right error????
329 return FALSE;
330 }
331 return pModule->enumResourceLanguagesW(hModule, lpType, lpName, lpEnumFunc, lParam);
332}
333
334/*****************************************************************************
335 * Name : BOOL WIN32API EnumResourceTypesA
336 * Purpose : The EnumResourceTypesA function searches a module for resources
337 * and passes each resource type it finds to an application-defined
338 * callback function
339 * Parameters: HMODULE hModule, resource-module handle
340 * ENUMRESTYPEPROC lpEnumFunc pointer to callback function
341 * LONG lParam application-defined parameter
342 * Variables :
343 * Result : If the function succeeds, the return value is nonzero.
344 * If the function fails, the return value is zero
345 * Remark :
346 * Status : fully implemented
347 *
348 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
349 *****************************************************************************/
350
351BOOL WIN32API EnumResourceTypesA(HMODULE hModule,
352 ENUMRESTYPEPROCA lpEnumFunc, LONG lParam)
353{
354 Win32ImageBase *pModule;
355
356 dprintf(("KERNEL32:EnumResourceTypesA(%08x,%08x,%08x)\n",
357 hModule, lpEnumFunc, lParam));
358
359 pModule = Win32ImageBase::findModule(hModule);
360 if (pModule == NULL)
361 {
362 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); //todo: right error????
363 return FALSE;
364 }
365
366 return pModule->enumResourceTypesA(hModule, lpEnumFunc, lParam);
367}
368
369/*****************************************************************************
370 * Name : BOOL WIN32API EnumResourceTypesW
371 * Purpose : The EnumResourceTypesW function searches a module for resources
372 * and passes each resource type it finds to an application-defined
373 * callback function
374 * Parameters: HMODULE hModule, resource-module handle
375 * ENUMRESTYPEPROC lpEnumFunc pointer to callback function
376 * LONG lParam application-defined parameter
377 * Variables :
378 * Result : If the function succeeds, the return value is nonzero.
379 * If the function fails, the return value is zero
380 * Remark :
381 * Status : fully implemented
382 *
383 * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
384 *****************************************************************************/
385
386BOOL WIN32API EnumResourceTypesW(HMODULE hModule,
387 ENUMRESTYPEPROCW lpEnumFunc, LONG lParam)
388{
389 Win32ImageBase *pModule;
390
391 dprintf(("KERNEL32:EnumResourceTypesW(%08x,%08x,%08x)\n",
392 hModule, lpEnumFunc, lParam));
393
394 pModule = Win32ImageBase::findModule(hModule);
395 if (pModule == NULL)
396 {
397 SetLastError(ERROR_RESOURCE_DATA_NOT_FOUND); //todo: right error????
398 return FALSE;
399 }
400
401 return pModule->enumResourceTypesW(hModule, lpEnumFunc, lParam);
402}
403//******************************************************************************
404//******************************************************************************
Note: See TracBrowser for help on using the repository browser.