2 * PE->NE resource conversion functions
4 * Copyright 1998 Ulrich Weigand
10 #include "wine/winuser16.h"
11 #include "wine/unicode.h"
12 #include "wine/winestring.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(resource);
18 /**********************************************************************
19 * ConvertDialog32To16 (KERNEL.615)
21 VOID WINAPI ConvertDialog32To16( LPVOID dialog32, DWORD size, LPVOID dialog16 )
24 WORD nbItems, data, dialogEx;
27 style = *((DWORD *)dialog16)++ = *((DWORD *)p)++;
28 dialogEx = (style == 0xffff0001); /* DIALOGEX resource */
31 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* helpID */
32 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* exStyle */
33 style = *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* style */
36 ((DWORD *)p)++; /* exStyle ignored in 16-bit standard dialog */
38 nbItems = *((BYTE *)dialog16)++ = (BYTE)*((WORD *)p)++;
39 *((WORD *)dialog16)++ = *((WORD *)p)++; /* x */
40 *((WORD *)dialog16)++ = *((WORD *)p)++; /* y */
41 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cx */
42 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cy */
44 /* Transfer menu name */
47 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
48 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
49 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
50 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
51 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
52 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
56 /* Transfer class name */
59 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
60 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
61 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
62 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
63 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
64 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
68 /* Transfer window caption */
69 lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
70 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
71 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
73 /* Transfer font info */
74 if (style & DS_SETFONT)
76 *((WORD *)dialog16)++ = *((WORD *)p)++; /* pointSize */
79 *((WORD *)dialog16)++ = *((WORD *)p)++; /* weight */
80 *((WORD *)dialog16)++ = *((WORD *)p)++; /* italic */
82 lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p ); /* faceName */
83 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
84 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
87 /* Transfer dialog items */
90 /* align on DWORD boundary (32-bit only) */
91 p = (LPVOID)((((int)p) + 3) & ~3);
95 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* helpID */
96 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* exStyle */
97 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* style */
101 style = *((DWORD *)p)++; /* save style */
102 ((DWORD *)p)++; /* ignore exStyle */
105 *((WORD *)dialog16)++ = *((WORD *)p)++; /* x */
106 *((WORD *)dialog16)++ = *((WORD *)p)++; /* y */
107 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cx */
108 *((WORD *)dialog16)++ = *((WORD *)p)++; /* cy */
111 *((DWORD *)dialog16)++ = *((DWORD *)p)++; /* ID */
114 *((WORD *)dialog16)++ = *((WORD *)p)++; /* ID */
115 *((DWORD *)dialog16)++ = style; /* style from above */
118 /* Transfer class name */
119 switch (*((WORD *)p))
121 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
122 case 0xffff: ((WORD *)p)++;
123 *((BYTE *)dialog16)++ = (BYTE)*((WORD *)p)++; break;
124 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
125 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
126 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
130 /* Transfer window name */
131 switch (*((WORD *)p))
133 case 0x0000: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0; break;
134 case 0xffff: ((WORD *)p)++; *((BYTE *)dialog16)++ = 0xff;
135 *((WORD *)dialog16)++ = *((WORD *)p)++; break;
136 default: lstrcpyWtoA( (LPSTR)dialog16, (LPWSTR)p );
137 ((LPSTR)dialog16) += strlen( (LPSTR)dialog16 ) + 1;
138 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
143 data = *((WORD *)p)++;
145 *((WORD *)dialog16)++ = data;
147 *((BYTE *)dialog16)++ = (BYTE)data;
151 memcpy( dialog16, p, data );
152 (LPSTR)dialog16 += data;
161 /**********************************************************************
162 * GetDialog32Size (KERNEL.618)
164 WORD WINAPI GetDialog32Size16( LPVOID dialog32 )
167 WORD nbItems, data, dialogEx;
170 style = *((DWORD *)p)++;
171 dialogEx = (style == 0xffff0001); /* DIALOGEX resource */
174 ((DWORD *)p)++; /* helpID */
175 ((DWORD *)p)++; /* exStyle */
176 style = *((DWORD *)p)++; /* style */
179 ((DWORD *)p)++; /* exStyle */
181 nbItems = *((WORD *)p)++;
182 ((WORD *)p)++; /* x */
183 ((WORD *)p)++; /* y */
184 ((WORD *)p)++; /* cx */
185 ((WORD *)p)++; /* cy */
188 switch (*((WORD *)p))
190 case 0x0000: ((WORD *)p)++; break;
191 case 0xffff: ((WORD *)p) += 2; break;
192 default: ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1; break;
195 /* Skip class name */
196 switch (*((WORD *)p))
198 case 0x0000: ((WORD *)p)++; break;
199 case 0xffff: ((WORD *)p) += 2; break;
200 default: ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1; break;
203 /* Skip window caption */
204 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
207 if (style & DS_SETFONT)
209 ((WORD *)p)++; /* pointSize */
212 ((WORD *)p)++; /* weight */
213 ((WORD *)p)++; /* italic */
215 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1; /* faceName */
218 /* Skip dialog items */
221 /* align on DWORD boundary */
222 p = (LPVOID)((((int)p) + 3) & ~3);
226 ((DWORD *)p)++; /* helpID */
227 ((DWORD *)p)++; /* exStyle */
228 ((DWORD *)p)++; /* style */
232 ((DWORD *)p)++; /* style */
233 ((DWORD *)p)++; /* exStyle */
236 ((WORD *)p)++; /* x */
237 ((WORD *)p)++; /* y */
238 ((WORD *)p)++; /* cx */
239 ((WORD *)p)++; /* cy */
242 ((DWORD *)p)++; /* ID */
244 ((WORD *)p)++; /* ID */
246 /* Skip class name */
247 switch (*((WORD *)p))
249 case 0x0000: ((WORD *)p)++; break;
250 case 0xffff: ((WORD *)p) += 2; break;
251 default: ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1; break;
254 /* Skip window name */
255 switch (*((WORD *)p))
257 case 0x0000: ((WORD *)p)++; break;
258 case 0xffff: ((WORD *)p) += 2; break;
259 default: ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1; break;
263 data = *((WORD *)p)++;
270 return (WORD)((LPSTR)p - (LPSTR)dialog32);
273 /**********************************************************************
274 * ConvertMenu32To16 (KERNEL.616)
276 VOID WINAPI ConvertMenu32To16( LPVOID menu32, DWORD size, LPVOID menu16 )
279 WORD version, headersize, flags, level = 1;
281 version = *((WORD *)menu16)++ = *((WORD *)p)++;
282 headersize = *((WORD *)menu16)++ = *((WORD *)p)++;
285 memcpy( menu16, p, headersize );
286 ((LPSTR)menu16) += headersize;
287 ((LPSTR)p) += headersize;
291 if ( version == 0 ) /* standard */
293 flags = *((WORD *)menu16)++ = *((WORD *)p)++;
294 if ( !(flags & MF_POPUP) )
295 *((WORD *)menu16)++ = *((WORD *)p)++; /* ID */
299 lstrcpyWtoA( (LPSTR)menu16, (LPWSTR)p );
300 ((LPSTR)menu16) += strlen( (LPSTR)menu16 ) + 1;
301 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
303 if ( flags & MF_END )
308 *((DWORD *)menu16)++ = *((DWORD *)p)++; /* fType */
309 *((DWORD *)menu16)++ = *((DWORD *)p)++; /* fState */
310 *((WORD *)menu16)++ = (WORD)*((DWORD *)p)++; /* ID */
311 flags = *((BYTE *)menu16)++ = (BYTE)*((WORD *)p)++;
313 lstrcpyWtoA( (LPSTR)menu16, (LPWSTR)p );
314 ((LPSTR)menu16) += strlen( (LPSTR)menu16 ) + 1;
315 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
317 /* align on DWORD boundary (32-bit only) */
318 p = (LPVOID)((((int)p) + 3) & ~3);
320 /* If popup, transfer helpid */
323 *((DWORD *)menu16)++ = *((DWORD *)p)++;
327 if ( flags & MF_END )
332 /**********************************************************************
333 * GetMenu32Size (KERNEL.617)
335 WORD WINAPI GetMenu32Size16( LPVOID menu32 )
338 WORD version, headersize, flags, level = 1;
340 version = *((WORD *)p)++;
341 headersize = *((WORD *)p)++;
342 ((LPSTR)p) += headersize;
345 if ( version == 0 ) /* standard */
347 flags = *((WORD *)p)++;
348 if ( !(flags & MF_POPUP) )
349 ((WORD *)p)++; /* ID */
353 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
355 if ( flags & MF_END )
360 ((DWORD *)p)++; /* fType */
361 ((DWORD *)p)++; /* fState */
362 ((DWORD *)p)++; /* ID */
363 flags = *((WORD *)p)++;
365 ((LPWSTR)p) += strlenW( (LPWSTR)p ) + 1;
367 /* align on DWORD boundary (32-bit only) */
368 p = (LPVOID)((((int)p) + 3) & ~3);
370 /* If popup, skip helpid */
377 if ( flags & MF_END )
381 return (WORD)((LPSTR)p - (LPSTR)menu32);
384 /**********************************************************************
385 * ConvertAccelerator32To16
387 VOID ConvertAccelerator32To16( LPVOID acc32, DWORD size, LPVOID acc16 )
394 type = *((BYTE *)acc16)++ = *((BYTE *)acc32)++;
397 /* Copy event and IDval */
398 *((WORD *)acc16)++ = *((WORD *)acc32)++;
399 *((WORD *)acc16)++ = *((WORD *)acc32)++;
403 } while ( !( type & 0x80 ) );
406 /**********************************************************************
409 HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size )
413 TRACE("module=%04x type=%04x\n", pModule->self, type );
414 if (!pModule || !bits || !size) return 0;
416 handle = GlobalAlloc16( 0, size );
421 ConvertMenu32To16( bits, size, GlobalLock16( handle ) );
425 ConvertDialog32To16( bits, size, GlobalLock16( handle ) );
428 case RT_ACCELERATOR16:
429 ConvertAccelerator32To16( bits, size, GlobalLock16( handle ) );
433 FIXME("not yet implemented!\n" );
437 memcpy( GlobalLock16( handle ), bits, size );