2 * USER resource functions
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995, 2009 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(resource
);
31 WINE_DECLARE_DEBUG_CHANNEL(accel
);
33 /* this is the 8 byte accel struct used in Win32 resources (internal only) */
42 /**********************************************************************
43 * LoadAcceleratorsW (USER32.@)
45 HACCEL WINAPI
LoadAcceleratorsW(HINSTANCE instance
, LPCWSTR name
)
47 const PE_ACCEL
*pe_table
;
54 if (!(rsrc
= FindResourceW( instance
, name
, (LPWSTR
)RT_ACCELERATOR
))) return 0;
55 pe_table
= LoadResource( instance
, rsrc
);
56 count
= SizeofResource( instance
, rsrc
) / sizeof(*pe_table
);
58 table
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*table
) );
60 for (i
= 0; i
< count
; i
++)
62 table
[i
].fVirt
= pe_table
[i
].fVirt
;
63 table
[i
].key
= pe_table
[i
].key
;
64 table
[i
].cmd
= pe_table
[i
].cmd
;
66 handle
= NtUserCreateAcceleratorTable( table
, count
);
67 HeapFree( GetProcessHeap(), 0, table
);
68 TRACE_(accel
)("%p %s returning %p\n", instance
, debugstr_w(name
), handle
);
72 /***********************************************************************
73 * LoadAcceleratorsA (USER32.@)
75 HACCEL WINAPI
LoadAcceleratorsA(HINSTANCE instance
,LPCSTR lpTableName
)
81 if (IS_INTRESOURCE(lpTableName
)) return LoadAcceleratorsW( instance
, (LPCWSTR
)lpTableName
);
83 len
= MultiByteToWideChar( CP_ACP
, 0, lpTableName
, -1, NULL
, 0 );
84 if ((uni
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
86 MultiByteToWideChar( CP_ACP
, 0, lpTableName
, -1, uni
, len
);
87 result
= LoadAcceleratorsW(instance
,uni
);
88 HeapFree( GetProcessHeap(), 0, uni
);
93 /**********************************************************************
94 * CopyAcceleratorTableA (USER32.@)
96 INT WINAPI
CopyAcceleratorTableA(HACCEL src
, LPACCEL dst
, INT count
)
99 int i
, ret
= NtUserCopyAcceleratorTable( src
, dst
, count
);
103 for (i
= 0; i
< ret
; i
++)
105 if (dst
[i
].fVirt
& FVIRTKEY
) continue;
106 WideCharToMultiByte( CP_ACP
, 0, &dst
[i
].key
, 1, &ch
, 1, NULL
, NULL
);
113 /*********************************************************************
114 * CreateAcceleratorTableA (USER32.@)
116 HACCEL WINAPI
CreateAcceleratorTableA( ACCEL
*accel
, INT count
)
124 SetLastError( ERROR_INVALID_PARAMETER
);
127 table
= HeapAlloc( GetProcessHeap(), 0, count
* sizeof(*table
) );
128 if (!table
) return 0;
129 for (i
= 0; i
< count
; i
++)
131 table
[i
].fVirt
= accel
[i
].fVirt
;
132 table
[i
].cmd
= accel
[i
].cmd
;
133 if (!(accel
[i
].fVirt
& FVIRTKEY
))
135 char ch
= accel
[i
].key
;
136 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &table
[i
].key
, 1 );
138 else table
[i
].key
= accel
[i
].key
;
140 handle
= NtUserCreateAcceleratorTable( table
, count
);
141 HeapFree( GetProcessHeap(), 0, table
);
142 TRACE_(accel
)("returning %p\n", handle
);
146 /**********************************************************************
147 * LoadStringW (USER32.@)
149 INT WINAPI DECLSPEC_HOTPATCH
LoadStringW( HINSTANCE instance
, UINT resource_id
,
150 LPWSTR buffer
, INT buflen
)
158 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
159 instance
, resource_id
, buffer
, buflen
);
164 /* Use loword (incremented by 1) as resourceid */
165 hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
167 if (!hrsrc
) return 0;
168 hmem
= LoadResource( instance
, hrsrc
);
171 p
= LockResource(hmem
);
172 string_num
= resource_id
& 0x000f;
173 for (i
= 0; i
< string_num
; i
++)
176 TRACE("strlen = %d\n", (int)*p
);
178 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
179 it is assumed that buffer is actually a (LPWSTR *) */
182 *((LPWSTR
*)buffer
) = p
+ 1;
186 i
= min(buflen
- 1, *p
);
188 memcpy(buffer
, p
+ 1, i
* sizeof (WCHAR
));
197 TRACE("%s loaded !\n", debugstr_w(buffer
));
201 /**********************************************************************
202 * LoadStringA (USER32.@)
204 INT WINAPI DECLSPEC_HOTPATCH
LoadStringA( HINSTANCE instance
, UINT resource_id
, LPSTR buffer
, INT buflen
)
210 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
211 instance
, resource_id
, buffer
, buflen
);
213 if (!buflen
) return -1;
215 /* Use loword (incremented by 1) as resourceid */
216 if ((hrsrc
= FindResourceW( instance
, MAKEINTRESOURCEW((LOWORD(resource_id
) >> 4) + 1),
217 (LPWSTR
)RT_STRING
)) &&
218 (hmem
= LoadResource( instance
, hrsrc
)))
220 const WCHAR
*p
= LockResource(hmem
);
221 unsigned int id
= resource_id
& 0x000f;
223 while (id
--) p
+= *p
+ 1;
225 RtlUnicodeToMultiByteN( buffer
, buflen
- 1, &retval
, p
+ 1, *p
* sizeof(WCHAR
) );
228 TRACE("returning %s\n", debugstr_a(buffer
));
232 /**********************************************************************
233 * GetGuiResources (USER32.@)
235 DWORD WINAPI
GetGuiResources( HANDLE hProcess
, DWORD uiFlags
)
237 static BOOL warn
= TRUE
;
240 FIXME("(%p,%lx): stub\n",hProcess
,uiFlags
);
244 SetLastError( ERROR_CALL_NOT_IMPLEMENTED
);