/* * USER resource functions * * Copyright 1993 Robert J. Amstadt * Copyright 1995 Alexandre Julliard * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include "windef.h" #include "winbase.h" #include "winerror.h" #include "winnls.h" #include "wine/winbase16.h" #include "wine/winuser16.h" #include "wownt32.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(resource); WINE_DECLARE_DEBUG_CHANNEL(accel); /* this is the 8 byte accel struct used in Win32 resources (internal only) */ typedef struct { WORD fVirt; WORD key; WORD cmd; WORD pad; } PE_ACCEL, *LPPE_ACCEL; /********************************************************************** * LoadAccelerators [USER.177] */ HACCEL16 WINAPI LoadAccelerators16(HINSTANCE16 instance, LPCSTR lpTableName) { HRSRC16 hRsrc; TRACE_(accel)("%04x %s\n", instance, debugstr_a(lpTableName) ); if (!(hRsrc = FindResource16( instance, lpTableName, (LPSTR)RT_ACCELERATOR ))) { WARN_(accel)("couldn't find accelerator table resource\n"); return 0; } TRACE_(accel)("returning HACCEL 0x%x\n", hRsrc); return LoadResource16(instance,hRsrc); } /********************************************************************** * LoadAcceleratorsW (USER32.@) * The image layout seems to look like this (not 100% sure): * 00: WORD type type of accelerator * 02: WORD event * 04: WORD IDval * 06: WORD pad (to DWORD boundary) */ HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance,LPCWSTR lpTableName) { HRSRC hRsrc; HACCEL hMem; HACCEL16 hRetval=0; DWORD size; if (HIWORD(lpTableName)) TRACE_(accel)("%p '%s'\n", (LPVOID)instance, (const char *)( lpTableName ) ); else TRACE_(accel)("%p 0x%04x\n", (LPVOID)instance, LOWORD(lpTableName) ); if (!(hRsrc = FindResourceW( instance, lpTableName, (LPWSTR)RT_ACCELERATOR ))) { WARN_(accel)("couldn't find accelerator table resource\n"); } else { hMem = LoadResource( instance, hRsrc ); size = SizeofResource( instance, hRsrc ); if(size>=sizeof(PE_ACCEL)) { LPPE_ACCEL accel_table = (LPPE_ACCEL) hMem; LPACCEL16 accel16; int i,nrofaccells = size/sizeof(PE_ACCEL); hRetval = GlobalAlloc16(0,sizeof(ACCEL16)*nrofaccells); accel16 = (LPACCEL16)GlobalLock16(hRetval); for (i=0;i>4)+1), (LPSTR)RT_STRING ); if (!hrsrc) return 0; hmem = LoadResource16( instance, hrsrc ); if (!hmem) return 0; p = LockResource16(hmem); string_num = resource_id & 0x000f; for (i = 0; i < string_num; i++) p += *p + 1; TRACE("strlen = %d\n", (int)*p ); if (buffer == NULL) return *p; i = min(buflen - 1, *p); if (i > 0) { memcpy(buffer, p + 1, i); buffer[i] = '\0'; } else { if (buflen > 1) { buffer[0] = '\0'; return 0; } WARN("Don't know why caller gave buflen=%d *p=%d trying to obtain string '%s'\n", buflen, *p, p + 1); } FreeResource16( hmem ); TRACE("'%s' loaded !\n", buffer); return i; } /********************************************************************** * LoadStringW (USER32.@) */ INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen ) { HGLOBAL hmem; HRSRC hrsrc; WCHAR *p; int string_num; int i; if (HIWORD(resource_id)==0xFFFF) /* netscape 3 passes this */ resource_id = (UINT)(-((INT)resource_id)); TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n", instance, resource_id, buffer, buflen); /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out * 20 - 31. */ hrsrc = FindResourceW( instance, MAKEINTRESOURCEW(((resource_id>>4)&0xffff)+1), (LPWSTR)RT_STRING ); if (!hrsrc) return 0; hmem = LoadResource( instance, hrsrc ); if (!hmem) return 0; p = LockResource(hmem); string_num = resource_id & 0x000f; for (i = 0; i < string_num; i++) p += *p + 1; TRACE("strlen = %d\n", (int)*p ); if (buffer == NULL) return *p; i = min(buflen - 1, *p); if (i > 0) { memcpy(buffer, p + 1, i * sizeof (WCHAR)); buffer[i] = (WCHAR) 0; } else { if (buflen > 1) { buffer[0] = (WCHAR) 0; return 0; } #if 0 WARN("Don't know why caller gave buflen=%d *p=%d trying to obtain string '%s'\n", buflen, *p, p + 1); #endif } TRACE("%s loaded !\n", debugstr_w(buffer)); return i; } /********************************************************************** * LoadStringA (USER32.@) */ INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen ) { INT retval; LPWSTR wbuf; TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n", instance, resource_id, buffer, buflen); if(buffer == NULL) /* asked size of string */ return LoadStringW(instance, resource_id, NULL, 0); wbuf = HeapAlloc(GetProcessHeap(), 0, buflen * sizeof(WCHAR)); if(!wbuf) return 0; retval = LoadStringW(instance, resource_id, wbuf, buflen); if(retval != 0) { retval = WideCharToMultiByte(CP_ACP, 0, wbuf, retval, buffer, buflen - 1, NULL, NULL); buffer[retval] = 0; TRACE("%s loaded !\n", debugstr_a(buffer)); } else buffer[0] = 0; /* no check of buflen here */ HeapFree( GetProcessHeap(), 0, wbuf ); return retval; } /********************************************************************** * GetGuiResources (USER32.@) */ DWORD WINAPI GetGuiResources( HANDLE hProcess, DWORD uiFlags ) { FIXME("(%p,%lx): stub\n",hProcess,uiFlags); SetLastError( ERROR_CALL_NOT_IMPLEMENTED ); return 0; }