2 * PE->NE resource conversion functions
4 * Copyright 1998 Ulrich Weigand
10 #include "wine/winuser16.h"
12 #include "debugtools.h"
14 DEFAULT_DEBUG_CHANNEL(resource
);
16 /**********************************************************************
17 * ConvertDialog32To16 (KERNEL.615)
19 VOID WINAPI
ConvertDialog32To16( LPVOID dialog32
, DWORD size
, LPVOID dialog16
)
22 WORD nbItems
, data
, dialogEx
;
25 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++;
26 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
29 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
30 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
31 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
34 ((DWORD
*)p
)++; /* exStyle ignored in 16-bit standard dialog */
36 nbItems
= *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++;
37 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
38 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
39 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
40 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
42 /* Transfer menu name */
45 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
46 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
47 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
48 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
49 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
50 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
54 /* Transfer class name */
57 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
58 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
59 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
60 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
61 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
62 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
66 /* Transfer window caption */
67 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
68 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
69 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
71 /* Transfer font info */
72 if (style
& DS_SETFONT
)
74 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* pointSize */
77 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* weight */
78 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* italic */
80 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
); /* faceName */
81 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
82 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
85 /* Transfer dialog items */
88 /* align on DWORD boundary (32-bit only) */
89 p
= (LPVOID
)((((int)p
) + 3) & ~3);
93 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
94 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
95 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
99 style
= *((DWORD
*)p
)++; /* save style */
100 ((DWORD
*)p
)++; /* ignore exStyle */
103 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
104 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
105 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
106 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
109 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* ID */
112 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* ID */
113 *((DWORD
*)dialog16
)++ = style
; /* style from above */
116 /* Transfer class name */
117 switch (*((WORD
*)p
))
119 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
120 case 0xffff: ((WORD
*)p
)++;
121 *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++; break;
122 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
123 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
124 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
128 /* Transfer window name */
129 switch (*((WORD
*)p
))
131 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
132 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
133 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
134 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
135 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
136 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
141 data
= *((WORD
*)p
)++;
143 *((WORD
*)dialog16
)++ = data
;
145 *((BYTE
*)dialog16
)++ = (BYTE
)data
;
149 memcpy( dialog16
, p
, data
);
150 (LPSTR
)dialog16
+= data
;
159 /**********************************************************************
160 * GetDialog32Size (KERNEL.618)
162 WORD WINAPI
GetDialog32Size16( LPVOID dialog32
)
165 WORD nbItems
, data
, dialogEx
;
168 style
= *((DWORD
*)p
)++;
169 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
172 ((DWORD
*)p
)++; /* helpID */
173 ((DWORD
*)p
)++; /* exStyle */
174 style
= *((DWORD
*)p
)++; /* style */
177 ((DWORD
*)p
)++; /* exStyle */
179 nbItems
= *((WORD
*)p
)++;
180 ((WORD
*)p
)++; /* x */
181 ((WORD
*)p
)++; /* y */
182 ((WORD
*)p
)++; /* cx */
183 ((WORD
*)p
)++; /* cy */
186 switch (*((WORD
*)p
))
188 case 0x0000: ((WORD
*)p
)++; break;
189 case 0xffff: ((WORD
*)p
) += 2; break;
190 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
193 /* Skip class name */
194 switch (*((WORD
*)p
))
196 case 0x0000: ((WORD
*)p
)++; break;
197 case 0xffff: ((WORD
*)p
) += 2; break;
198 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
201 /* Skip window caption */
202 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
205 if (style
& DS_SETFONT
)
207 ((WORD
*)p
)++; /* pointSize */
210 ((WORD
*)p
)++; /* weight */
211 ((WORD
*)p
)++; /* italic */
213 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; /* faceName */
216 /* Skip dialog items */
219 /* align on DWORD boundary */
220 p
= (LPVOID
)((((int)p
) + 3) & ~3);
224 ((DWORD
*)p
)++; /* helpID */
225 ((DWORD
*)p
)++; /* exStyle */
226 ((DWORD
*)p
)++; /* style */
230 ((DWORD
*)p
)++; /* style */
231 ((DWORD
*)p
)++; /* exStyle */
234 ((WORD
*)p
)++; /* x */
235 ((WORD
*)p
)++; /* y */
236 ((WORD
*)p
)++; /* cx */
237 ((WORD
*)p
)++; /* cy */
240 ((DWORD
*)p
)++; /* ID */
242 ((WORD
*)p
)++; /* ID */
244 /* Skip class name */
245 switch (*((WORD
*)p
))
247 case 0x0000: ((WORD
*)p
)++; break;
248 case 0xffff: ((WORD
*)p
) += 2; break;
249 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
252 /* Skip window name */
253 switch (*((WORD
*)p
))
255 case 0x0000: ((WORD
*)p
)++; break;
256 case 0xffff: ((WORD
*)p
) += 2; break;
257 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
261 data
= *((WORD
*)p
)++;
268 return (WORD
)((LPSTR
)p
- (LPSTR
)dialog32
);
271 /**********************************************************************
272 * ConvertMenu32To16 (KERNEL.616)
274 VOID WINAPI
ConvertMenu32To16( LPVOID menu32
, DWORD size
, LPVOID menu16
)
277 WORD version
, headersize
, flags
, level
= 1;
279 version
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
280 headersize
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
283 memcpy( menu16
, p
, headersize
);
284 ((LPSTR
)menu16
) += headersize
;
285 ((LPSTR
)p
) += headersize
;
289 if ( version
== 0 ) /* standard */
291 flags
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
292 if ( !(flags
& MF_POPUP
) )
293 *((WORD
*)menu16
)++ = *((WORD
*)p
)++; /* ID */
297 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
298 ((LPSTR
)menu16
) += lstrlenA( (LPSTR
)menu16
) + 1;
299 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
301 if ( flags
& MF_END
)
306 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fType */
307 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fState */
308 *((WORD
*)menu16
)++ = (WORD
)*((DWORD
*)p
)++; /* ID */
309 flags
= *((BYTE
*)menu16
)++ = (BYTE
)*((WORD
*)p
)++;
311 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
312 ((LPSTR
)menu16
) += lstrlenA( (LPSTR
)menu16
) + 1;
313 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
315 /* align on DWORD boundary (32-bit only) */
316 p
= (LPVOID
)((((int)p
) + 3) & ~3);
318 /* If popup, transfer helpid */
321 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++;
325 if ( flags
& MF_END
)
330 /**********************************************************************
331 * GetMenu32Size (KERNEL.617)
333 WORD WINAPI
GetMenu32Size16( LPVOID menu32
)
336 WORD version
, headersize
, flags
, level
= 1;
338 version
= *((WORD
*)p
)++;
339 headersize
= *((WORD
*)p
)++;
340 ((LPSTR
)p
) += headersize
;
343 if ( version
== 0 ) /* standard */
345 flags
= *((WORD
*)p
)++;
346 if ( !(flags
& MF_POPUP
) )
347 ((WORD
*)p
)++; /* ID */
351 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
353 if ( flags
& MF_END
)
358 ((DWORD
*)p
)++; /* fType */
359 ((DWORD
*)p
)++; /* fState */
360 ((DWORD
*)p
)++; /* ID */
361 flags
= *((WORD
*)p
)++;
363 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
365 /* align on DWORD boundary (32-bit only) */
366 p
= (LPVOID
)((((int)p
) + 3) & ~3);
368 /* If popup, skip helpid */
375 if ( flags
& MF_END
)
379 return (WORD
)((LPSTR
)p
- (LPSTR
)menu32
);
382 /**********************************************************************
383 * ConvertAccelerator32To16
385 VOID
ConvertAccelerator32To16( LPVOID acc32
, DWORD size
, LPVOID acc16
)
392 type
= *((BYTE
*)acc16
)++ = *((BYTE
*)acc32
)++;
395 /* Copy event and IDval */
396 *((WORD
*)acc16
)++ = *((WORD
*)acc32
)++;
397 *((WORD
*)acc16
)++ = *((WORD
*)acc32
)++;
401 } while ( !( type
& 0x80 ) );
404 /**********************************************************************
407 HGLOBAL16
NE_LoadPEResource( NE_MODULE
*pModule
, WORD type
, LPVOID bits
, DWORD size
)
411 TRACE("module=%04x type=%04x\n", pModule
->self
, type
);
412 if (!pModule
|| !bits
|| !size
) return 0;
414 handle
= GlobalAlloc16( 0, size
);
419 ConvertMenu32To16( bits
, size
, GlobalLock16( handle
) );
423 ConvertDialog32To16( bits
, size
, GlobalLock16( handle
) );
426 case RT_ACCELERATOR16
:
427 ConvertAccelerator32To16( bits
, size
, GlobalLock16( handle
) );
431 FIXME("not yet implemented!\n" );
435 memcpy( GlobalLock16( handle
), bits
, size
);