4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Alexandre Julliard
11 #include <sys/types.h>
18 #include "wine/winbase16.h"
19 #include "wine/winuser16.h"
24 #include "cursoricon.h"
30 #include "debugtools.h"
35 DECLARE_DEBUG_CHANNEL(accel
)
36 DECLARE_DEBUG_CHANNEL(resource
)
38 extern WORD WINE_LanguageId
;
40 #define HRSRC_MAP_BLOCKSIZE 16
42 typedef struct _HRSRC_ELEM
48 typedef struct _HRSRC_MAP
55 /**********************************************************************
58 static HRSRC16
MapHRsrc32To16( NE_MODULE
*pModule
, HANDLE hRsrc32
, WORD type
)
60 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
64 /* On first call, initialize HRSRC map */
67 if ( !(map
= (HRSRC_MAP
*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
68 sizeof(HRSRC_MAP
) ) ) )
70 ERR_(resource
)("Cannot allocate HRSRC map\n" );
73 pModule
->hRsrcMap
= (LPVOID
)map
;
76 /* Check whether HRSRC32 already in map */
77 for ( i
= 0; i
< map
->nUsed
; i
++ )
78 if ( map
->elem
[i
].hRsrc
== hRsrc32
)
79 return (HRSRC16
)(i
+ 1);
81 /* If no space left, grow table */
82 if ( map
->nUsed
== map
->nAlloc
)
84 if ( !(newElem
= (HRSRC_ELEM
*)HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
86 (map
->nAlloc
+ HRSRC_MAP_BLOCKSIZE
)
87 * sizeof(HRSRC_ELEM
) ) ))
89 ERR_(resource
)("Cannot grow HRSRC map\n" );
93 map
->nAlloc
+= HRSRC_MAP_BLOCKSIZE
;
96 /* Add HRSRC32 to table */
97 map
->elem
[map
->nUsed
].hRsrc
= hRsrc32
;
98 map
->elem
[map
->nUsed
].type
= type
;
101 return (HRSRC16
)map
->nUsed
;
104 /**********************************************************************
107 static HANDLE
MapHRsrc16To32( NE_MODULE
*pModule
, HRSRC16 hRsrc16
)
109 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
110 if ( !map
|| !hRsrc16
|| (int)hRsrc16
> map
->nUsed
) return 0;
112 return map
->elem
[(int)hRsrc16
-1].hRsrc
;
115 /**********************************************************************
118 static WORD
MapHRsrc16ToType( NE_MODULE
*pModule
, HRSRC16 hRsrc16
)
120 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
121 if ( !map
|| !hRsrc16
|| (int)hRsrc16
> map
->nUsed
) return 0;
123 return map
->elem
[(int)hRsrc16
-1].type
;
127 /**********************************************************************
130 static HRSRC
RES_FindResource( HMODULE hModule
, LPCSTR type
,
131 LPCSTR name
, WORD lang
,
132 BOOL bUnicode
, BOOL bRet16
)
136 HMODULE16 hMod16
= MapHModuleLS( hModule
);
137 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
138 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
139 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
141 TRACE_(resource
)("(%08x %s, %08x%s, %08x%s, %04x, %s, %s)\n",
142 hModule
, NE_MODULE_NAME(pModule
),
143 (UINT
)type
, HIWORD(type
)? (bUnicode
? debugstr_w((LPWSTR
)type
) : debugstr_a(type
)) : "",
144 (UINT
)name
, HIWORD(name
)? (bUnicode
? debugstr_w((LPWSTR
)name
) : debugstr_a(name
)) : "",
147 bRet16
? "NE" : "PE" );
149 if ( !pModule
) return 0;
153 /* 32-bit PE/ELF module */
154 LPWSTR typeStr
, nameStr
;
156 if ( HIWORD( type
) && !bUnicode
)
157 typeStr
= HEAP_strdupAtoW( GetProcessHeap(), 0, type
);
159 typeStr
= (LPWSTR
)type
;
160 if ( HIWORD( name
) && !bUnicode
)
161 nameStr
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
163 nameStr
= (LPWSTR
)name
;
168 hRsrc
= PE_FindResourceExW( wm
, nameStr
, typeStr
, lang
);
172 hRsrc
= LIBRES_FindResource( hModule
, nameStr
, typeStr
);
176 ERR_(resource
)("unknown module type %d\n", wm
->type
);
180 if ( HIWORD( type
) && !bUnicode
)
181 HeapFree( GetProcessHeap(), 0, typeStr
);
182 if ( HIWORD( name
) && !bUnicode
)
183 HeapFree( GetProcessHeap(), 0, nameStr
);
186 /* If we need to return 16-bit HRSRC, perform conversion */
188 hRsrc
= MapHRsrc32To16( pModule
, hRsrc
,
189 HIWORD( type
)? 0 : LOWORD( type
) );
193 /* 16-bit NE module */
194 LPSTR typeStr
, nameStr
;
196 if ( HIWORD( type
) && bUnicode
)
197 typeStr
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)type
);
199 typeStr
= (LPSTR
)type
;
200 if ( HIWORD( name
) && bUnicode
)
201 nameStr
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)name
);
203 nameStr
= (LPSTR
)name
;
205 hRsrc
= NE_FindResource( pModule
, nameStr
, typeStr
);
207 if ( HIWORD( type
) && bUnicode
)
208 HeapFree( GetProcessHeap(), 0, typeStr
);
209 if ( HIWORD( name
) && bUnicode
)
210 HeapFree( GetProcessHeap(), 0, nameStr
);
213 /* If we need to return 32-bit HRSRC, no conversion is necessary,
214 we simply use the 16-bit HRSRC as 32-bit HRSRC */
220 /**********************************************************************
223 static DWORD
RES_SizeofResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
227 HMODULE16 hMod16
= MapHModuleLS( hModule
);
228 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
229 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
230 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
232 TRACE_(resource
)("(%08x %s, %08x, %s)\n",
233 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
235 if ( !pModule
|| !hRsrc
) return 0;
239 /* 32-bit PE/ELF module */
241 /* If we got a 16-bit hRsrc, convert it */
242 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
247 size
= PE_SizeofResource( hModule
, hRsrc32
);
251 size
= LIBRES_SizeofResource( hModule
, hRsrc32
);
255 ERR_(resource
)("unknown module type %d\n", wm
->type
);
261 /* 16-bit NE module */
263 /* If we got a 32-bit hRsrc, we don't need to convert it */
265 size
= NE_SizeofResource( pModule
, hRsrc
);
271 /**********************************************************************
274 static HFILE
RES_AccessResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
276 HFILE hFile
= HFILE_ERROR
;
278 HMODULE16 hMod16
= MapHModuleLS( hModule
);
279 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
280 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
281 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
283 TRACE_(resource
)("(%08x %s, %08x, %s)\n",
284 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
286 if ( !pModule
|| !hRsrc
) return HFILE_ERROR
;
290 /* 32-bit PE/ELF module */
292 /* If we got a 16-bit hRsrc, convert it */
293 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
296 FIXME_(resource
)("32-bit modules not yet supported.\n" );
299 /* If we need to return a 16-bit file handle, convert it */
301 hFile
= FILE_AllocDosHandle( hFile
);
305 /* 16-bit NE module */
307 /* If we got a 32-bit hRsrc, we don't need to convert it */
309 hFile
= NE_AccessResource( pModule
, hRsrc
);
311 /* If we are to return a 32-bit file handle, convert it */
313 hFile
= FILE_GetHandle( hFile
);
319 /**********************************************************************
322 static HGLOBAL
RES_LoadResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
326 HMODULE16 hMod16
= MapHModuleLS( hModule
);
327 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
328 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
329 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
331 TRACE_(resource
)("(%08x %s, %08x, %s)\n",
332 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
334 if ( !pModule
|| !hRsrc
) return 0;
338 /* 32-bit PE/ELF module */
340 /* If we got a 16-bit hRsrc, convert it */
341 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
346 hMem
= PE_LoadResource( wm
, hRsrc32
);
350 hMem
= LIBRES_LoadResource( hModule
, hRsrc32
);
354 ERR_(resource
)("unknown module type %d\n", wm
->type
);
358 /* If we need to return a 16-bit resource, convert it */
361 WORD type
= MapHRsrc16ToType( pModule
, hRsrc
);
362 DWORD size
= SizeofResource( hModule
, hRsrc
);
363 LPVOID bits
= LockResource( hMem
);
365 hMem
= NE_LoadPEResource( pModule
, type
, bits
, size
);
370 /* 16-bit NE module */
372 /* If we got a 32-bit hRsrc, we don't need to convert it */
374 hMem
= NE_LoadResource( pModule
, hRsrc
);
376 /* If we are to return a 32-bit resource, we should probably
377 convert it but we don't for now. FIXME !!! */
383 /**********************************************************************
386 static LPVOID
RES_LockResource( HGLOBAL handle
, BOOL bRet16
)
390 TRACE_(resource
)("(%08x, %s)\n", handle
, bRet16
? "NE" : "PE" );
392 if ( HIWORD( handle
) )
394 /* 32-bit memory handle */
397 FIXME_(resource
)("can't return SEGPTR to 32-bit resource %08x.\n", handle
);
399 bits
= (LPVOID
)handle
;
403 /* 16-bit memory handle */
405 /* May need to reload the resource if discarded */
406 SEGPTR segPtr
= WIN16_GlobalLock16( handle
);
409 bits
= (LPVOID
)segPtr
;
411 bits
= PTR_SEG_TO_LIN( segPtr
);
417 /**********************************************************************
420 static BOOL
RES_FreeResource( HGLOBAL handle
)
422 HGLOBAL retv
= handle
;
424 TRACE_(resource
)("(%08x)\n", handle
);
426 if ( HIWORD( handle
) )
428 /* 32-bit memory handle: nothing to do */
432 /* 16-bit memory handle */
433 NE_MODULE
*pModule
= NE_GetPtr( FarGetOwner16( handle
) );
435 /* Try NE resource first */
436 retv
= NE_FreeResource( pModule
, handle
);
438 /* If this failed, call USER.DestroyIcon32; this will check
439 whether it is a shared cursor/icon; if not it will call
442 if ( Callout
.DestroyIcon32
)
443 retv
= Callout
.DestroyIcon32( handle
, CID_RESOURCE
);
445 retv
= GlobalFree16( handle
);
453 /**********************************************************************
454 * FindResource16 (KERNEL.60)
456 HRSRC16 WINAPI
FindResource16( HMODULE16 hModule
, SEGPTR name
, SEGPTR type
)
458 LPCSTR nameStr
= HIWORD(name
)? PTR_SEG_TO_LIN(name
) : (LPCSTR
)name
;
459 LPCSTR typeStr
= HIWORD(type
)? PTR_SEG_TO_LIN(type
) : (LPCSTR
)type
;
461 return RES_FindResource( hModule
, typeStr
, nameStr
,
462 WINE_LanguageId
, FALSE
, TRUE
);
465 /**********************************************************************
466 * FindResourceA (KERNEL32.128)
468 HANDLE WINAPI
FindResourceA( HMODULE hModule
, LPCSTR name
, LPCSTR type
)
470 return RES_FindResource( hModule
, type
, name
,
471 WINE_LanguageId
, FALSE
, FALSE
);
474 /**********************************************************************
475 * FindResourceExA (KERNEL32.129)
477 HANDLE WINAPI
FindResourceExA( HMODULE hModule
,
478 LPCSTR type
, LPCSTR name
, WORD lang
)
480 return RES_FindResource( hModule
, type
, name
,
481 lang
, FALSE
, FALSE
);
484 /**********************************************************************
485 * FindResourceExW (KERNEL32.130)
487 HRSRC WINAPI
FindResourceExW( HMODULE hModule
,
488 LPCWSTR type
, LPCWSTR name
, WORD lang
)
490 return RES_FindResource( hModule
, (LPCSTR
)type
, (LPCSTR
)name
,
494 /**********************************************************************
495 * FindResourceW (KERNEL32.131)
497 HRSRC WINAPI
FindResourceW(HINSTANCE hModule
, LPCWSTR name
, LPCWSTR type
)
499 return RES_FindResource( hModule
, (LPCSTR
)type
, (LPCSTR
)name
,
500 WINE_LanguageId
, TRUE
, FALSE
);
503 /**********************************************************************
504 * LoadResource16 (KERNEL.61)
506 HGLOBAL16 WINAPI
LoadResource16( HMODULE16 hModule
, HRSRC16 hRsrc
)
508 return RES_LoadResource( hModule
, hRsrc
, TRUE
);
511 /**********************************************************************
512 * LoadResource (KERNEL32.370)
514 HGLOBAL WINAPI
LoadResource( HINSTANCE hModule
, HRSRC hRsrc
)
516 return RES_LoadResource( hModule
, hRsrc
, FALSE
);
519 /**********************************************************************
520 * LockResource16 (KERNEL.62)
522 SEGPTR WINAPI
WIN16_LockResource16( HGLOBAL16 handle
)
524 return (SEGPTR
)RES_LockResource( handle
, TRUE
);
526 LPVOID WINAPI
LockResource16( HGLOBAL16 handle
)
528 return RES_LockResource( handle
, FALSE
);
531 /**********************************************************************
532 * LockResource (KERNEL32.384)
534 LPVOID WINAPI
LockResource( HGLOBAL handle
)
536 return RES_LockResource( handle
, FALSE
);
539 /**********************************************************************
540 * FreeResource16 (KERNEL.63)
542 BOOL16 WINAPI
FreeResource16( HGLOBAL16 handle
)
544 return RES_FreeResource( handle
);
547 /**********************************************************************
548 * FreeResource (KERNEL32.145)
550 BOOL WINAPI
FreeResource( HGLOBAL handle
)
552 return RES_FreeResource( handle
);
555 /**********************************************************************
556 * AccessResource16 (KERNEL.64)
558 INT16 WINAPI
AccessResource16( HINSTANCE16 hModule
, HRSRC16 hRsrc
)
560 return RES_AccessResource( hModule
, hRsrc
, TRUE
);
563 /**********************************************************************
564 * AccessResource (KERNEL32.64)
566 INT WINAPI
AccessResource( HMODULE hModule
, HRSRC hRsrc
)
568 return RES_AccessResource( hModule
, hRsrc
, FALSE
);
571 /**********************************************************************
572 * SizeofResource16 (KERNEL.65)
574 DWORD WINAPI
SizeofResource16( HMODULE16 hModule
, HRSRC16 hRsrc
)
576 return RES_SizeofResource( hModule
, hRsrc
, TRUE
);
579 /**********************************************************************
580 * SizeofResource (KERNEL32.522)
582 DWORD WINAPI
SizeofResource( HINSTANCE hModule
, HRSRC hRsrc
)
584 return RES_SizeofResource( hModule
, hRsrc
, FALSE
);
589 /**********************************************************************
590 * LoadAccelerators16 [USER.177]
592 HACCEL16 WINAPI
LoadAccelerators16(HINSTANCE16 instance
, SEGPTR lpTableName
)
596 if (HIWORD(lpTableName
))
597 TRACE_(accel
)("%04x '%s'\n",
598 instance
, (char *)PTR_SEG_TO_LIN( lpTableName
) );
600 TRACE_(accel
)("%04x %04x\n",
601 instance
, LOWORD(lpTableName
) );
603 if (!(hRsrc
= FindResource16( instance
, lpTableName
, RT_ACCELERATOR16
))) {
604 WARN_(accel
)("couldn't find accelerator table resource\n");
608 TRACE_(accel
)("returning HACCEL 0x%x\n", hRsrc
);
609 return LoadResource16(instance
,hRsrc
);
612 /**********************************************************************
613 * LoadAccelerators32W [USER.177]
614 * The image layout seems to look like this (not 100% sure):
615 * 00: BYTE type type of accelerator
616 * 01: BYTE pad (to WORD boundary)
619 * 06: WORD pad (to DWORD boundary)
621 HACCEL WINAPI
LoadAcceleratorsW(HINSTANCE instance
,LPCWSTR lpTableName
)
624 HACCEL hMem
,hRetval
=0;
627 if (HIWORD(lpTableName
))
628 TRACE_(accel
)("%p '%s'\n",
629 (LPVOID
)instance
, (char *)( lpTableName
) );
631 TRACE_(accel
)("%p 0x%04x\n",
632 (LPVOID
)instance
, LOWORD(lpTableName
) );
634 if (!(hRsrc
= FindResourceW( instance
, lpTableName
, RT_ACCELERATORW
)))
636 WARN_(accel
)("couldn't find accelerator table resource\n");
638 hMem
= LoadResource( instance
, hRsrc
);
639 size
= SizeofResource( instance
, hRsrc
);
640 if(size
>=sizeof(PE_ACCEL
))
642 LPPE_ACCEL accel_table
= (LPPE_ACCEL
) hMem
;
644 int i
,nrofaccells
= size
/sizeof(PE_ACCEL
);
646 hRetval
= GlobalAlloc16(0,sizeof(ACCEL16
)*nrofaccells
);
647 accel16
= (LPACCEL16
)GlobalLock16(hRetval
);
648 for (i
=0;i
<nrofaccells
;i
++) {
649 accel16
[i
].fVirt
= accel_table
[i
].fVirt
;
650 accel16
[i
].key
= accel_table
[i
].key
;
651 accel16
[i
].cmd
= accel_table
[i
].cmd
;
653 accel16
[i
-1].fVirt
|= 0x80;
656 TRACE_(accel
)("returning HACCEL 0x%x\n", hRsrc
);
660 HACCEL WINAPI
LoadAcceleratorsA(HINSTANCE instance
,LPCSTR lpTableName
)
664 if (HIWORD(lpTableName
))
665 uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, lpTableName
);
667 uni
= (LPWSTR
)lpTableName
;
668 result
= LoadAcceleratorsW(instance
,uni
);
669 if (HIWORD(uni
)) HeapFree( GetProcessHeap(), 0, uni
);
673 /**********************************************************************
674 * CopyAcceleratorTable32A (USER32.58)
676 INT WINAPI
CopyAcceleratorTableA(HACCEL src
, LPACCEL dst
, INT entries
)
678 return CopyAcceleratorTableW(src
, dst
, entries
);
681 /**********************************************************************
682 * CopyAcceleratorTable32W (USER32.59)
684 * By mortene@pvv.org 980321
686 INT WINAPI
CopyAcceleratorTableW(HACCEL src
, LPACCEL dst
,
690 LPACCEL16 accel
= (LPACCEL16
)GlobalLock16(src
);
693 /* Do parameter checking to avoid the explosions and the screaming
694 as far as possible. */
695 if((dst
&& (entries
< 1)) || (src
== (HACCEL
)NULL
) || !accel
) {
696 WARN_(accel
)("Application sent invalid parameters (%p %p %d).\n",
697 (LPVOID
)src
, (LPVOID
)dst
, entries
);
700 xsize
= GlobalSize16(src
)/sizeof(ACCEL16
);
701 if (xsize
>entries
) entries
=xsize
;
705 /* Spit out some debugging information. */
706 TRACE_(accel
)("accel %d: type 0x%02x, event '%c', IDval 0x%04x.\n",
707 i
, accel
[i
].fVirt
, accel
[i
].key
, accel
[i
].cmd
);
709 /* Copy data to the destination structure array (if dst == NULL,
710 we're just supposed to count the number of entries). */
712 dst
[i
].fVirt
= accel
[i
].fVirt
;
713 dst
[i
].key
= accel
[i
].key
;
714 dst
[i
].cmd
= accel
[i
].cmd
;
716 /* Check if we've reached the end of the application supplied
717 accelerator table. */
719 /* Turn off the high order bit, just in case. */
720 dst
[i
].fVirt
&= 0x7f;
725 /* The highest order bit seems to mark the end of the accelerator
726 resource table, but not always. Use GlobalSize() check too. */
727 if((accel
[i
].fVirt
& 0x80) != 0) done
= TRUE
;
735 /*********************************************************************
736 * CreateAcceleratorTable (USER32.64)
738 * By mortene@pvv.org 980321
740 HACCEL WINAPI
CreateAcceleratorTableA(LPACCEL lpaccel
, INT cEntries
)
746 /* Do parameter checking just in case someone's trying to be
749 WARN_(accel
)("Application sent invalid parameters (%p %d).\n",
751 SetLastError(ERROR_INVALID_PARAMETER
);
754 FIXME_(accel
)("should check that the accelerator descriptions are valid,"
755 " return NULL and SetLastError() if not.\n");
758 /* Allocate memory and copy the table. */
759 hAccel
= GlobalAlloc16(0,cEntries
*sizeof(ACCEL16
));
761 TRACE_(accel
)("handle %x\n", hAccel
);
763 ERR_(accel
)("Out of memory.\n");
764 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
767 accel
= GlobalLock16(hAccel
);
768 for (i
=0;i
<cEntries
;i
++) {
769 accel
[i
].fVirt
= lpaccel
[i
].fVirt
;
770 accel
[i
].key
= lpaccel
[i
].key
;
771 accel
[i
].cmd
= lpaccel
[i
].cmd
;
773 /* Set the end-of-table terminator. */
774 accel
[cEntries
-1].fVirt
|= 0x80;
776 TRACE_(accel
)("Allocated accelerator handle %x\n", hAccel
);
781 /******************************************************************************
782 * DestroyAcceleratorTable [USER32.130]
783 * Destroys an accelerator table
786 * By mortene@pvv.org 980321
789 * handle [I] Handle to accelerator table
793 BOOL WINAPI
DestroyAcceleratorTable( HACCEL handle
)
795 FIXME_(accel
)("(0x%x): stub\n", handle
);
796 /* FIXME: GlobalFree16(handle); */
800 /**********************************************************************
803 INT16 WINAPI
LoadString16( HINSTANCE16 instance
, UINT16 resource_id
,
804 LPSTR buffer
, INT16 buflen
)
812 TRACE_(resource
)("inst=%04x id=%04x buff=%08x len=%d\n",
813 instance
, resource_id
, (int) buffer
, buflen
);
815 hrsrc
= FindResource16( instance
, (SEGPTR
)((resource_id
>>4)+1), RT_STRING16
);
816 if (!hrsrc
) return 0;
817 hmem
= LoadResource16( instance
, hrsrc
);
820 p
= LockResource16(hmem
);
821 string_num
= resource_id
& 0x000f;
822 for (i
= 0; i
< string_num
; i
++)
825 TRACE_(resource
)("strlen = %d\n", (int)*p
);
827 i
= MIN(buflen
- 1, *p
);
831 memcpy(buffer
, p
+ 1, i
);
838 WARN_(resource
)("Dont know why caller give buflen=%d *p=%d trying to obtain string '%s'\n", buflen
, *p
, p
+ 1);
840 FreeResource16( hmem
);
842 TRACE_(resource
)("'%s' loaded !\n", buffer
);
846 /**********************************************************************
847 * LoadString32W (USER32.376)
849 INT WINAPI
LoadStringW( HINSTANCE instance
, UINT resource_id
,
850 LPWSTR buffer
, INT buflen
)
858 if (HIWORD(resource_id
)==0xFFFF) /* netscape 3 passes this */
859 resource_id
= (UINT
)(-((INT
)resource_id
));
860 TRACE_(resource
)("instance = %04x, id = %04x, buffer = %08x, "
861 "length = %d\n", instance
, (int)resource_id
, (int) buffer
, buflen
);
863 /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out
865 hrsrc
= FindResourceW( instance
, (LPCWSTR
)(((resource_id
>>4)&0xffff)+1),
867 if (!hrsrc
) return 0;
868 hmem
= LoadResource( instance
, hrsrc
);
871 p
= LockResource(hmem
);
872 string_num
= resource_id
& 0x000f;
873 for (i
= 0; i
< string_num
; i
++)
876 TRACE_(resource
)("strlen = %d\n", (int)*p
);
878 i
= MIN(buflen
- 1, *p
);
882 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
883 buffer
[i
] = (WCHAR
) 0;
886 buffer
[0] = (WCHAR
) 0;
890 WARN_(resource
)("Dont know why caller give buflen=%d *p=%d trying to obtain string '%s'\n", buflen
, *p
, p
+ 1);
894 TRACE_(resource
)("%s loaded !\n", debugstr_w(buffer
));
898 /**********************************************************************
899 * LoadString32A (USER32.375)
901 INT WINAPI
LoadStringA( HINSTANCE instance
, UINT resource_id
,
902 LPSTR buffer
, INT buflen
)
905 LPWSTR buffer2
= NULL
;
906 if (buffer
&& buflen
)
907 buffer2
= HeapAlloc( GetProcessHeap(), 0, buflen
* 2 );
908 retval
= LoadStringW(instance
,resource_id
,buffer2
,buflen
);
913 lstrcpynWtoA( buffer
, buffer2
, buflen
);
914 retval
= lstrlenA( buffer
);
918 HeapFree( GetProcessHeap(), 0, buffer2
);
923 /* Messages...used by FormatMessage32* (KERNEL32.something)
925 * They can be specified either directly or using a message ID and
926 * loading them from the resource.
928 * The resourcedata has following format:
930 * 0: DWORD nrofentries
931 * nrofentries * subentry:
932 * 0: DWORD firstentry
934 * 8: DWORD offset from start to the stringentries
936 * (lastentry-firstentry) * stringentry:
937 * 0: WORD len (0 marks end)
940 * (stringentry i of a subentry refers to the ID 'firstentry+i')
942 * Yes, ANSI strings in win32 resources. Go figure.
945 /**********************************************************************
946 * LoadMessage32A (internal)
948 INT WINAPI
LoadMessageA( HMODULE instance
, UINT id
, WORD lang
,
949 LPSTR buffer
, INT buflen
)
953 PMESSAGE_RESOURCE_DATA mrd
;
954 PMESSAGE_RESOURCE_BLOCK mrb
;
955 PMESSAGE_RESOURCE_ENTRY mre
;
958 TRACE_(resource
)("instance = %08lx, id = %08lx, buffer = %p, length = %ld\n", (DWORD
)instance
, (DWORD
)id
, buffer
, (DWORD
)buflen
);
960 /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
961 hrsrc
= FindResourceExW(instance
,RT_MESSAGELISTW
,(LPWSTR
)1,lang
);
962 if (!hrsrc
) return 0;
963 hmem
= LoadResource( instance
, hrsrc
);
966 mrd
= (PMESSAGE_RESOURCE_DATA
)LockResource(hmem
);
968 mrb
= &(mrd
->Blocks
[0]);
969 for (i
=mrd
->NumberOfBlocks
;i
--;) {
970 if ((id
>=mrb
->LowId
) && (id
<=mrb
->HighId
)) {
971 mre
= (PMESSAGE_RESOURCE_ENTRY
)(((char*)mrd
)+mrb
->OffsetToEntries
);
982 mre
= (PMESSAGE_RESOURCE_ENTRY
)(((char*)mre
)+(mre
->Length
));
985 TRACE_(resource
)(" - strlen=%d\n",slen
);
986 i
= MIN(buflen
- 1, slen
);
988 return slen
; /* different to LoadString */
990 lstrcpynA(buffer
,(char*)mre
->Text
,i
);
999 TRACE_(resource
)("'%s' copied !\n", buffer
);
1003 /**********************************************************************
1004 * LoadMessage32W (internal)
1006 INT WINAPI
LoadMessageW( HMODULE instance
, UINT id
, WORD lang
,
1007 LPWSTR buffer
, INT buflen
)
1010 LPSTR buffer2
= NULL
;
1011 if (buffer
&& buflen
)
1012 buffer2
= HeapAlloc( GetProcessHeap(), 0, buflen
);
1013 retval
= LoadMessageA(instance
,id
,lang
,buffer2
,buflen
);
1017 lstrcpynAtoW( buffer
, buffer2
, buflen
);
1018 retval
= lstrlenW( buffer
);
1020 HeapFree( GetProcessHeap(), 0, buffer2
);
1026 /**********************************************************************
1027 * EnumResourceTypesA (KERNEL32.90)
1029 BOOL WINAPI
EnumResourceTypesA( HMODULE hmodule
,ENUMRESTYPEPROCA lpfun
,
1032 /* FIXME: move WINE_MODREF stuff here */
1033 return PE_EnumResourceTypesA(hmodule
,lpfun
,lParam
);
1036 /**********************************************************************
1037 * EnumResourceTypesW (KERNEL32.91)
1039 BOOL WINAPI
EnumResourceTypesW( HMODULE hmodule
,ENUMRESTYPEPROCW lpfun
,
1042 /* FIXME: move WINE_MODREF stuff here */
1043 return PE_EnumResourceTypesW(hmodule
,lpfun
,lParam
);
1046 /**********************************************************************
1047 * EnumResourceNamesA (KERNEL32.88)
1049 BOOL WINAPI
EnumResourceNamesA( HMODULE hmodule
, LPCSTR type
,
1050 ENUMRESNAMEPROCA lpfun
, LONG lParam
)
1052 /* FIXME: move WINE_MODREF stuff here */
1053 return PE_EnumResourceNamesA(hmodule
,type
,lpfun
,lParam
);
1055 /**********************************************************************
1056 * EnumResourceNamesW (KERNEL32.89)
1058 BOOL WINAPI
EnumResourceNamesW( HMODULE hmodule
, LPCWSTR type
,
1059 ENUMRESNAMEPROCW lpfun
, LONG lParam
)
1061 /* FIXME: move WINE_MODREF stuff here */
1062 return PE_EnumResourceNamesW(hmodule
,type
,lpfun
,lParam
);
1065 /**********************************************************************
1066 * EnumResourceLanguagesA (KERNEL32.86)
1068 BOOL WINAPI
EnumResourceLanguagesA( HMODULE hmodule
, LPCSTR type
,
1069 LPCSTR name
, ENUMRESLANGPROCA lpfun
,
1072 /* FIXME: move WINE_MODREF stuff here */
1073 return PE_EnumResourceLanguagesA(hmodule
,type
,name
,lpfun
,lParam
);
1075 /**********************************************************************
1076 * EnumResourceLanguagesW (KERNEL32.87)
1078 BOOL WINAPI
EnumResourceLanguagesW( HMODULE hmodule
, LPCWSTR type
,
1079 LPCWSTR name
, ENUMRESLANGPROCW lpfun
,
1082 /* FIXME: move WINE_MODREF stuff here */
1083 return PE_EnumResourceLanguagesW(hmodule
,type
,name
,lpfun
,lParam
);