2 * PE->NE resource conversion functions
4 * Copyright 1998 Ulrich Weigand
8 #include "wine/winuser16.h"
11 #include "debugtools.h"
13 DEFAULT_DEBUG_CHANNEL(resource)
15 /**********************************************************************
16 * ConvertDialog32To16 (KERNEL.615)
18 VOID WINAPI ConvertDialog32To16( LPVOID dialog32, DWORD size, LPVOID dialog16 )
21 WORD nbItems, data, dialogEx;
24 style = *((DWORD *)dialog16)++ = *((DWORD *)p)++;
25 dialogEx = (style == 0xffff0001); /* DIALOGEX resource */
28 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* helpID */
29 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* exStyle */
30 style = *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* style */
33 ((DWORD *)p)++; /* exStyle ignored in 16-bit standard dialog */
35 nbItems = *((BYTE *)dialog16)++ = (BYTE)*((WORD *)p)++;
36 *((WORD *)dialog16)++ = *((WORD *)p)++; /* x */
37 *((WORD *)dialog16)++ = *((WORD *)p)++; /* y */
38 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cx */
39 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cy */
41 /* Transfer menu name */
44 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
45 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
46 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
47 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
48 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
49 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
53 /* Transfer class name */
56 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
57 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
58 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
59 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
60 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
61 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
65 /* Transfer window caption */
66 lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
67 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
68 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
70 /* Transfer font info */
71 if (style & DS_SETFONT)
73 *((WORD *)dialog16)++ = *((WORD *)p)++; /* pointSize */
76 *((WORD *)dialog16)++ = *((WORD *)p)++; /* weight */
77 *((WORD *)dialog16)++ = *((WORD *)p)++; /* italic */
79 lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p ); /* faceName */
80 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
81 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
84 /* Transfer dialog items */
87 /* align on DWORD boundary (32-bit only) */
88 p = (LPVOID)((((int)p) + 3) & ~3);
92 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* helpID */
93 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* exStyle */
94 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* style */
98 style = *((DWORD *)p)++; /* save style */
99 ((DWORD *)p)++; /* ignore exStyle */
102 *((WORD *)dialog16)++ = *((WORD *)p)++; /* x */
103 *((WORD *)dialog16)++ = *((WORD *)p)++; /* y */
104 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cx */
105 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cy */
108 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* ID */
111 *((WORD *)dialog16)++ = *((WORD *)p)++; /* ID */
112 *((DWORD *)dialog16)++ = style; /* style from above */
115 /* Transfer class name */
116 switch (*((WORD *)p))
118 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
119 case 0xffff: ((WORD *)p)++;
120 *((BYTE *)dialog16)++ = (BYTE)*((WORD *)p)++; break;
121 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
122 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
123 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
127 /* Transfer window name */
128 switch (*((WORD *)p))
130 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
131 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
132 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
133 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
134 ((LPSTR)dialog16) += lstrlenA( (LPSTR)dialog16 ) + 1;
135 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
140 data = *((WORD *)p)++;
142 *((WORD *)dialog16)++ = data;
144 *((BYTE *)dialog16)++ = (BYTE)data;
148 memcpy( dialog16, p, data );
149 (LPSTR)dialog16 += data;
158 /**********************************************************************
159 * GetDialog32Size (KERNEL.618)
161 WORD WINAPI GetDialog32Size16( LPVOID dialog32 )
164 WORD nbItems, data, dialogEx;
167 style = *((DWORD *)p)++;
168 dialogEx = (style == 0xffff0001); /* DIALOGEX resource */
171 ((DWORD *)p)++; /* helpID */
172 ((DWORD *)p)++; /* exStyle */
173 style = *((DWORD *)p)++; /* style */
176 ((DWORD *)p)++; /* exStyle */
178 nbItems = *((WORD *)p)++;
179 ((WORD *)p)++; /* x */
180 ((WORD *)p)++; /* y */
181 ((WORD *)p)++; /* cx */
182 ((WORD *)p)++; /* cy */
185 switch (*((WORD *)p))
187 case 0x0000: ((WORD *)p)++; break;
188 case 0xffff: ((WORD *)p) += 2; break;
189 default: ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1; break;
192 /* Skip class name */
193 switch (*((WORD *)p))
195 case 0x0000: ((WORD *)p)++; break;
196 case 0xffff: ((WORD *)p) += 2; break;
197 default: ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1; break;
200 /* Skip window caption */
201 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
204 if (style & DS_SETFONT)
206 ((WORD *)p)++; /* pointSize */
209 ((WORD *)p)++; /* weight */
210 ((WORD *)p)++; /* italic */
212 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1; /* faceName */
215 /* Skip dialog items */
218 /* align on DWORD boundary */
219 p = (LPVOID)((((int)p) + 3) & ~3);
223 ((DWORD *)p)++; /* helpID */
224 ((DWORD *)p)++; /* exStyle */
225 ((DWORD *)p)++; /* style */
229 ((DWORD *)p)++; /* style */
230 ((DWORD *)p)++; /* exStyle */
233 ((WORD *)p)++; /* x */
234 ((WORD *)p)++; /* y */
235 ((WORD *)p)++; /* cx */
236 ((WORD *)p)++; /* cy */
239 ((DWORD *)p)++; /* ID */
241 ((WORD *)p)++; /* ID */
243 /* Skip class name */
244 switch (*((WORD *)p))
246 case 0x0000: ((WORD *)p)++; break;
247 case 0xffff: ((WORD *)p) += 2; break;
248 default: ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1; break;
251 /* Skip window name */
252 switch (*((WORD *)p))
254 case 0x0000: ((WORD *)p)++; break;
255 case 0xffff: ((WORD *)p) += 2; break;
256 default: ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1; break;
260 data = *((WORD *)p)++;
267 return (WORD)((LPSTR)p - (LPSTR)dialog32);
270 /**********************************************************************
271 * ConvertMenu32To16 (KERNEL.616)
273 VOID WINAPI ConvertMenu32To16( LPVOID menu32, DWORD size, LPVOID menu16 )
276 WORD version, headersize, flags, level = 1;
278 version = *((WORD *)menu16)++ = *((WORD *)p)++;
279 headersize = *((WORD *)menu16)++ = *((WORD *)p)++;
282 memcpy( menu16, p, headersize );
283 ((LPSTR)menu16) += headersize;
284 ((LPSTR)p) += headersize;
288 if ( version == 0 ) /* standard */
290 flags = *((WORD *)menu16)++ = *((WORD *)p)++;
291 if ( !(flags & MF_POPUP) )
292 *((WORD *)menu16)++ = *((WORD *)p)++; /* ID */
296 lstrcpyWtoA( (LPSTR)menu16, (LPWSTR)p );
297 ((LPSTR)menu16) += lstrlenA( (LPSTR)menu16 ) + 1;
298 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
300 if ( flags & MF_END )
305 *((DWORD *)menu16)++ = *((DWORD *)p)++; /* fType */
306 *((DWORD *)menu16)++ = *((DWORD *)p)++; /* fState */
307 *((WORD *)menu16)++ = (WORD)*((DWORD *)p)++; /* ID */
308 flags = *((BYTE *)menu16)++ = (BYTE)*((WORD *)p)++;
310 lstrcpyWtoA( (LPSTR)menu16, (LPWSTR)p );
311 ((LPSTR)menu16) += lstrlenA( (LPSTR)menu16 ) + 1;
312 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
314 /* align on DWORD boundary (32-bit only) */
315 p = (LPVOID)((((int)p) + 3) & ~3);
317 /* If popup, transfer helpid */
320 *((DWORD *)menu16)++ = *((DWORD *)p)++;
324 if ( flags & MF_END )
329 /**********************************************************************
330 * GetMenu32Size (KERNEL.617)
332 WORD WINAPI GetMenu32Size16( LPVOID menu32 )
335 WORD version, headersize, flags, level = 1;
337 version = *((WORD *)p)++;
338 headersize = *((WORD *)p)++;
339 ((LPSTR)p) += headersize;
342 if ( version == 0 ) /* standard */
344 flags = *((WORD *)p)++;
345 if ( !(flags & MF_POPUP) )
346 ((WORD *)p)++; /* ID */
350 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
352 if ( flags & MF_END )
357 ((DWORD *)p)++; /* fType */
358 ((DWORD *)p)++; /* fState */
359 ((DWORD *)p)++; /* ID */
360 flags = *((WORD *)p)++;
362 ((LPWSTR)p) += lstrlenW( (LPWSTR)p ) + 1;
364 /* align on DWORD boundary (32-bit only) */
365 p = (LPVOID)((((int)p) + 3) & ~3);
367 /* If popup, skip helpid */
374 if ( flags & MF_END )
378 return (WORD)((LPSTR)p - (LPSTR)menu32);
381 /**********************************************************************
382 * ConvertAccelerator32To16
384 VOID ConvertAccelerator32To16( LPVOID acc32, DWORD size, LPVOID acc16 )
391 type = *((BYTE *)acc16)++ = *((BYTE *)acc32)++;
394 /* Copy event and IDval */
395 *((WORD *)acc16)++ = *((WORD *)acc32)++;
396 *((WORD *)acc16)++ = *((WORD *)acc32)++;
400 } while ( !( type & 0x80 ) );
403 /**********************************************************************
406 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size )
410 TRACE( resource, "module=%04x type=%04x\n", pModule->self, type );
411 if (!pModule || !bits || !size) return 0;
413 handle = GlobalAlloc16( 0, size );
418 ConvertMenu32To16( bits, size, GlobalLock16( handle ) );
422 ConvertDialog32To16( bits, size, GlobalLock16( handle ) );
425 case RT_ACCELERATOR16:
426 ConvertAccelerator32To16( bits, size, GlobalLock16( handle ) );
430 FIXME( resource, "not yet implemented!\n" );
434 memcpy( GlobalLock16( handle ), bits, size );