4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Alexandre Julliard
11 #include <sys/types.h>
19 #include "wine/winbase16.h"
20 #include "wine/winuser16.h"
21 #include "wine/exception.h"
26 #include "cursoricon.h"
32 #include "debugtools.h"
36 DEFAULT_DEBUG_CHANNEL(resource
);
37 DECLARE_DEBUG_CHANNEL(accel
);
39 extern WORD WINE_LanguageId
;
41 #define HRSRC_MAP_BLOCKSIZE 16
43 typedef struct _HRSRC_ELEM
49 typedef struct _HRSRC_MAP
56 /**********************************************************************
59 static HRSRC16
MapHRsrc32To16( NE_MODULE
*pModule
, HANDLE hRsrc32
, WORD type
)
61 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
65 /* On first call, initialize HRSRC map */
68 if ( !(map
= (HRSRC_MAP
*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
69 sizeof(HRSRC_MAP
) ) ) )
71 ERR("Cannot allocate HRSRC map\n" );
74 pModule
->hRsrcMap
= (LPVOID
)map
;
77 /* Check whether HRSRC32 already in map */
78 for ( i
= 0; i
< map
->nUsed
; i
++ )
79 if ( map
->elem
[i
].hRsrc
== hRsrc32
)
80 return (HRSRC16
)(i
+ 1);
82 /* If no space left, grow table */
83 if ( map
->nUsed
== map
->nAlloc
)
85 if ( !(newElem
= (HRSRC_ELEM
*)HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
87 (map
->nAlloc
+ HRSRC_MAP_BLOCKSIZE
)
88 * sizeof(HRSRC_ELEM
) ) ))
90 ERR("Cannot grow HRSRC map\n" );
94 map
->nAlloc
+= HRSRC_MAP_BLOCKSIZE
;
97 /* Add HRSRC32 to table */
98 map
->elem
[map
->nUsed
].hRsrc
= hRsrc32
;
99 map
->elem
[map
->nUsed
].type
= type
;
102 return (HRSRC16
)map
->nUsed
;
105 /**********************************************************************
108 static HANDLE
MapHRsrc16To32( NE_MODULE
*pModule
, HRSRC16 hRsrc16
)
110 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
111 if ( !map
|| !hRsrc16
|| (int)hRsrc16
> map
->nUsed
) return 0;
113 return map
->elem
[(int)hRsrc16
-1].hRsrc
;
116 /**********************************************************************
119 static WORD
MapHRsrc16ToType( NE_MODULE
*pModule
, HRSRC16 hRsrc16
)
121 HRSRC_MAP
*map
= (HRSRC_MAP
*)pModule
->hRsrcMap
;
122 if ( !map
|| !hRsrc16
|| (int)hRsrc16
> map
->nUsed
) return 0;
124 return map
->elem
[(int)hRsrc16
-1].type
;
128 /* filter for page-fault exceptions */
129 static WINE_EXCEPTION_FILTER(page_fault
)
131 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION
)
132 return EXCEPTION_EXECUTE_HANDLER
;
133 return EXCEPTION_CONTINUE_SEARCH
;
136 static HRSRC
RES_FindResource2( HMODULE hModule
, LPCSTR type
,
137 LPCSTR name
, WORD lang
,
138 BOOL bUnicode
, BOOL bRet16
)
141 HMODULE16 hMod16
= MapHModuleLS( hModule
);
142 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
143 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
144 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
146 TRACE("(%08x %s, %08x%s, %08x%s, %04x, %s, %s)\n",
148 pModule
? (char *)NE_MODULE_NAME(pModule
) : "NULL dereference",
149 (UINT
)type
, HIWORD(type
)? (bUnicode
? debugstr_w((LPWSTR
)type
) : debugstr_a(type
)) : "",
150 (UINT
)name
, HIWORD(name
)? (bUnicode
? debugstr_w((LPWSTR
)name
) : debugstr_a(name
)) : "",
153 bRet16
? "NE" : "PE" );
159 /* 32-bit PE module */
160 LPWSTR typeStr
, nameStr
;
162 if ( HIWORD( type
) && !bUnicode
)
163 typeStr
= HEAP_strdupAtoW( GetProcessHeap(), 0, type
);
165 typeStr
= (LPWSTR
)type
;
166 if ( HIWORD( name
) && !bUnicode
)
167 nameStr
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
169 nameStr
= (LPWSTR
)name
;
171 hRsrc
= PE_FindResourceExW( wm
, nameStr
, typeStr
, lang
);
173 if ( HIWORD( type
) && !bUnicode
)
174 HeapFree( GetProcessHeap(), 0, typeStr
);
175 if ( HIWORD( name
) && !bUnicode
)
176 HeapFree( GetProcessHeap(), 0, nameStr
);
179 /* If we need to return 16-bit HRSRC, perform conversion */
181 hRsrc
= MapHRsrc32To16( pModule
, hRsrc
,
182 HIWORD( type
)? 0 : LOWORD( type
) );
186 /* 16-bit NE module */
187 LPSTR typeStr
, nameStr
;
189 if ( HIWORD( type
) && bUnicode
)
190 typeStr
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)type
);
192 typeStr
= (LPSTR
)type
;
193 if ( HIWORD( name
) && bUnicode
)
194 nameStr
= HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)name
);
196 nameStr
= (LPSTR
)name
;
198 hRsrc
= NE_FindResource( pModule
, nameStr
, typeStr
);
200 if ( HIWORD( type
) && bUnicode
)
201 HeapFree( GetProcessHeap(), 0, typeStr
);
202 if ( HIWORD( name
) && bUnicode
)
203 HeapFree( GetProcessHeap(), 0, nameStr
);
206 /* If we need to return 32-bit HRSRC, no conversion is necessary,
207 we simply use the 16-bit HRSRC as 32-bit HRSRC */
213 /**********************************************************************
217 static HRSRC
RES_FindResource( HMODULE hModule
, LPCSTR type
,
218 LPCSTR name
, WORD lang
,
219 BOOL bUnicode
, BOOL bRet16
)
224 hRsrc
= RES_FindResource2(hModule
, type
, name
, lang
, bUnicode
, bRet16
);
228 WARN("page fault\n");
229 SetLastError(ERROR_INVALID_PARAMETER
);
236 /**********************************************************************
239 static DWORD
RES_SizeofResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
243 HMODULE16 hMod16
= MapHModuleLS( hModule
);
244 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
245 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
246 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
248 TRACE("(%08x %s, %08x, %s)\n",
249 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
251 if ( !pModule
|| !hRsrc
) return 0;
255 /* 32-bit PE module */
257 /* If we got a 16-bit hRsrc, convert it */
258 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
260 size
= PE_SizeofResource( hModule
, hRsrc32
);
264 /* 16-bit NE module */
266 /* If we got a 32-bit hRsrc, we don't need to convert it */
268 size
= NE_SizeofResource( pModule
, hRsrc
);
274 /**********************************************************************
277 static HFILE
RES_AccessResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
279 HFILE hFile
= HFILE_ERROR
;
281 HMODULE16 hMod16
= MapHModuleLS( hModule
);
282 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
283 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
284 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
286 TRACE("(%08x %s, %08x, %s)\n",
287 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
289 if ( !pModule
|| !hRsrc
) return HFILE_ERROR
;
293 /* 32-bit PE module */
295 /* If we got a 16-bit hRsrc, convert it */
296 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
299 FIXME("32-bit modules not yet supported.\n" );
302 /* If we need to return a 16-bit file handle, convert it */
304 hFile
= FILE_AllocDosHandle( hFile
);
308 /* 16-bit NE module */
310 /* If we got a 32-bit hRsrc, we don't need to convert it */
312 hFile
= NE_AccessResource( pModule
, hRsrc
);
314 /* If we are to return a 32-bit file handle, convert it */
316 hFile
= FILE_GetHandle( hFile
);
322 /**********************************************************************
325 static HGLOBAL
RES_LoadResource( HMODULE hModule
, HRSRC hRsrc
, BOOL bRet16
)
329 HMODULE16 hMod16
= MapHModuleLS( hModule
);
330 NE_MODULE
*pModule
= NE_GetPtr( hMod16
);
331 WINE_MODREF
*wm
= pModule
&& pModule
->module32
?
332 MODULE32_LookupHMODULE( pModule
->module32
) : NULL
;
334 TRACE("(%08x %s, %08x, %s)\n",
335 hModule
, NE_MODULE_NAME(pModule
), hRsrc
, bRet16
? "NE" : "PE" );
337 if ( !pModule
|| !hRsrc
) return 0;
341 /* 32-bit PE module */
343 /* If we got a 16-bit hRsrc, convert it */
344 HRSRC hRsrc32
= HIWORD(hRsrc
)? hRsrc
: MapHRsrc16To32( pModule
, hRsrc
);
346 hMem
= PE_LoadResource( wm
, hRsrc32
);
348 /* If we need to return a 16-bit resource, convert it */
351 WORD type
= MapHRsrc16ToType( pModule
, hRsrc
);
352 DWORD size
= SizeofResource( hModule
, hRsrc
);
353 LPVOID bits
= LockResource( hMem
);
355 hMem
= NE_LoadPEResource( pModule
, type
, bits
, size
);
360 /* 16-bit NE module */
362 /* If we got a 32-bit hRsrc, we don't need to convert it */
364 hMem
= NE_LoadResource( pModule
, hRsrc
);
366 /* If we are to return a 32-bit resource, we should probably
367 convert it but we don't for now. FIXME !!! */
373 /**********************************************************************
376 static LPVOID
RES_LockResource( HGLOBAL handle
, BOOL bRet16
)
380 TRACE("(%08x, %s)\n", handle
, bRet16
? "NE" : "PE" );
382 if ( HIWORD( handle
) )
384 /* 32-bit memory handle */
387 FIXME("can't return SEGPTR to 32-bit resource %08x.\n", handle
);
389 bits
= (LPVOID
)handle
;
393 /* 16-bit memory handle */
395 /* May need to reload the resource if discarded */
396 SEGPTR segPtr
= WIN16_GlobalLock16( handle
);
399 bits
= (LPVOID
)segPtr
;
401 bits
= PTR_SEG_TO_LIN( segPtr
);
407 /**********************************************************************
410 static BOOL
RES_FreeResource( HGLOBAL handle
)
412 HGLOBAL retv
= handle
;
414 TRACE("(%08x)\n", handle
);
416 if ( HIWORD( handle
) )
418 /* 32-bit memory handle: nothing to do */
422 /* 16-bit memory handle */
423 NE_MODULE
*pModule
= NE_GetPtr( FarGetOwner16( handle
) );
425 /* Try NE resource first */
426 retv
= NE_FreeResource( pModule
, handle
);
428 /* If this failed, call USER.DestroyIcon32; this will check
429 whether it is a shared cursor/icon; if not it will call
432 if ( Callout
.DestroyIcon32
)
433 retv
= Callout
.DestroyIcon32( handle
, CID_RESOURCE
);
435 retv
= GlobalFree16( handle
);
443 /**********************************************************************
444 * FindResource16 (KERNEL.60)
446 HRSRC16 WINAPI
FindResource16( HMODULE16 hModule
, SEGPTR name
, SEGPTR type
)
448 LPCSTR nameStr
= HIWORD(name
)? PTR_SEG_TO_LIN(name
) : (LPCSTR
)name
;
449 LPCSTR typeStr
= HIWORD(type
)? PTR_SEG_TO_LIN(type
) : (LPCSTR
)type
;
451 return RES_FindResource( hModule
, typeStr
, nameStr
,
452 WINE_LanguageId
, FALSE
, TRUE
);
455 /**********************************************************************
456 * FindResourceA (KERNEL32.128)
458 HANDLE WINAPI
FindResourceA( HMODULE hModule
, LPCSTR name
, LPCSTR type
)
460 return RES_FindResource( hModule
, type
, name
,
461 WINE_LanguageId
, FALSE
, FALSE
);
464 /**********************************************************************
465 * FindResourceExA (KERNEL32.129)
467 HANDLE WINAPI
FindResourceExA( HMODULE hModule
,
468 LPCSTR type
, LPCSTR name
, WORD lang
)
470 return RES_FindResource( hModule
, type
, name
,
471 lang
, FALSE
, FALSE
);
474 /**********************************************************************
475 * FindResourceExW (KERNEL32.130)
477 HRSRC WINAPI
FindResourceExW( HMODULE hModule
,
478 LPCWSTR type
, LPCWSTR name
, WORD lang
)
480 return RES_FindResource( hModule
, (LPCSTR
)type
, (LPCSTR
)name
,
484 /**********************************************************************
485 * FindResourceW (KERNEL32.131)
487 HRSRC WINAPI
FindResourceW(HINSTANCE hModule
, LPCWSTR name
, LPCWSTR type
)
489 return RES_FindResource( hModule
, (LPCSTR
)type
, (LPCSTR
)name
,
490 WINE_LanguageId
, TRUE
, FALSE
);
493 /**********************************************************************
494 * LoadResource16 (KERNEL.61)
496 HGLOBAL16 WINAPI
LoadResource16( HMODULE16 hModule
, HRSRC16 hRsrc
)
498 return RES_LoadResource( hModule
, hRsrc
, TRUE
);
501 /**********************************************************************
502 * LoadResource (KERNEL32.370)
504 HGLOBAL WINAPI
LoadResource( HINSTANCE hModule
, HRSRC hRsrc
)
506 return RES_LoadResource( hModule
, hRsrc
, FALSE
);
509 /**********************************************************************
510 * LockResource16 (KERNEL.62)
512 SEGPTR WINAPI
WIN16_LockResource16( HGLOBAL16 handle
)
514 return (SEGPTR
)RES_LockResource( handle
, TRUE
);
516 LPVOID WINAPI
LockResource16( HGLOBAL16 handle
)
518 return RES_LockResource( handle
, FALSE
);
521 /**********************************************************************
522 * LockResource (KERNEL32.384)
524 LPVOID WINAPI
LockResource( HGLOBAL handle
)
526 return RES_LockResource( handle
, FALSE
);
529 /**********************************************************************
530 * FreeResource16 (KERNEL.63)
532 BOOL16 WINAPI
FreeResource16( HGLOBAL16 handle
)
534 return RES_FreeResource( handle
);
537 /**********************************************************************
538 * FreeResource (KERNEL32.145)
540 BOOL WINAPI
FreeResource( HGLOBAL handle
)
542 return RES_FreeResource( handle
);
545 /**********************************************************************
546 * AccessResource16 (KERNEL.64)
548 INT16 WINAPI
AccessResource16( HINSTANCE16 hModule
, HRSRC16 hRsrc
)
550 return RES_AccessResource( hModule
, hRsrc
, TRUE
);
553 /**********************************************************************
554 * AccessResource (KERNEL32.64)
556 INT WINAPI
AccessResource( HMODULE hModule
, HRSRC hRsrc
)
558 return RES_AccessResource( hModule
, hRsrc
, FALSE
);
561 /**********************************************************************
562 * SizeofResource16 (KERNEL.65)
564 DWORD WINAPI
SizeofResource16( HMODULE16 hModule
, HRSRC16 hRsrc
)
566 return RES_SizeofResource( hModule
, hRsrc
, TRUE
);
569 /**********************************************************************
570 * SizeofResource (KERNEL32.522)
572 DWORD WINAPI
SizeofResource( HINSTANCE hModule
, HRSRC hRsrc
)
574 return RES_SizeofResource( hModule
, hRsrc
, FALSE
);
579 /**********************************************************************
580 * LoadAccelerators16 [USER.177]
582 HACCEL16 WINAPI
LoadAccelerators16(HINSTANCE16 instance
, SEGPTR lpTableName
)
586 if (HIWORD(lpTableName
))
587 TRACE_(accel
)("%04x '%s'\n",
588 instance
, (char *)PTR_SEG_TO_LIN( lpTableName
) );
590 TRACE_(accel
)("%04x %04x\n",
591 instance
, LOWORD(lpTableName
) );
593 if (!(hRsrc
= FindResource16( instance
, lpTableName
, RT_ACCELERATOR16
))) {
594 WARN_(accel
)("couldn't find accelerator table resource\n");
598 TRACE_(accel
)("returning HACCEL 0x%x\n", hRsrc
);
599 return LoadResource16(instance
,hRsrc
);
602 /**********************************************************************
603 * LoadAcceleratorsW [USER.177]
604 * The image layout seems to look like this (not 100% sure):
605 * 00: BYTE type type of accelerator
606 * 01: BYTE pad (to WORD boundary)
609 * 06: WORD pad (to DWORD boundary)
611 HACCEL WINAPI
LoadAcceleratorsW(HINSTANCE instance
,LPCWSTR lpTableName
)
614 HACCEL hMem
,hRetval
=0;
617 if (HIWORD(lpTableName
))
618 TRACE_(accel
)("%p '%s'\n",
619 (LPVOID
)instance
, (char *)( lpTableName
) );
621 TRACE_(accel
)("%p 0x%04x\n",
622 (LPVOID
)instance
, LOWORD(lpTableName
) );
624 if (!(hRsrc
= FindResourceW( instance
, lpTableName
, RT_ACCELERATORW
)))
626 WARN_(accel
)("couldn't find accelerator table resource\n");
628 hMem
= LoadResource( instance
, hRsrc
);
629 size
= SizeofResource( instance
, hRsrc
);
630 if(size
>=sizeof(PE_ACCEL
))
632 LPPE_ACCEL accel_table
= (LPPE_ACCEL
) hMem
;
634 int i
,nrofaccells
= size
/sizeof(PE_ACCEL
);
636 hRetval
= GlobalAlloc16(0,sizeof(ACCEL16
)*nrofaccells
);
637 accel16
= (LPACCEL16
)GlobalLock16(hRetval
);
638 for (i
=0;i
<nrofaccells
;i
++) {
639 accel16
[i
].fVirt
= accel_table
[i
].fVirt
;
640 accel16
[i
].key
= accel_table
[i
].key
;
641 accel16
[i
].cmd
= accel_table
[i
].cmd
;
643 accel16
[i
-1].fVirt
|= 0x80;
646 TRACE_(accel
)("returning HACCEL 0x%x\n", hRsrc
);
650 /***********************************************************************
653 HACCEL WINAPI
LoadAcceleratorsA(HINSTANCE instance
,LPCSTR lpTableName
)
657 if (HIWORD(lpTableName
))
658 uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, lpTableName
);
660 uni
= (LPWSTR
)lpTableName
;
661 result
= LoadAcceleratorsW(instance
,uni
);
662 if (HIWORD(uni
)) HeapFree( GetProcessHeap(), 0, uni
);
666 /**********************************************************************
667 * CopyAcceleratorTableA (USER32.58)
669 INT WINAPI
CopyAcceleratorTableA(HACCEL src
, LPACCEL dst
, INT entries
)
671 return CopyAcceleratorTableW(src
, dst
, entries
);
674 /**********************************************************************
675 * CopyAcceleratorTableW (USER32.59)
677 * By mortene@pvv.org 980321
679 INT WINAPI
CopyAcceleratorTableW(HACCEL src
, LPACCEL dst
,
683 LPACCEL16 accel
= (LPACCEL16
)GlobalLock16(src
);
686 /* Do parameter checking to avoid the explosions and the screaming
687 as far as possible. */
688 if((dst
&& (entries
< 1)) || (src
== (HACCEL
)NULL
) || !accel
) {
689 WARN_(accel
)("Application sent invalid parameters (%p %p %d).\n",
690 (LPVOID
)src
, (LPVOID
)dst
, entries
);
693 xsize
= GlobalSize16(src
)/sizeof(ACCEL16
);
694 if (xsize
>entries
) entries
=xsize
;
698 /* Spit out some debugging information. */
699 TRACE_(accel
)("accel %d: type 0x%02x, event '%c', IDval 0x%04x.\n",
700 i
, accel
[i
].fVirt
, accel
[i
].key
, accel
[i
].cmd
);
702 /* Copy data to the destination structure array (if dst == NULL,
703 we're just supposed to count the number of entries). */
705 dst
[i
].fVirt
= accel
[i
].fVirt
;
706 dst
[i
].key
= accel
[i
].key
;
707 dst
[i
].cmd
= accel
[i
].cmd
;
709 /* Check if we've reached the end of the application supplied
710 accelerator table. */
712 /* Turn off the high order bit, just in case. */
713 dst
[i
].fVirt
&= 0x7f;
718 /* The highest order bit seems to mark the end of the accelerator
719 resource table, but not always. Use GlobalSize() check too. */
720 if((accel
[i
].fVirt
& 0x80) != 0) done
= TRUE
;
728 /*********************************************************************
729 * CreateAcceleratorTableA (USER32.64)
731 * By mortene@pvv.org 980321
733 HACCEL WINAPI
CreateAcceleratorTableA(LPACCEL lpaccel
, INT cEntries
)
739 /* Do parameter checking just in case someone's trying to be
742 WARN_(accel
)("Application sent invalid parameters (%p %d).\n",
744 SetLastError(ERROR_INVALID_PARAMETER
);
747 FIXME_(accel
)("should check that the accelerator descriptions are valid,"
748 " return NULL and SetLastError() if not.\n");
751 /* Allocate memory and copy the table. */
752 hAccel
= GlobalAlloc16(0,cEntries
*sizeof(ACCEL16
));
754 TRACE_(accel
)("handle %x\n", hAccel
);
756 ERR_(accel
)("Out of memory.\n");
757 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
760 accel
= GlobalLock16(hAccel
);
761 for (i
=0;i
<cEntries
;i
++) {
762 accel
[i
].fVirt
= lpaccel
[i
].fVirt
;
763 accel
[i
].key
= lpaccel
[i
].key
;
764 accel
[i
].cmd
= lpaccel
[i
].cmd
;
766 /* Set the end-of-table terminator. */
767 accel
[cEntries
-1].fVirt
|= 0x80;
769 TRACE_(accel
)("Allocated accelerator handle %x\n", hAccel
);
773 /*********************************************************************
774 * CreateAcceleratorTableW (USER32.64)
778 HACCEL WINAPI
CreateAcceleratorTableW(LPACCEL lpaccel
, INT cEntries
)
785 /* Do parameter checking just in case someone's trying to be
788 WARN_(accel
)("Application sent invalid parameters (%p %d).\n",
790 SetLastError(ERROR_INVALID_PARAMETER
);
793 FIXME_(accel
)("should check that the accelerator descriptions are valid,"
794 " return NULL and SetLastError() if not.\n");
797 /* Allocate memory and copy the table. */
798 hAccel
= GlobalAlloc16(0,cEntries
*sizeof(ACCEL16
));
800 TRACE_(accel
)("handle %x\n", hAccel
);
802 ERR_(accel
)("Out of memory.\n");
803 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
806 accel
= GlobalLock16(hAccel
);
809 for (i
=0;i
<cEntries
;i
++) {
810 accel
[i
].fVirt
= lpaccel
[i
].fVirt
;
811 if( !(accel
[i
].fVirt
& FVIRTKEY
) ) {
812 ckey
= (char) lpaccel
[i
].key
;
813 if(!MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, &ckey
, 1, &accel
[i
].key
, 1))
814 WARN_(accel
)("Error converting ASCII accelerator table to Unicode");
817 accel
[i
].key
= lpaccel
[i
].key
;
818 accel
[i
].cmd
= lpaccel
[i
].cmd
;
821 /* Set the end-of-table terminator. */
822 accel
[cEntries
-1].fVirt
|= 0x80;
824 TRACE_(accel
)("Allocated accelerator handle %x\n", hAccel
);
828 /******************************************************************************
829 * DestroyAcceleratorTable [USER32.130]
830 * Destroys an accelerator table
833 * By mortene@pvv.org 980321
836 * handle [I] Handle to accelerator table
840 BOOL WINAPI
DestroyAcceleratorTable( HACCEL handle
)
842 return GlobalFree16(handle
);
845 /**********************************************************************
848 INT16 WINAPI
LoadString16( HINSTANCE16 instance
, UINT16 resource_id
,
849 LPSTR buffer
, INT16 buflen
)
857 TRACE("inst=%04x id=%04x buff=%08x len=%d\n",
858 instance
, resource_id
, (int) buffer
, buflen
);
860 hrsrc
= FindResource16( instance
, (SEGPTR
)((resource_id
>>4)+1), RT_STRING16
);
861 if (!hrsrc
) return 0;
862 hmem
= LoadResource16( instance
, hrsrc
);
865 p
= LockResource16(hmem
);
866 string_num
= resource_id
& 0x000f;
867 for (i
= 0; i
< string_num
; i
++)
870 TRACE("strlen = %d\n", (int)*p
);
872 if (buffer
== NULL
) return *p
;
873 i
= min(buflen
- 1, *p
);
875 memcpy(buffer
, p
+ 1, i
);
882 WARN("Dont know why caller give buflen=%d *p=%d trying to obtain string '%s'\n", buflen
, *p
, p
+ 1);
884 FreeResource16( hmem
);
886 TRACE("'%s' loaded !\n", buffer
);
890 /**********************************************************************
891 * LoadStringW (USER32.376)
893 INT WINAPI
LoadStringW( HINSTANCE instance
, UINT resource_id
,
894 LPWSTR buffer
, INT buflen
)
902 if (HIWORD(resource_id
)==0xFFFF) /* netscape 3 passes this */
903 resource_id
= (UINT
)(-((INT
)resource_id
));
904 TRACE("instance = %04x, id = %04x, buffer = %08x, "
905 "length = %d\n", instance
, (int)resource_id
, (int) buffer
, buflen
);
907 /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out
909 hrsrc
= FindResourceW( instance
, (LPCWSTR
)(((resource_id
>>4)&0xffff)+1),
911 if (!hrsrc
) return 0;
912 hmem
= LoadResource( instance
, hrsrc
);
915 p
= LockResource(hmem
);
916 string_num
= resource_id
& 0x000f;
917 for (i
= 0; i
< string_num
; i
++)
920 TRACE("strlen = %d\n", (int)*p
);
922 if (buffer
== NULL
) return *p
;
923 i
= min(buflen
- 1, *p
);
925 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
926 buffer
[i
] = (WCHAR
) 0;
929 buffer
[0] = (WCHAR
) 0;
933 WARN("Dont know why caller give buflen=%d *p=%d trying to obtain string '%s'\n", buflen
, *p
, p
+ 1);
937 TRACE("%s loaded !\n", debugstr_w(buffer
));
941 /**********************************************************************
942 * LoadStringA (USER32.375)
944 INT WINAPI
LoadStringA( HINSTANCE instance
, UINT resource_id
,
945 LPSTR buffer
, INT buflen
)
953 if ( buffer
!= NULL
&& buflen
> 0 )
956 wbuflen
= LoadStringW(instance
,resource_id
,NULL
,0);
962 wbuf
= HeapAlloc( GetProcessHeap(), 0, wbuflen
* sizeof(WCHAR
) );
963 wbuflen
= LoadStringW(instance
,resource_id
,wbuf
,wbuflen
);
966 abuflen
= WideCharToMultiByte(CP_ACP
,0,wbuf
,wbuflen
,NULL
,0,NULL
,NULL
);
969 if ( buffer
== NULL
|| buflen
== 0 )
973 abuf
= HeapAlloc( GetProcessHeap(), 0, abuflen
* sizeof(CHAR
) );
974 abuflen
= WideCharToMultiByte(CP_ACP
,0,wbuf
,wbuflen
,abuf
,abuflen
,NULL
,NULL
);
977 abuflen
= min(abuflen
,buflen
- 1);
978 memcpy( buffer
, abuf
, abuflen
);
982 HeapFree( GetProcessHeap(), 0, abuf
);
986 HeapFree( GetProcessHeap(), 0, wbuf
);
991 /* Messages...used by FormatMessage32* (KERNEL32.something)
993 * They can be specified either directly or using a message ID and
994 * loading them from the resource.
996 * The resourcedata has following format:
998 * 0: DWORD nrofentries
999 * nrofentries * subentry:
1000 * 0: DWORD firstentry
1001 * 4: DWORD lastentry
1002 * 8: DWORD offset from start to the stringentries
1004 * (lastentry-firstentry) * stringentry:
1005 * 0: WORD len (0 marks end)
1008 * (stringentry i of a subentry refers to the ID 'firstentry+i')
1010 * Yes, ANSI strings in win32 resources. Go figure.
1013 /**********************************************************************
1014 * LoadMessageA (internal)
1016 INT WINAPI
LoadMessageA( HMODULE instance
, UINT id
, WORD lang
,
1017 LPSTR buffer
, INT buflen
)
1021 PMESSAGE_RESOURCE_DATA mrd
;
1022 PMESSAGE_RESOURCE_BLOCK mrb
;
1023 PMESSAGE_RESOURCE_ENTRY mre
;
1026 TRACE("instance = %08lx, id = %08lx, buffer = %p, length = %ld\n", (DWORD
)instance
, (DWORD
)id
, buffer
, (DWORD
)buflen
);
1028 /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/
1029 hrsrc
= FindResourceExW(instance
,RT_MESSAGELISTW
,(LPWSTR
)1,lang
);
1030 if (!hrsrc
) return 0;
1031 hmem
= LoadResource( instance
, hrsrc
);
1032 if (!hmem
) return 0;
1034 mrd
= (PMESSAGE_RESOURCE_DATA
)LockResource(hmem
);
1036 mrb
= &(mrd
->Blocks
[0]);
1037 for (i
=mrd
->NumberOfBlocks
;i
--;) {
1038 if ((id
>=mrb
->LowId
) && (id
<=mrb
->HighId
)) {
1039 mre
= (PMESSAGE_RESOURCE_ENTRY
)(((char*)mrd
)+mrb
->OffsetToEntries
);
1050 mre
= (PMESSAGE_RESOURCE_ENTRY
)(((char*)mre
)+(mre
->Length
));
1053 TRACE(" - strlen=%d\n",slen
);
1054 i
= min(buflen
- 1, slen
);
1058 lstrcpynA(buffer
,(char*)mre
->Text
,i
);
1067 TRACE("'%s' copied !\n", buffer
);
1071 /**********************************************************************
1072 * LoadMessageW (internal)
1074 INT WINAPI
LoadMessageW( HMODULE instance
, UINT id
, WORD lang
,
1075 LPWSTR buffer
, INT buflen
)
1078 LPSTR buffer2
= NULL
;
1079 if (buffer
&& buflen
)
1080 buffer2
= HeapAlloc( GetProcessHeap(), 0, buflen
);
1081 retval
= LoadMessageA(instance
,id
,lang
,buffer2
,buflen
);
1085 lstrcpynAtoW( buffer
, buffer2
, buflen
);
1086 retval
= lstrlenW( buffer
);
1088 HeapFree( GetProcessHeap(), 0, buffer2
);
1094 /**********************************************************************
1095 * EnumResourceTypesA (KERNEL32.90)
1097 BOOL WINAPI
EnumResourceTypesA( HMODULE hmodule
,ENUMRESTYPEPROCA lpfun
,
1100 /* FIXME: move WINE_MODREF stuff here */
1101 return PE_EnumResourceTypesA(hmodule
,lpfun
,lParam
);
1104 /**********************************************************************
1105 * EnumResourceTypesW (KERNEL32.91)
1107 BOOL WINAPI
EnumResourceTypesW( HMODULE hmodule
,ENUMRESTYPEPROCW lpfun
,
1110 /* FIXME: move WINE_MODREF stuff here */
1111 return PE_EnumResourceTypesW(hmodule
,lpfun
,lParam
);
1114 /**********************************************************************
1115 * EnumResourceNamesA (KERNEL32.88)
1117 BOOL WINAPI
EnumResourceNamesA( HMODULE hmodule
, LPCSTR type
,
1118 ENUMRESNAMEPROCA lpfun
, LONG lParam
)
1120 /* FIXME: move WINE_MODREF stuff here */
1121 return PE_EnumResourceNamesA(hmodule
,type
,lpfun
,lParam
);
1123 /**********************************************************************
1124 * EnumResourceNamesW (KERNEL32.89)
1126 BOOL WINAPI
EnumResourceNamesW( HMODULE hmodule
, LPCWSTR type
,
1127 ENUMRESNAMEPROCW lpfun
, LONG lParam
)
1129 /* FIXME: move WINE_MODREF stuff here */
1130 return PE_EnumResourceNamesW(hmodule
,type
,lpfun
,lParam
);
1133 /**********************************************************************
1134 * EnumResourceLanguagesA (KERNEL32.86)
1136 BOOL WINAPI
EnumResourceLanguagesA( HMODULE hmodule
, LPCSTR type
,
1137 LPCSTR name
, ENUMRESLANGPROCA lpfun
,
1140 /* FIXME: move WINE_MODREF stuff here */
1141 return PE_EnumResourceLanguagesA(hmodule
,type
,name
,lpfun
,lParam
);
1143 /**********************************************************************
1144 * EnumResourceLanguagesW (KERNEL32.87)
1146 BOOL WINAPI
EnumResourceLanguagesW( HMODULE hmodule
, LPCWSTR type
,
1147 LPCWSTR name
, ENUMRESLANGPROCW lpfun
,
1150 /* FIXME: move WINE_MODREF stuff here */
1151 return PE_EnumResourceLanguagesW(hmodule
,type
,name
,lpfun
,lParam
);