2 * PE->NE resource conversion functions
4 * Copyright 1998 Ulrich Weigand
8 #include "wine/winuser16.h"
10 #include "debugtools.h"
12 DEFAULT_DEBUG_CHANNEL(resource
)
14 /**********************************************************************
15 * ConvertDialog32To16 (KERNEL.615)
17 VOID WINAPI
ConvertDialog32To16( LPVOID dialog32
, DWORD size
, LPVOID dialog16
)
20 WORD nbItems
, data
, dialogEx
;
23 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++;
24 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
27 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
28 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
29 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
32 ((DWORD
*)p
)++; /* exStyle ignored in 16-bit standard dialog */
34 nbItems
= *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++;
35 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
36 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
37 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
38 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
40 /* Transfer menu name */
43 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
44 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
45 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
46 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
47 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
48 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
52 /* Transfer class name */
55 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
56 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
57 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
58 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
59 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
60 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
64 /* Transfer window caption */
65 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
66 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
67 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
69 /* Transfer font info */
70 if (style
& DS_SETFONT
)
72 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* pointSize */
75 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* weight */
76 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* italic */
78 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
); /* faceName */
79 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
80 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
83 /* Transfer dialog items */
86 /* align on DWORD boundary (32-bit only) */
87 p
= (LPVOID
)((((int)p
) + 3) & ~3);
91 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
92 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
93 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
97 style
= *((DWORD
*)p
)++; /* save style */
98 ((DWORD
*)p
)++; /* ignore exStyle */
101 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
102 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
103 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
104 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
107 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* ID */
110 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* ID */
111 *((DWORD
*)dialog16
)++ = style
; /* style from above */
114 /* Transfer class name */
115 switch (*((WORD
*)p
))
117 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
118 case 0xffff: ((WORD
*)p
)++;
119 *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++; break;
120 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
121 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
122 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
126 /* Transfer window name */
127 switch (*((WORD
*)p
))
129 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
130 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
131 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
132 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
133 ((LPSTR
)dialog16
) += lstrlenA( (LPSTR
)dialog16
) + 1;
134 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
139 data
= *((WORD
*)p
)++;
141 *((WORD
*)dialog16
)++ = data
;
143 *((BYTE
*)dialog16
)++ = (BYTE
)data
;
147 memcpy( dialog16
, p
, data
);
148 (LPSTR
)dialog16
+= data
;
157 /**********************************************************************
158 * GetDialog32Size (KERNEL.618)
160 WORD WINAPI
GetDialog32Size16( LPVOID dialog32
)
163 WORD nbItems
, data
, dialogEx
;
166 style
= *((DWORD
*)p
)++;
167 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
170 ((DWORD
*)p
)++; /* helpID */
171 ((DWORD
*)p
)++; /* exStyle */
172 style
= *((DWORD
*)p
)++; /* style */
175 ((DWORD
*)p
)++; /* exStyle */
177 nbItems
= *((WORD
*)p
)++;
178 ((WORD
*)p
)++; /* x */
179 ((WORD
*)p
)++; /* y */
180 ((WORD
*)p
)++; /* cx */
181 ((WORD
*)p
)++; /* cy */
184 switch (*((WORD
*)p
))
186 case 0x0000: ((WORD
*)p
)++; break;
187 case 0xffff: ((WORD
*)p
) += 2; break;
188 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
191 /* Skip class name */
192 switch (*((WORD
*)p
))
194 case 0x0000: ((WORD
*)p
)++; break;
195 case 0xffff: ((WORD
*)p
) += 2; break;
196 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
199 /* Skip window caption */
200 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
203 if (style
& DS_SETFONT
)
205 ((WORD
*)p
)++; /* pointSize */
208 ((WORD
*)p
)++; /* weight */
209 ((WORD
*)p
)++; /* italic */
211 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; /* faceName */
214 /* Skip dialog items */
217 /* align on DWORD boundary */
218 p
= (LPVOID
)((((int)p
) + 3) & ~3);
222 ((DWORD
*)p
)++; /* helpID */
223 ((DWORD
*)p
)++; /* exStyle */
224 ((DWORD
*)p
)++; /* style */
228 ((DWORD
*)p
)++; /* style */
229 ((DWORD
*)p
)++; /* exStyle */
232 ((WORD
*)p
)++; /* x */
233 ((WORD
*)p
)++; /* y */
234 ((WORD
*)p
)++; /* cx */
235 ((WORD
*)p
)++; /* cy */
238 ((DWORD
*)p
)++; /* ID */
240 ((WORD
*)p
)++; /* ID */
242 /* Skip class name */
243 switch (*((WORD
*)p
))
245 case 0x0000: ((WORD
*)p
)++; break;
246 case 0xffff: ((WORD
*)p
) += 2; break;
247 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
250 /* Skip window name */
251 switch (*((WORD
*)p
))
253 case 0x0000: ((WORD
*)p
)++; break;
254 case 0xffff: ((WORD
*)p
) += 2; break;
255 default: ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1; break;
259 data
= *((WORD
*)p
)++;
266 return (WORD
)((LPSTR
)p
- (LPSTR
)dialog32
);
269 /**********************************************************************
270 * ConvertMenu32To16 (KERNEL.616)
272 VOID WINAPI
ConvertMenu32To16( LPVOID menu32
, DWORD size
, LPVOID menu16
)
275 WORD version
, headersize
, flags
, level
= 1;
277 version
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
278 headersize
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
281 memcpy( menu16
, p
, headersize
);
282 ((LPSTR
)menu16
) += headersize
;
283 ((LPSTR
)p
) += headersize
;
287 if ( version
== 0 ) /* standard */
289 flags
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
290 if ( !(flags
& MF_POPUP
) )
291 *((WORD
*)menu16
)++ = *((WORD
*)p
)++; /* ID */
295 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
296 ((LPSTR
)menu16
) += lstrlenA( (LPSTR
)menu16
) + 1;
297 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
299 if ( flags
& MF_END
)
304 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fType */
305 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fState */
306 *((WORD
*)menu16
)++ = (WORD
)*((DWORD
*)p
)++; /* ID */
307 flags
= *((BYTE
*)menu16
)++ = (BYTE
)*((WORD
*)p
)++;
309 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
310 ((LPSTR
)menu16
) += lstrlenA( (LPSTR
)menu16
) + 1;
311 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
313 /* align on DWORD boundary (32-bit only) */
314 p
= (LPVOID
)((((int)p
) + 3) & ~3);
316 /* If popup, transfer helpid */
319 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++;
323 if ( flags
& MF_END
)
328 /**********************************************************************
329 * GetMenu32Size (KERNEL.617)
331 WORD WINAPI
GetMenu32Size16( LPVOID menu32
)
334 WORD version
, headersize
, flags
, level
= 1;
336 version
= *((WORD
*)p
)++;
337 headersize
= *((WORD
*)p
)++;
338 ((LPSTR
)p
) += headersize
;
341 if ( version
== 0 ) /* standard */
343 flags
= *((WORD
*)p
)++;
344 if ( !(flags
& MF_POPUP
) )
345 ((WORD
*)p
)++; /* ID */
349 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
351 if ( flags
& MF_END
)
356 ((DWORD
*)p
)++; /* fType */
357 ((DWORD
*)p
)++; /* fState */
358 ((DWORD
*)p
)++; /* ID */
359 flags
= *((WORD
*)p
)++;
361 ((LPWSTR
)p
) += lstrlenW( (LPWSTR
)p
) + 1;
363 /* align on DWORD boundary (32-bit only) */
364 p
= (LPVOID
)((((int)p
) + 3) & ~3);
366 /* If popup, skip helpid */
373 if ( flags
& MF_END
)
377 return (WORD
)((LPSTR
)p
- (LPSTR
)menu32
);
380 /**********************************************************************
381 * ConvertAccelerator32To16
383 VOID
ConvertAccelerator32To16( LPVOID acc32
, DWORD size
, LPVOID acc16
)
390 type
= *((BYTE
*)acc16
)++ = *((BYTE
*)acc32
)++;
393 /* Copy event and IDval */
394 *((WORD
*)acc16
)++ = *((WORD
*)acc32
)++;
395 *((WORD
*)acc16
)++ = *((WORD
*)acc32
)++;
399 } while ( !( type
& 0x80 ) );
402 /**********************************************************************
405 HGLOBAL16
NE_LoadPEResource( NE_MODULE
*pModule
, WORD type
, LPVOID bits
, DWORD size
)
409 TRACE("module=%04x type=%04x\n", pModule
->self
, type
);
410 if (!pModule
|| !bits
|| !size
) return 0;
412 handle
= GlobalAlloc16( 0, size
);
417 ConvertMenu32To16( bits
, size
, GlobalLock16( handle
) );
421 ConvertDialog32To16( bits
, size
, GlobalLock16( handle
) );
424 case RT_ACCELERATOR16
:
425 ConvertAccelerator32To16( bits
, size
, GlobalLock16( handle
) );
429 FIXME("not yet implemented!\n" );
433 memcpy( GlobalLock16( handle
), bits
, size
);