2 * PE->NE resource conversion functions
4 * Copyright 1998 Ulrich Weigand
9 #include "debugtools.h"
12 /**********************************************************************
13 * ConvertDialog32To16 (KERNEL.615)
15 VOID WINAPI
ConvertDialog32To16( LPVOID dialog32
, DWORD size
, LPVOID dialog16
)
18 WORD nbItems
, data
, dialogEx
;
21 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++;
22 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
25 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
26 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
27 style
= *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
30 ((DWORD
*)p
)++; /* exStyle ignored in 16-bit standard dialog */
32 nbItems
= *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++;
33 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
34 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
35 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
36 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
38 /* Transfer menu name */
41 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
42 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
43 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
44 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
45 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
46 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
50 /* Transfer class name */
53 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
54 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
55 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
56 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
57 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
58 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
62 /* Transfer window caption */
63 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
64 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
65 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
67 /* Transfer font info */
68 if (style
& DS_SETFONT
)
70 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* pointSize */
73 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* weight */
74 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* italic */
76 lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
); /* faceName */
77 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
78 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
81 /* Transfer dialog items */
84 /* align on DWORD boundary (32-bit only) */
85 p
= (LPVOID
)((((int)p
) + 3) & ~3);
89 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* helpID */
90 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* exStyle */
91 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* style */
95 style
= *((DWORD
*)p
)++; /* save style */
96 ((DWORD
*)p
)++; /* ignore exStyle */
99 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* x */
100 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* y */
101 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cx */
102 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* cy */
105 *((DWORD
*)dialog16
)++ = *((DWORD
*)p
)++; /* ID */
108 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; /* ID */
109 *((DWORD
*)dialog16
)++ = style
; /* style from above */
112 /* Transfer class name */
113 switch (*((WORD
*)p
))
115 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
116 case 0xffff: ((WORD
*)p
)++;
117 *((BYTE
*)dialog16
)++ = (BYTE
)*((WORD
*)p
)++; break;
118 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
119 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
120 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
124 /* Transfer window name */
125 switch (*((WORD
*)p
))
127 case 0x0000: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0; break;
128 case 0xffff: ((WORD
*)p
)++; *((BYTE
*)dialog16
)++ = 0xff;
129 *((WORD
*)dialog16
)++ = *((WORD
*)p
)++; break;
130 default: lstrcpyWtoA( (LPSTR
)dialog16
, (LPWSTR
)p
);
131 ((LPSTR
)dialog16
) += lstrlen32A( (LPSTR
)dialog16
) + 1;
132 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
137 data
= *((WORD
*)p
)++;
139 *((WORD
*)dialog16
)++ = data
;
141 *((BYTE
*)dialog16
)++ = (BYTE
)data
;
145 memcpy( dialog16
, p
, data
);
146 (LPSTR
)dialog16
+= data
;
155 /**********************************************************************
156 * GetDialog32Size (KERNEL.618)
158 WORD WINAPI
GetDialog32Size( LPVOID dialog32
)
161 WORD nbItems
, data
, dialogEx
;
164 style
= *((DWORD
*)p
)++;
165 dialogEx
= (style
== 0xffff0001); /* DIALOGEX resource */
168 ((DWORD
*)p
)++; /* helpID */
169 ((DWORD
*)p
)++; /* exStyle */
170 style
= *((DWORD
*)p
)++; /* style */
173 ((DWORD
*)p
)++; /* exStyle */
175 nbItems
= *((WORD
*)p
)++;
176 ((WORD
*)p
)++; /* x */
177 ((WORD
*)p
)++; /* y */
178 ((WORD
*)p
)++; /* cx */
179 ((WORD
*)p
)++; /* cy */
182 switch (*((WORD
*)p
))
184 case 0x0000: ((WORD
*)p
)++; break;
185 case 0xffff: ((WORD
*)p
) += 2; break;
186 default: ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1; break;
189 /* Skip class name */
190 switch (*((WORD
*)p
))
192 case 0x0000: ((WORD
*)p
)++; break;
193 case 0xffff: ((WORD
*)p
) += 2; break;
194 default: ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1; break;
197 /* Skip window caption */
198 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
201 if (style
& DS_SETFONT
)
203 ((WORD
*)p
)++; /* pointSize */
206 ((WORD
*)p
)++; /* weight */
207 ((WORD
*)p
)++; /* italic */
209 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1; /* faceName */
212 /* Skip dialog items */
215 /* align on DWORD boundary */
216 p
= (LPVOID
)((((int)p
) + 3) & ~3);
220 ((DWORD
*)p
)++; /* helpID */
221 ((DWORD
*)p
)++; /* exStyle */
222 ((DWORD
*)p
)++; /* style */
226 ((DWORD
*)p
)++; /* style */
227 ((DWORD
*)p
)++; /* exStyle */
230 ((WORD
*)p
)++; /* x */
231 ((WORD
*)p
)++; /* y */
232 ((WORD
*)p
)++; /* cx */
233 ((WORD
*)p
)++; /* cy */
236 ((DWORD
*)p
)++; /* ID */
238 ((WORD
*)p
)++; /* ID */
240 /* Skip class name */
241 switch (*((WORD
*)p
))
243 case 0x0000: ((WORD
*)p
)++; break;
244 case 0xffff: ((WORD
*)p
) += 2; break;
245 default: ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1; break;
248 /* Skip window name */
249 switch (*((WORD
*)p
))
251 case 0x0000: ((WORD
*)p
)++; break;
252 case 0xffff: ((WORD
*)p
) += 2; break;
253 default: ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1; break;
257 data
= *((WORD
*)p
)++;
264 return (WORD
)((LPSTR
)p
- (LPSTR
)dialog32
);
267 /**********************************************************************
268 * ConvertMenu32To16 (KERNEL.616)
270 VOID WINAPI
ConvertMenu32To16( LPVOID menu32
, DWORD size
, LPVOID menu16
)
273 WORD version
, headersize
, flags
, level
= 1;
275 version
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
276 headersize
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
279 memcpy( menu16
, p
, headersize
);
280 ((LPSTR
)menu16
) += headersize
;
281 ((LPSTR
)p
) += headersize
;
285 if ( version
== 0 ) /* standard */
287 flags
= *((WORD
*)menu16
)++ = *((WORD
*)p
)++;
288 if ( !(flags
& MF_POPUP
) )
289 *((WORD
*)menu16
)++ = *((WORD
*)p
)++; /* ID */
293 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
294 ((LPSTR
)menu16
) += lstrlen32A( (LPSTR
)menu16
) + 1;
295 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
297 if ( flags
& MF_END
)
302 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fType */
303 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++; /* fState */
304 *((WORD
*)menu16
)++ = (WORD
)*((DWORD
*)p
)++; /* ID */
305 flags
= *((BYTE
*)menu16
)++ = (BYTE
)*((WORD
*)p
)++;
307 lstrcpyWtoA( (LPSTR
)menu16
, (LPWSTR
)p
);
308 ((LPSTR
)menu16
) += lstrlen32A( (LPSTR
)menu16
) + 1;
309 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
311 /* align on DWORD boundary (32-bit only) */
312 p
= (LPVOID
)((((int)p
) + 3) & ~3);
314 /* If popup, transfer helpid */
317 *((DWORD
*)menu16
)++ = *((DWORD
*)p
)++;
321 if ( flags
& MF_END
)
326 /**********************************************************************
327 * GetMenu32Size (KERNEL.617)
329 WORD WINAPI
GetMenu32Size( LPVOID menu32
)
332 WORD version
, headersize
, flags
, level
= 1;
334 version
= *((WORD
*)p
)++;
335 headersize
= *((WORD
*)p
)++;
336 ((LPSTR
)p
) += headersize
;
339 if ( version
== 0 ) /* standard */
341 flags
= *((WORD
*)p
)++;
342 if ( !(flags
& MF_POPUP
) )
343 ((WORD
*)p
)++; /* ID */
347 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
349 if ( flags
& MF_END
)
354 ((DWORD
*)p
)++; /* fType */
355 ((DWORD
*)p
)++; /* fState */
356 ((DWORD
*)p
)++; /* ID */
357 flags
= *((WORD
*)p
)++;
359 ((LPWSTR
)p
) += lstrlen32W( (LPWSTR
)p
) + 1;
361 /* align on DWORD boundary (32-bit only) */
362 p
= (LPVOID
)((((int)p
) + 3) & ~3);
364 /* If popup, skip helpid */
371 if ( flags
& MF_END
)
375 return (WORD
)((LPSTR
)p
- (LPSTR
)menu32
);
378 /**********************************************************************
381 HGLOBAL16
NE_LoadPEResource( NE_MODULE
*pModule
, WORD type
, LPVOID bits
, DWORD size
)
385 TRACE( resource
, "module=%04x type=%04x\n", pModule
->self
, type
);
386 if (!pModule
|| !bits
|| !size
) return 0;
388 handle
= GlobalAlloc16( 0, size
);
393 ConvertMenu32To16( bits
, size
, GlobalLock16( handle
) );
397 ConvertDialog32To16( bits
, size
, GlobalLock16( handle
) );
401 FIXME( resource
, "not yet implemented!\n" );
405 memcpy( GlobalLock16( handle
), bits
, size
);
412 /**********************************************************************
415 BOOL16
NE_FreePEResource( NE_MODULE
*pModule
, HGLOBAL16 handle
)
417 GlobalFree16( handle
);