Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * 16-bit resource functions |
| 3 | * |
| 4 | * Copyright 1993 Robert J. Amstadt |
| 5 | * Copyright 1997 Alex Korobka |
| 6 | * Copyright 1998 Ulrich Weigand |
| 7 | * Copyright 1995, 2003 Alexandre Julliard |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Lesser General Public |
| 11 | * License as published by the Free Software Foundation; either |
| 12 | * version 2.1 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public |
| 20 | * License along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | #include "wine/port.h" |
| 26 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 27 | #include <stdarg.h> |
Alexandre Julliard | 402b79a | 2003-11-27 00:59:36 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #include <sys/types.h> |
| 32 | |
| 33 | #include "windef.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 34 | #include "winbase.h" |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 35 | #include "wownt32.h" |
| 36 | #include "wine/winbase16.h" |
| 37 | #include "wine/winuser16.h" |
| 38 | #include "wine/unicode.h" |
| 39 | #include "module.h" |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 40 | #include "wine/debug.h" |
| 41 | |
| 42 | WINE_DEFAULT_DEBUG_CHANNEL(resource); |
| 43 | |
| 44 | /* handle conversions */ |
| 45 | #define HRSRC_32(h16) ((HRSRC)(ULONG_PTR)(h16)) |
| 46 | #define HGLOBAL_32(h16) ((HGLOBAL)(ULONG_PTR)(h16)) |
| 47 | |
| 48 | static inline NE_MODULE *get_module( HMODULE16 mod ) |
| 49 | { |
| 50 | if (!mod) mod = TASK_GetCurrent()->hModule; |
| 51 | return NE_GetPtr( mod ); |
| 52 | } |
| 53 | |
| 54 | #define HRSRC_MAP_BLOCKSIZE 16 |
| 55 | |
| 56 | typedef struct _HRSRC_ELEM |
| 57 | { |
| 58 | HRSRC hRsrc; |
| 59 | WORD type; |
| 60 | } HRSRC_ELEM; |
| 61 | |
| 62 | typedef struct _HRSRC_MAP |
| 63 | { |
| 64 | int nAlloc; |
| 65 | int nUsed; |
| 66 | HRSRC_ELEM *elem; |
| 67 | } HRSRC_MAP; |
| 68 | |
| 69 | |
| 70 | /********************************************************************** |
| 71 | * MapHRsrc32To16 |
| 72 | */ |
| 73 | static HRSRC16 MapHRsrc32To16( NE_MODULE *pModule, HRSRC hRsrc32, WORD type ) |
| 74 | { |
| 75 | HRSRC_MAP *map = (HRSRC_MAP *)pModule->hRsrcMap; |
| 76 | HRSRC_ELEM *newElem; |
| 77 | int i; |
| 78 | |
| 79 | /* On first call, initialize HRSRC map */ |
| 80 | if ( !map ) |
| 81 | { |
| 82 | if ( !(map = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HRSRC_MAP) ) ) ) |
| 83 | { |
| 84 | ERR("Cannot allocate HRSRC map\n" ); |
| 85 | return 0; |
| 86 | } |
| 87 | pModule->hRsrcMap = map; |
| 88 | } |
| 89 | |
| 90 | /* Check whether HRSRC32 already in map */ |
| 91 | for ( i = 0; i < map->nUsed; i++ ) |
| 92 | if ( map->elem[i].hRsrc == hRsrc32 ) |
| 93 | return (HRSRC16)(i + 1); |
| 94 | |
| 95 | /* If no space left, grow table */ |
| 96 | if ( map->nUsed == map->nAlloc ) |
| 97 | { |
Oleg Prokhorov | de12a97 | 2003-10-14 05:24:20 +0000 | [diff] [blame] | 98 | |
| 99 | if (map->elem) |
Jakob Eriksson | 9ed61de | 2005-03-24 21:01:35 +0000 | [diff] [blame^] | 100 | newElem = HeapReAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, |
Oleg Prokhorov | de12a97 | 2003-10-14 05:24:20 +0000 | [diff] [blame] | 101 | map->elem, (map->nAlloc + HRSRC_MAP_BLOCKSIZE) * sizeof(HRSRC_ELEM) ); |
| 102 | else |
Jakob Eriksson | 9ed61de | 2005-03-24 21:01:35 +0000 | [diff] [blame^] | 103 | newElem = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, |
Oleg Prokhorov | de12a97 | 2003-10-14 05:24:20 +0000 | [diff] [blame] | 104 | (map->nAlloc + HRSRC_MAP_BLOCKSIZE) * sizeof(HRSRC_ELEM) ); |
| 105 | |
| 106 | if ( !newElem ) |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 107 | { |
| 108 | ERR("Cannot grow HRSRC map\n" ); |
| 109 | return 0; |
| 110 | } |
| 111 | map->elem = newElem; |
| 112 | map->nAlloc += HRSRC_MAP_BLOCKSIZE; |
| 113 | } |
| 114 | |
| 115 | /* Add HRSRC32 to table */ |
| 116 | map->elem[map->nUsed].hRsrc = hRsrc32; |
| 117 | map->elem[map->nUsed].type = type; |
| 118 | map->nUsed++; |
| 119 | |
| 120 | return (HRSRC16)map->nUsed; |
| 121 | } |
| 122 | |
| 123 | /********************************************************************** |
| 124 | * MapHRsrc16To32 |
| 125 | */ |
| 126 | static HRSRC MapHRsrc16To32( NE_MODULE *pModule, HRSRC16 hRsrc16 ) |
| 127 | { |
| 128 | HRSRC_MAP *map = (HRSRC_MAP *)pModule->hRsrcMap; |
| 129 | if ( !map || !hRsrc16 || hRsrc16 > map->nUsed ) return 0; |
| 130 | |
| 131 | return map->elem[hRsrc16-1].hRsrc; |
| 132 | } |
| 133 | |
| 134 | /********************************************************************** |
| 135 | * MapHRsrc16ToType |
| 136 | */ |
| 137 | static WORD MapHRsrc16ToType( NE_MODULE *pModule, HRSRC16 hRsrc16 ) |
| 138 | { |
| 139 | HRSRC_MAP *map = (HRSRC_MAP *)pModule->hRsrcMap; |
| 140 | if ( !map || !hRsrc16 || hRsrc16 > map->nUsed ) return 0; |
| 141 | |
| 142 | return map->elem[hRsrc16-1].type; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | /********************************************************************** |
| 147 | * get_res_name |
| 148 | * |
| 149 | * Convert a resource name from '#xxx' form to numerical id. |
| 150 | */ |
| 151 | static inline LPCSTR get_res_name( LPCSTR name ) |
| 152 | { |
| 153 | if (HIWORD(name) && name[0] == '#') name = (LPCSTR)atoi( name + 1 ); |
| 154 | return name; |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /********************************************************************** |
| 159 | * next_typeinfo |
| 160 | */ |
| 161 | static inline NE_TYPEINFO *next_typeinfo( NE_TYPEINFO *info ) |
| 162 | { |
| 163 | return (NE_TYPEINFO *)((char*)(info + 1) + info->count * sizeof(NE_NAMEINFO)); |
| 164 | } |
| 165 | |
| 166 | |
| 167 | /********************************************************************** |
| 168 | * get_default_res_handler |
| 169 | */ |
| 170 | static inline FARPROC16 get_default_res_handler(void) |
| 171 | { |
| 172 | static FARPROC16 handler; |
| 173 | |
| 174 | if (!handler) handler = GetProcAddress16( GetModuleHandle16("KERNEL"), "DefResourceHandler" ); |
| 175 | return handler; |
| 176 | } |
| 177 | |
| 178 | |
| 179 | /*********************************************************************** |
| 180 | * NE_FindNameTableId |
| 181 | * |
| 182 | * Find the type and resource id from their names. |
| 183 | * Return value is MAKELONG( typeId, resId ), or 0 if not found. |
| 184 | */ |
| 185 | static DWORD NE_FindNameTableId( NE_MODULE *pModule, LPCSTR typeId, LPCSTR resId ) |
| 186 | { |
| 187 | NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2); |
| 188 | NE_NAMEINFO *pNameInfo; |
| 189 | HGLOBAL16 handle; |
| 190 | WORD *p; |
| 191 | DWORD ret = 0; |
| 192 | int count; |
| 193 | |
| 194 | for (; pTypeInfo->type_id != 0; |
| 195 | pTypeInfo = (NE_TYPEINFO *)((char*)(pTypeInfo+1) + |
| 196 | pTypeInfo->count * sizeof(NE_NAMEINFO))) |
| 197 | { |
| 198 | if (pTypeInfo->type_id != 0x800f) continue; |
| 199 | pNameInfo = (NE_NAMEINFO *)(pTypeInfo + 1); |
| 200 | for (count = pTypeInfo->count; count > 0; count--, pNameInfo++) |
| 201 | { |
| 202 | TRACE("NameTable entry: type=%04x id=%04x\n", |
| 203 | pTypeInfo->type_id, pNameInfo->id ); |
| 204 | handle = LoadResource16( pModule->self, |
| 205 | (HRSRC16)((int)pNameInfo - (int)pModule) ); |
| 206 | for(p = (WORD*)LockResource16(handle); p && *p; p = (WORD *)((char*)p+*p)) |
| 207 | { |
| 208 | TRACE(" type=%04x '%s' id=%04x '%s'\n", |
| 209 | p[1], (char *)(p+3), p[2], |
| 210 | (char *)(p+3)+strlen((char *)(p+3))+1 ); |
| 211 | /* Check for correct type */ |
| 212 | |
| 213 | if (p[1] & 0x8000) |
| 214 | { |
| 215 | if (!HIWORD(typeId)) continue; |
| 216 | if (strcasecmp( typeId, (char *)(p + 3) )) continue; |
| 217 | } |
| 218 | else if (HIWORD(typeId) || (((DWORD)typeId & ~0x8000)!= p[1])) |
| 219 | continue; |
| 220 | |
| 221 | /* Now check for the id */ |
| 222 | |
| 223 | if (p[2] & 0x8000) |
| 224 | { |
| 225 | if (!HIWORD(resId)) continue; |
| 226 | if (strcasecmp( resId, (char*)(p+3)+strlen((char*)(p+3))+1 )) continue; |
| 227 | |
| 228 | } |
| 229 | else if (HIWORD(resId) || (((DWORD)resId & ~0x8000) != p[2])) |
| 230 | continue; |
| 231 | |
| 232 | /* If we get here, we've found the entry */ |
| 233 | |
| 234 | TRACE(" Found!\n" ); |
| 235 | ret = MAKELONG( p[1], p[2] ); |
| 236 | break; |
| 237 | } |
| 238 | FreeResource16( handle ); |
| 239 | if (ret) return ret; |
| 240 | } |
| 241 | } |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /*********************************************************************** |
| 247 | * NE_FindTypeSection |
| 248 | * |
| 249 | * Find header struct for a particular resource type. |
| 250 | */ |
| 251 | static NE_TYPEINFO *NE_FindTypeSection( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR typeId ) |
| 252 | { |
| 253 | /* start from pTypeInfo */ |
| 254 | |
| 255 | if (HIWORD(typeId) != 0) /* Named type */ |
| 256 | { |
| 257 | LPCSTR str = typeId; |
| 258 | BYTE len = strlen( str ); |
| 259 | while (pTypeInfo->type_id) |
| 260 | { |
| 261 | if (!(pTypeInfo->type_id & 0x8000)) |
| 262 | { |
| 263 | BYTE *p = pResTab + pTypeInfo->type_id; |
| 264 | if ((*p == len) && !strncasecmp( p+1, str, len )) |
| 265 | { |
| 266 | TRACE(" Found type '%s'\n", str ); |
| 267 | return pTypeInfo; |
| 268 | } |
| 269 | } |
| 270 | TRACE(" Skipping type %04x\n", pTypeInfo->type_id ); |
| 271 | pTypeInfo = next_typeinfo(pTypeInfo); |
| 272 | } |
| 273 | } |
| 274 | else /* Numeric type id */ |
| 275 | { |
| 276 | WORD id = LOWORD(typeId) | 0x8000; |
| 277 | while (pTypeInfo->type_id) |
| 278 | { |
| 279 | if (pTypeInfo->type_id == id) |
| 280 | { |
| 281 | TRACE(" Found type %04x\n", id ); |
| 282 | return pTypeInfo; |
| 283 | } |
| 284 | TRACE(" Skipping type %04x\n", pTypeInfo->type_id ); |
| 285 | pTypeInfo = next_typeinfo(pTypeInfo); |
| 286 | } |
| 287 | } |
| 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /*********************************************************************** |
| 293 | * NE_FindResourceFromType |
| 294 | * |
| 295 | * Find a resource once the type info structure has been found. |
| 296 | */ |
| 297 | static NE_NAMEINFO *NE_FindResourceFromType( LPBYTE pResTab, NE_TYPEINFO *pTypeInfo, LPCSTR resId ) |
| 298 | { |
| 299 | BYTE *p; |
| 300 | int count; |
| 301 | NE_NAMEINFO *pNameInfo = (NE_NAMEINFO *)(pTypeInfo + 1); |
| 302 | |
| 303 | if (HIWORD(resId) != 0) /* Named resource */ |
| 304 | { |
| 305 | LPCSTR str = resId; |
| 306 | BYTE len = strlen( str ); |
| 307 | for (count = pTypeInfo->count; count > 0; count--, pNameInfo++) |
| 308 | { |
| 309 | if (pNameInfo->id & 0x8000) continue; |
| 310 | p = pResTab + pNameInfo->id; |
| 311 | if ((*p == len) && !strncasecmp( p+1, str, len )) |
| 312 | return pNameInfo; |
| 313 | } |
| 314 | } |
| 315 | else /* Numeric resource id */ |
| 316 | { |
| 317 | WORD id = LOWORD(resId) | 0x8000; |
| 318 | for (count = pTypeInfo->count; count > 0; count--, pNameInfo++) |
| 319 | if (pNameInfo->id == id) return pNameInfo; |
| 320 | } |
| 321 | return NULL; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | /*********************************************************************** |
| 326 | * DefResourceHandler (KERNEL.456) |
| 327 | * |
| 328 | * This is the default LoadProc() function. |
| 329 | */ |
| 330 | HGLOBAL16 WINAPI NE_DefResourceHandler( HGLOBAL16 hMemObj, HMODULE16 hModule, |
| 331 | HRSRC16 hRsrc ) |
| 332 | { |
| 333 | HANDLE fd; |
| 334 | NE_MODULE* pModule = NE_GetPtr( hModule ); |
| 335 | if (pModule && (pModule->flags & NE_FFLAGS_BUILTIN)) |
| 336 | { |
| 337 | HGLOBAL16 handle; |
| 338 | WORD sizeShift = *(WORD *)((char *)pModule + pModule->res_table); |
| 339 | NE_NAMEINFO* pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc); |
| 340 | |
| 341 | if ( hMemObj ) |
| 342 | handle = GlobalReAlloc16( hMemObj, pNameInfo->length << sizeShift, 0 ); |
| 343 | else |
| 344 | handle = AllocResource16( hModule, hRsrc, 0 ); |
| 345 | |
| 346 | if ( handle ) |
| 347 | { |
| 348 | /* NOTE: hRsrcMap points to start of built-in resource data */ |
| 349 | memcpy( GlobalLock16( handle ), |
| 350 | (char *)pModule->hRsrcMap + (pNameInfo->offset << sizeShift), |
| 351 | pNameInfo->length << sizeShift ); |
| 352 | } |
| 353 | return handle; |
| 354 | } |
| 355 | if (pModule && (fd = NE_OpenFile( pModule )) != INVALID_HANDLE_VALUE) |
| 356 | { |
| 357 | HGLOBAL16 handle; |
| 358 | WORD sizeShift = *(WORD *)((char *)pModule + pModule->res_table); |
| 359 | NE_NAMEINFO* pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc); |
| 360 | |
| 361 | TRACE("loading, pos=%d, len=%d\n", |
| 362 | (int)pNameInfo->offset << sizeShift, |
| 363 | (int)pNameInfo->length << sizeShift ); |
| 364 | if( hMemObj ) |
| 365 | handle = GlobalReAlloc16( hMemObj, pNameInfo->length << sizeShift, 0 ); |
| 366 | else |
| 367 | handle = AllocResource16( hModule, hRsrc, 0 ); |
| 368 | |
| 369 | if( handle ) |
| 370 | { |
| 371 | DWORD res; |
| 372 | SetFilePointer( fd, (int)pNameInfo->offset << sizeShift, NULL, SEEK_SET ); |
| 373 | ReadFile( fd, GlobalLock16( handle ), (int)pNameInfo->length << sizeShift, |
| 374 | &res, NULL ); |
| 375 | } |
| 376 | CloseHandle(fd); |
| 377 | return handle; |
| 378 | } |
| 379 | return (HGLOBAL16)0; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /********************************************************************** |
| 384 | * SetResourceHandler (KERNEL.67) |
| 385 | */ |
| 386 | FARPROC16 WINAPI SetResourceHandler16( HMODULE16 hModule, LPCSTR typeId, FARPROC16 resourceHandler ) |
| 387 | { |
| 388 | LPBYTE pResTab; |
| 389 | NE_TYPEINFO *pTypeInfo; |
| 390 | FARPROC16 prevHandler = NULL; |
| 391 | NE_MODULE *pModule = NE_GetPtr( hModule ); |
| 392 | |
| 393 | if (!pModule || !pModule->res_table) return NULL; |
| 394 | |
| 395 | pResTab = (LPBYTE)pModule + pModule->res_table; |
| 396 | pTypeInfo = (NE_TYPEINFO *)(pResTab + 2); |
| 397 | |
| 398 | TRACE("module=%04x type=%s\n", hModule, debugstr_a(typeId) ); |
| 399 | |
| 400 | for (;;) |
| 401 | { |
| 402 | if (!(pTypeInfo = NE_FindTypeSection( pResTab, pTypeInfo, typeId ))) |
| 403 | break; |
| 404 | memcpy_unaligned( &prevHandler, &pTypeInfo->resloader, sizeof(FARPROC16) ); |
| 405 | memcpy_unaligned( &pTypeInfo->resloader, &resourceHandler, sizeof(FARPROC16) ); |
| 406 | pTypeInfo = next_typeinfo(pTypeInfo); |
| 407 | } |
| 408 | if (!prevHandler) prevHandler = get_default_res_handler(); |
| 409 | return prevHandler; |
| 410 | } |
| 411 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 412 | static inline DWORD get_dword(LPVOID *p) |
| 413 | { |
| 414 | DWORD ret = *(DWORD*)*p; |
| 415 | *p = (DWORD *)*p + 1; |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | static inline void put_dword(LPVOID *p, DWORD d) |
| 420 | { |
| 421 | *(DWORD*)*p = d; |
| 422 | *p = (DWORD *)*p + 1; |
| 423 | } |
| 424 | |
| 425 | static inline WORD get_word(LPVOID *p) |
| 426 | { |
| 427 | WORD ret = *(WORD*)*p; |
| 428 | *p = (WORD *)*p + 1; |
| 429 | return ret; |
| 430 | } |
| 431 | |
| 432 | static inline void put_word(LPVOID *p, WORD w) |
| 433 | { |
| 434 | *(WORD*)*p = w; |
| 435 | *p = (WORD *)*p + 1; |
| 436 | } |
| 437 | |
| 438 | static inline BYTE get_byte(LPVOID *p) |
| 439 | { |
| 440 | BYTE ret = *(BYTE *)*p; |
| 441 | *p = (BYTE *)*p + 1; |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | static inline void put_byte(LPVOID *p, BYTE b) |
| 446 | { |
| 447 | *(BYTE *)*p = b; |
| 448 | *p = (BYTE *)*p + 1; |
| 449 | } |
| 450 | |
| 451 | /* convert a resource name */ |
| 452 | static void convert_name( LPVOID *dst, LPVOID *src ) |
| 453 | { |
| 454 | int len; |
| 455 | switch (*((WORD *)*src)) |
| 456 | { |
| 457 | case 0x0000: |
| 458 | get_word( src ); |
| 459 | put_byte( dst, 0 ); |
| 460 | break; |
| 461 | case 0xffff: |
| 462 | get_word( src ); |
| 463 | put_byte( dst, 0xff ); |
| 464 | put_word( dst, get_word(src) ); |
| 465 | break; |
| 466 | default: |
| 467 | len = WideCharToMultiByte( CP_ACP, 0, *src, -1, *dst, 0x7fffffff, NULL,NULL ); |
| 468 | *dst = (char *)*dst + len; |
| 469 | *src = (WCHAR *)*src + strlenW( (WCHAR *)*src ) + 1; |
| 470 | break; |
| 471 | } |
| 472 | } |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 473 | |
| 474 | /********************************************************************** |
| 475 | * ConvertDialog32To16 (KERNEL.615) |
| 476 | */ |
| 477 | VOID WINAPI ConvertDialog32To16( LPVOID dialog32, DWORD size, LPVOID dialog16 ) |
| 478 | { |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 479 | WORD nbItems, data, dialogEx; |
| 480 | DWORD style; |
| 481 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 482 | style = get_dword( &dialog32 ); |
| 483 | put_dword( &dialog16, style ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 484 | dialogEx = (style == 0xffff0001); /* DIALOGEX resource */ |
| 485 | if (dialogEx) |
| 486 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 487 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* helpID */ |
| 488 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* exStyle */ |
| 489 | style = get_dword( &dialog32 ); |
| 490 | put_dword( &dialog16, style ); /* style */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 491 | } |
| 492 | else |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 493 | dialog32 = (DWORD *)dialog32 + 1; /* exStyle ignored in 16-bit standard dialog */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 494 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 495 | nbItems = get_word( &dialog32 ); |
| 496 | put_byte( &dialog16, nbItems ); |
| 497 | put_word( &dialog16, get_word( &dialog32 ) ); /* x */ |
| 498 | put_word( &dialog16, get_word( &dialog32 ) ); /* y */ |
| 499 | put_word( &dialog16, get_word( &dialog32 ) ); /* cx */ |
| 500 | put_word( &dialog16, get_word( &dialog32 ) ); /* cy */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 501 | |
| 502 | /* Transfer menu name */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 503 | convert_name( &dialog16, &dialog32 ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 504 | |
| 505 | /* Transfer class name */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 506 | convert_name( &dialog16, &dialog32 ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 507 | |
| 508 | /* Transfer window caption */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 509 | WideCharToMultiByte( CP_ACP, 0, dialog32, -1, dialog16, 0x7fffffff, NULL, NULL ); |
| 510 | dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1; |
| 511 | dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 512 | |
| 513 | /* Transfer font info */ |
| 514 | if (style & DS_SETFONT) |
| 515 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 516 | put_word( &dialog16, get_word( &dialog32 ) ); /* pointSize */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 517 | if (dialogEx) |
| 518 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 519 | put_word( &dialog16, get_word( &dialog32 ) ); /* weight */ |
| 520 | put_word( &dialog16, get_word( &dialog32 ) ); /* italic */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 521 | } |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 522 | WideCharToMultiByte( CP_ACP, 0, (LPWSTR)dialog32, -1, (LPSTR)dialog16, 0x7fffffff, NULL, NULL ); /* faceName */ |
| 523 | dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1; |
| 524 | dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /* Transfer dialog items */ |
| 528 | while (nbItems) |
| 529 | { |
| 530 | /* align on DWORD boundary (32-bit only) */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 531 | dialog32 = (LPVOID)((((int)dialog32) + 3) & ~3); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 532 | |
| 533 | if (dialogEx) |
| 534 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 535 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* helpID */ |
| 536 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* exStyle */ |
| 537 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* style */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 538 | } |
| 539 | else |
| 540 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 541 | style = get_dword( &dialog32 ); /* save style */ |
| 542 | dialog32 = (DWORD *)dialog32 + 1; /* ignore exStyle */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 545 | put_word( &dialog16, get_word( &dialog32 ) ); /* x */ |
| 546 | put_word( &dialog16, get_word( &dialog32 ) ); /* y */ |
| 547 | put_word( &dialog16, get_word( &dialog32 ) ); /* cx */ |
| 548 | put_word( &dialog16, get_word( &dialog32 ) ); /* cy */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 549 | |
| 550 | if (dialogEx) |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 551 | put_dword( &dialog16, get_dword( &dialog32 ) ); /* ID */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 552 | else |
| 553 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 554 | put_word( &dialog16, get_word( &dialog32 ) ); /* ID */ |
| 555 | put_dword( &dialog16, style ); /* style from above */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* Transfer class name */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 559 | switch (*(WORD *)dialog32) |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 560 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 561 | case 0x0000: |
| 562 | get_word( &dialog32 ); |
| 563 | put_byte( &dialog16, 0 ); |
| 564 | break; |
| 565 | case 0xffff: |
| 566 | get_word( &dialog32 ); |
| 567 | put_byte( &dialog16, get_word( &dialog32 ) ); |
| 568 | break; |
| 569 | default: |
| 570 | WideCharToMultiByte( CP_ACP, 0, (LPWSTR)dialog32, -1, (LPSTR)dialog16, 0x7fffffff, NULL, NULL ); |
| 571 | dialog16 = (LPSTR)dialog16 + strlen( (LPSTR)dialog16 ) + 1; |
| 572 | dialog32 = (LPWSTR)dialog32 + strlenW( (LPWSTR)dialog32 ) + 1; |
| 573 | break; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* Transfer window name */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 577 | convert_name( &dialog16, &dialog32 ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 578 | |
| 579 | /* Transfer data */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 580 | data = get_word( &dialog32 ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 581 | if (dialogEx) |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 582 | put_word(&dialog16, data); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 583 | else |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 584 | put_byte(&dialog16,(BYTE)data); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 585 | |
| 586 | if (data) |
| 587 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 588 | memcpy( dialog16, dialog32, data ); |
| 589 | dialog16 = (BYTE *)dialog16 + data; |
| 590 | dialog32 = (BYTE *)dialog32 + data; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | /* Next item */ |
| 594 | nbItems--; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | |
| 599 | /********************************************************************** |
| 600 | * GetDialog32Size (KERNEL.618) |
| 601 | */ |
| 602 | WORD WINAPI GetDialog32Size16( LPVOID dialog32 ) |
| 603 | { |
| 604 | LPVOID p = dialog32; |
| 605 | WORD nbItems, data, dialogEx; |
| 606 | DWORD style; |
| 607 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 608 | style = get_dword(&p); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 609 | dialogEx = (style == 0xffff0001); /* DIALOGEX resource */ |
| 610 | if (dialogEx) |
| 611 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 612 | p = (DWORD *)p + 1; /* helpID */ |
| 613 | p = (DWORD *)p + 1; /* exStyle */ |
| 614 | style = get_dword(&p); /* style */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 615 | } |
| 616 | else |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 617 | p = (DWORD *)p + 1; /* exStyle */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 618 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 619 | nbItems = get_word(&p); |
| 620 | p = (WORD *)p + 1; /* x */ |
| 621 | p = (WORD *)p + 1; /* y */ |
| 622 | p = (WORD *)p + 1; /* cx */ |
| 623 | p = (WORD *)p + 1; /* cy */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 624 | |
| 625 | /* Skip menu name */ |
| 626 | switch (*((WORD *)p)) |
| 627 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 628 | case 0x0000: p = (WORD *)p + 1; break; |
| 629 | case 0xffff: p = (WORD *)p + 2; break; |
| 630 | default: p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; break; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | /* Skip class name */ |
| 634 | switch (*((WORD *)p)) |
| 635 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 636 | case 0x0000: p = (WORD *)p + 1; break; |
| 637 | case 0xffff: p = (WORD *)p + 2; break; |
| 638 | default: p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; break; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /* Skip window caption */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 642 | p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 643 | |
| 644 | /* Skip font info */ |
| 645 | if (style & DS_SETFONT) |
| 646 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 647 | p = (WORD *)p + 1; /* pointSize */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 648 | if (dialogEx) |
| 649 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 650 | p = (WORD *)p + 1; /* weight */ |
| 651 | p = (WORD *)p + 1; /* italic */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 652 | } |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 653 | p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; /* faceName */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | /* Skip dialog items */ |
| 657 | while (nbItems) |
| 658 | { |
| 659 | /* align on DWORD boundary */ |
| 660 | p = (LPVOID)((((int)p) + 3) & ~3); |
| 661 | |
| 662 | if (dialogEx) |
| 663 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 664 | p = (DWORD *)p + 1; /* helpID */ |
| 665 | p = (DWORD *)p + 1; /* exStyle */ |
| 666 | p = (DWORD *)p + 1; /* style */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 667 | } |
| 668 | else |
| 669 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 670 | p = (DWORD *)p + 1; /* style */ |
| 671 | p = (DWORD *)p + 1; /* exStyle */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 672 | } |
| 673 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 674 | p = (WORD *)p + 1; /* x */ |
| 675 | p = (WORD *)p + 1; /* y */ |
| 676 | p = (WORD *)p + 1; /* cx */ |
| 677 | p = (WORD *)p + 1; /* cy */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 678 | |
| 679 | if (dialogEx) |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 680 | p = (DWORD *)p + 1; /* ID */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 681 | else |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 682 | p = (WORD *)p + 1; /* ID */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 683 | |
| 684 | /* Skip class name */ |
| 685 | switch (*((WORD *)p)) |
| 686 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 687 | case 0x0000: p = (WORD *)p + 1; break; |
| 688 | case 0xffff: p = (WORD *)p + 2; break; |
| 689 | default: p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; break; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /* Skip window name */ |
| 693 | switch (*((WORD *)p)) |
| 694 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 695 | case 0x0000: p = (WORD *)p + 1; break; |
| 696 | case 0xffff: p = (WORD *)p + 2; break; |
| 697 | default: p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; break; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | /* Skip data */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 701 | data = get_word(&p); |
| 702 | p = (BYTE *)p + data; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 703 | |
| 704 | /* Next item */ |
| 705 | nbItems--; |
| 706 | } |
| 707 | |
| 708 | return (WORD)((LPSTR)p - (LPSTR)dialog32); |
| 709 | } |
| 710 | |
| 711 | |
| 712 | /********************************************************************** |
| 713 | * ConvertMenu32To16 (KERNEL.616) |
| 714 | */ |
| 715 | VOID WINAPI ConvertMenu32To16( LPVOID menu32, DWORD size, LPVOID menu16 ) |
| 716 | { |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 717 | WORD version, headersize, flags, level = 1; |
| 718 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 719 | version = get_word( &menu32 ); |
| 720 | headersize = get_word( &menu32 ); |
| 721 | put_word( &menu16, version ); |
| 722 | put_word( &menu16, headersize ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 723 | if ( headersize ) |
| 724 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 725 | memcpy( menu16, menu32, headersize ); |
| 726 | menu16 = (BYTE *)menu16 + headersize; |
| 727 | menu32 = (BYTE *)menu32 + headersize; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | while ( level ) |
| 731 | if ( version == 0 ) /* standard */ |
| 732 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 733 | flags = get_word( &menu32 ); |
| 734 | put_word( &menu16, flags ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 735 | if ( !(flags & MF_POPUP) ) |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 736 | put_word( &menu16, get_word( &menu32 ) ); /* ID */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 737 | else |
| 738 | level++; |
| 739 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 740 | WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL ); |
| 741 | menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1; |
| 742 | menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 743 | |
| 744 | if ( flags & MF_END ) |
| 745 | level--; |
| 746 | } |
| 747 | else /* extended */ |
| 748 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 749 | put_dword( &menu16, get_dword( &menu32 ) ); /* fType */ |
| 750 | put_dword( &menu16, get_dword( &menu32 ) ); /* fState */ |
| 751 | put_word( &menu16, get_dword( &menu32 ) ); /* ID */ |
| 752 | flags = get_word( &menu32 ); |
| 753 | put_byte(&menu16,flags); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 754 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 755 | WideCharToMultiByte( CP_ACP, 0, (LPWSTR)menu32, -1, (LPSTR)menu16, 0x7fffffff, NULL, NULL ); |
| 756 | menu16 = (LPSTR)menu16 + strlen( (LPSTR)menu16 ) + 1; |
| 757 | menu32 = (LPWSTR)menu32 + strlenW( (LPWSTR)menu32 ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 758 | |
| 759 | /* align on DWORD boundary (32-bit only) */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 760 | menu32 = (LPVOID)((((int)menu32) + 3) & ~3); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 761 | |
| 762 | /* If popup, transfer helpid */ |
| 763 | if ( flags & 1) |
| 764 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 765 | put_dword( &menu16, get_dword( &menu32 ) ); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 766 | level++; |
| 767 | } |
| 768 | |
| 769 | if ( flags & MF_END ) |
| 770 | level--; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | |
| 775 | /********************************************************************** |
| 776 | * GetMenu32Size (KERNEL.617) |
| 777 | */ |
| 778 | WORD WINAPI GetMenu32Size16( LPVOID menu32 ) |
| 779 | { |
| 780 | LPVOID p = menu32; |
| 781 | WORD version, headersize, flags, level = 1; |
| 782 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 783 | version = get_word(&p); |
| 784 | headersize = get_word(&p); |
| 785 | p = (BYTE *)p + headersize; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 786 | |
| 787 | while ( level ) |
| 788 | if ( version == 0 ) /* standard */ |
| 789 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 790 | flags = get_word(&p); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 791 | if ( !(flags & MF_POPUP) ) |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 792 | p = (WORD *)p + 1; /* ID */ |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 793 | else |
| 794 | level++; |
| 795 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 796 | p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 797 | |
| 798 | if ( flags & MF_END ) |
| 799 | level--; |
| 800 | } |
| 801 | else /* extended */ |
| 802 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 803 | p = (DWORD *)p + 1; /* fType */ |
| 804 | p = (DWORD *)p + 1; /* fState */ |
| 805 | p = (DWORD *)p + 1; /* ID */ |
| 806 | flags = get_word(&p); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 807 | |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 808 | p = (LPWSTR)p + strlenW( (LPWSTR)p ) + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 809 | |
| 810 | /* align on DWORD boundary (32-bit only) */ |
| 811 | p = (LPVOID)((((int)p) + 3) & ~3); |
| 812 | |
| 813 | /* If popup, skip helpid */ |
| 814 | if ( flags & 1) |
| 815 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 816 | p = (DWORD *)p + 1; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 817 | level++; |
| 818 | } |
| 819 | |
| 820 | if ( flags & MF_END ) |
| 821 | level--; |
| 822 | } |
| 823 | |
| 824 | return (WORD)((LPSTR)p - (LPSTR)menu32); |
| 825 | } |
| 826 | |
| 827 | |
| 828 | /********************************************************************** |
| 829 | * ConvertAccelerator32To16 |
| 830 | */ |
| 831 | static void ConvertAccelerator32To16( LPVOID acc32, DWORD size, LPVOID acc16 ) |
| 832 | { |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 833 | BYTE type; |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 834 | |
| 835 | do |
| 836 | { |
| 837 | /* Copy type */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 838 | type = get_byte(&acc32); |
| 839 | put_byte(&acc16, type); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 840 | /* Skip padding */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 841 | get_byte(&acc32); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 842 | /* Copy event and IDval */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 843 | put_word(&acc16, get_word(&acc32)); |
| 844 | put_word(&acc16, get_word(&acc32)); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 845 | /* Skip padding */ |
Alexandre Julliard | c95b984 | 2004-07-23 19:09:35 +0000 | [diff] [blame] | 846 | get_word(&acc32); |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 847 | |
| 848 | } while ( !( type & 0x80 ) ); |
| 849 | } |
| 850 | |
| 851 | |
| 852 | /********************************************************************** |
| 853 | * NE_LoadPEResource |
| 854 | */ |
| 855 | static HGLOBAL16 NE_LoadPEResource( NE_MODULE *pModule, WORD type, LPVOID bits, DWORD size ) |
| 856 | { |
| 857 | HGLOBAL16 handle; |
| 858 | |
| 859 | TRACE("module=%04x type=%04x\n", pModule->self, type ); |
| 860 | |
| 861 | handle = GlobalAlloc16( 0, size ); |
| 862 | |
| 863 | switch (type) |
| 864 | { |
Alexandre Julliard | cf52644 | 2003-09-10 03:56:47 +0000 | [diff] [blame] | 865 | case RT_MENU: |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 866 | ConvertMenu32To16( bits, size, GlobalLock16( handle ) ); |
| 867 | break; |
Alexandre Julliard | cf52644 | 2003-09-10 03:56:47 +0000 | [diff] [blame] | 868 | case RT_DIALOG: |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 869 | ConvertDialog32To16( bits, size, GlobalLock16( handle ) ); |
| 870 | break; |
Alexandre Julliard | cf52644 | 2003-09-10 03:56:47 +0000 | [diff] [blame] | 871 | case RT_ACCELERATOR: |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 872 | ConvertAccelerator32To16( bits, size, GlobalLock16( handle ) ); |
| 873 | break; |
Alexandre Julliard | cf52644 | 2003-09-10 03:56:47 +0000 | [diff] [blame] | 874 | case RT_STRING: |
Alexandre Julliard | 424202b | 2003-04-30 00:53:23 +0000 | [diff] [blame] | 875 | FIXME("not yet implemented!\n" ); |
| 876 | /* fall through */ |
| 877 | default: |
| 878 | memcpy( GlobalLock16( handle ), bits, size ); |
| 879 | break; |
| 880 | } |
| 881 | return handle; |
| 882 | } |
| 883 | |
| 884 | |
| 885 | /********************************************************************** |
| 886 | * AllocResource (KERNEL.66) |
| 887 | */ |
| 888 | HGLOBAL16 WINAPI AllocResource16( HMODULE16 hModule, HRSRC16 hRsrc, DWORD size) |
| 889 | { |
| 890 | NE_NAMEINFO *pNameInfo=NULL; |
| 891 | WORD sizeShift; |
| 892 | HGLOBAL16 ret; |
| 893 | |
| 894 | NE_MODULE *pModule = NE_GetPtr( hModule ); |
| 895 | if (!pModule || !pModule->res_table || !hRsrc) return 0; |
| 896 | |
| 897 | TRACE("module=%04x res=%04x size=%ld\n", hModule, hRsrc, size ); |
| 898 | |
| 899 | sizeShift = *(WORD *)((char *)pModule + pModule->res_table); |
| 900 | pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc); |
| 901 | if (size < (DWORD)pNameInfo->length << sizeShift) |
| 902 | size = (DWORD)pNameInfo->length << sizeShift; |
| 903 | ret = GlobalAlloc16( GMEM_FIXED, size ); |
| 904 | if (ret) FarSetOwner16( ret, hModule ); |
| 905 | return ret; |
| 906 | } |
| 907 | |
| 908 | |
| 909 | /********************************************************************** |
| 910 | * DirectResAlloc (KERNEL.168) |
| 911 | * |
| 912 | * Check Schulman, p. 232 for details |
| 913 | */ |
| 914 | HGLOBAL16 WINAPI DirectResAlloc16( HINSTANCE16 hInstance, WORD wType, |
| 915 | UINT16 wSize ) |
| 916 | { |
| 917 | HGLOBAL16 ret; |
| 918 | TRACE("(%04x,%04x,%04x)\n", hInstance, wType, wSize ); |
| 919 | if (!(hInstance = GetExePtr( hInstance ))) return 0; |
| 920 | if(wType != 0x10) /* 0x10 is the only observed value, passed from |
| 921 | CreateCursorIndirect. */ |
| 922 | TRACE("(wType=%x)\n", wType); |
| 923 | ret = GlobalAlloc16( GMEM_MOVEABLE, wSize ); |
| 924 | if (ret) FarSetOwner16( ret, hInstance ); |
| 925 | return ret; |
| 926 | } |
| 927 | |
| 928 | |
| 929 | /********************************************************************** |
| 930 | * AccessResource (KERNEL.64) |
| 931 | */ |
| 932 | INT16 WINAPI AccessResource16( HINSTANCE16 hModule, HRSRC16 hRsrc ) |
| 933 | { |
| 934 | HFILE16 fd; |
| 935 | NE_MODULE *pModule = NE_GetPtr( hModule ); |
| 936 | |
| 937 | if (!pModule || !pModule->res_table || !hRsrc) return -1; |
| 938 | |
| 939 | TRACE("module=%04x res=%04x\n", pModule->self, hRsrc ); |
| 940 | |
| 941 | if ((fd = _lopen16( NE_MODULE_NAME(pModule), OF_READ )) != HFILE_ERROR16) |
| 942 | { |
| 943 | WORD sizeShift = *(WORD *)((char *)pModule + pModule->res_table); |
| 944 | NE_NAMEINFO *pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc); |
| 945 | _llseek16( fd, (int)pNameInfo->offset << sizeShift, SEEK_SET ); |
| 946 | } |
| 947 | return fd; |
| 948 | } |
| 949 | |
| 950 | |
| 951 | /********************************************************************** |
| 952 | * FindResource (KERNEL.60) |
| 953 | */ |
| 954 | HRSRC16 WINAPI FindResource16( HMODULE16 hModule, LPCSTR name, LPCSTR type ) |
| 955 | { |
| 956 | NE_TYPEINFO *pTypeInfo; |
| 957 | NE_NAMEINFO *pNameInfo; |
| 958 | LPBYTE pResTab; |
| 959 | NE_MODULE *pModule = get_module( hModule ); |
| 960 | |
| 961 | if (!pModule) return 0; |
| 962 | |
| 963 | if (pModule->module32) |
| 964 | { |
| 965 | /* 32-bit PE module */ |
| 966 | HRSRC hRsrc32 = FindResourceA( pModule->module32, name, type ); |
| 967 | return MapHRsrc32To16( pModule, hRsrc32, HIWORD(type) ? 0 : LOWORD(type) ); |
| 968 | } |
| 969 | |
| 970 | TRACE("module=%04x name=%s type=%s\n", pModule->self, debugstr_a(name), debugstr_a(type) ); |
| 971 | |
| 972 | if (!pModule->res_table) return 0; |
| 973 | |
| 974 | type = get_res_name( type ); |
| 975 | name = get_res_name( name ); |
| 976 | |
| 977 | if (HIWORD(type) || HIWORD(name)) |
| 978 | { |
| 979 | DWORD id = NE_FindNameTableId( pModule, type, name ); |
| 980 | if (id) /* found */ |
| 981 | { |
| 982 | type = (LPCSTR)(ULONG_PTR)LOWORD(id); |
| 983 | name = (LPCSTR)(ULONG_PTR)HIWORD(id); |
| 984 | } |
| 985 | } |
| 986 | pResTab = (LPBYTE)pModule + pModule->res_table; |
| 987 | pTypeInfo = (NE_TYPEINFO *)( pResTab + 2 ); |
| 988 | |
| 989 | for (;;) |
| 990 | { |
| 991 | if (!(pTypeInfo = NE_FindTypeSection( pResTab, pTypeInfo, type ))) break; |
| 992 | if ((pNameInfo = NE_FindResourceFromType( pResTab, pTypeInfo, name ))) |
| 993 | { |
| 994 | TRACE(" Found id %08lx\n", (DWORD)name ); |
| 995 | return (HRSRC16)( (char *)pNameInfo - (char *)pModule ); |
| 996 | } |
| 997 | pTypeInfo = next_typeinfo(pTypeInfo); |
| 998 | } |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | |
| 1003 | /********************************************************************** |
| 1004 | * LoadResource (KERNEL.61) |
| 1005 | */ |
| 1006 | HGLOBAL16 WINAPI LoadResource16( HMODULE16 hModule, HRSRC16 hRsrc ) |
| 1007 | { |
| 1008 | NE_TYPEINFO *pTypeInfo; |
| 1009 | NE_NAMEINFO *pNameInfo = NULL; |
| 1010 | NE_MODULE *pModule = get_module( hModule ); |
| 1011 | int d; |
| 1012 | |
| 1013 | if (!hRsrc || !pModule) return 0; |
| 1014 | |
| 1015 | if (pModule->module32) |
| 1016 | { |
| 1017 | /* load 32-bit resource and convert it */ |
| 1018 | HRSRC hRsrc32 = MapHRsrc16To32( pModule, hRsrc ); |
| 1019 | WORD type = MapHRsrc16ToType( pModule, hRsrc ); |
| 1020 | HGLOBAL hMem = LoadResource( pModule->module32, hRsrc32 ); |
| 1021 | DWORD size = SizeofResource( pModule->module32, hRsrc32 ); |
| 1022 | if (!hMem) return 0; |
| 1023 | return NE_LoadPEResource( pModule, type, LockResource( hMem ), size ); |
| 1024 | } |
| 1025 | |
| 1026 | /* first, verify hRsrc (just an offset from pModule to the needed pNameInfo) */ |
| 1027 | |
| 1028 | d = pModule->res_table + 2; |
| 1029 | pTypeInfo = (NE_TYPEINFO *)((char *)pModule + d); |
| 1030 | while( hRsrc > d ) |
| 1031 | { |
| 1032 | if (pTypeInfo->type_id == 0) break; /* terminal entry */ |
| 1033 | d += sizeof(NE_TYPEINFO) + pTypeInfo->count * sizeof(NE_NAMEINFO); |
| 1034 | if (hRsrc < d) |
| 1035 | { |
| 1036 | if( ((d - hRsrc)%sizeof(NE_NAMEINFO)) == 0 ) |
| 1037 | { |
| 1038 | pNameInfo = (NE_NAMEINFO *)((char *)pModule + hRsrc); |
| 1039 | break; |
| 1040 | } |
| 1041 | else break; /* NE_NAMEINFO boundary mismatch */ |
| 1042 | } |
| 1043 | pTypeInfo = (NE_TYPEINFO *)((char *)pModule + d); |
| 1044 | } |
| 1045 | |
| 1046 | if (pNameInfo) |
| 1047 | { |
| 1048 | if (pNameInfo->handle && !(GlobalFlags16(pNameInfo->handle) & GMEM_DISCARDED)) |
| 1049 | { |
| 1050 | pNameInfo->usage++; |
| 1051 | TRACE(" Already loaded, new count=%d\n", pNameInfo->usage ); |
| 1052 | } |
| 1053 | else |
| 1054 | { |
| 1055 | FARPROC16 resloader; |
| 1056 | memcpy_unaligned( &resloader, &pTypeInfo->resloader, sizeof(FARPROC16) ); |
| 1057 | if (resloader && resloader != get_default_res_handler()) |
| 1058 | { |
| 1059 | WORD args[3]; |
| 1060 | DWORD ret; |
| 1061 | |
| 1062 | args[2] = pNameInfo->handle; |
| 1063 | args[1] = pModule->self; |
| 1064 | args[0] = hRsrc; |
| 1065 | WOWCallback16Ex( (DWORD)resloader, WCB16_PASCAL, sizeof(args), args, &ret ); |
| 1066 | pNameInfo->handle = LOWORD(ret); |
| 1067 | } |
| 1068 | else |
| 1069 | pNameInfo->handle = NE_DefResourceHandler( pNameInfo->handle, pModule->self, hRsrc ); |
| 1070 | |
| 1071 | if (pNameInfo->handle) |
| 1072 | { |
| 1073 | pNameInfo->usage++; |
| 1074 | pNameInfo->flags |= NE_SEGFLAGS_LOADED; |
| 1075 | } |
| 1076 | } |
| 1077 | return pNameInfo->handle; |
| 1078 | } |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | /********************************************************************** |
| 1084 | * LockResource (KERNEL.62) |
| 1085 | */ |
| 1086 | SEGPTR WINAPI WIN16_LockResource16( HGLOBAL16 handle ) |
| 1087 | { |
| 1088 | TRACE("(%04x)\n", handle ); |
| 1089 | /* May need to reload the resource if discarded */ |
| 1090 | return K32WOWGlobalLock16( handle ); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | /********************************************************************** |
| 1095 | * LockResource16 (KERNEL32.@) |
| 1096 | */ |
| 1097 | LPVOID WINAPI LockResource16( HGLOBAL16 handle ) |
| 1098 | { |
| 1099 | return MapSL( WIN16_LockResource16(handle) ); |
| 1100 | } |
| 1101 | |
| 1102 | |
| 1103 | /********************************************************************** |
| 1104 | * SizeofResource (KERNEL.65) |
| 1105 | */ |
| 1106 | DWORD WINAPI SizeofResource16( HMODULE16 hModule, HRSRC16 hRsrc ) |
| 1107 | { |
| 1108 | NE_MODULE *pModule = NE_GetPtr( hModule ); |
| 1109 | |
| 1110 | TRACE("(%x, %x)\n", hModule, hRsrc ); |
| 1111 | |
| 1112 | if (!hRsrc) return 0; |
| 1113 | if (!(pModule = get_module( hModule ))) return 0; |
| 1114 | if (pModule->res_table) |
| 1115 | { |
| 1116 | WORD sizeShift = *(WORD *)((char *)pModule + pModule->res_table); |
| 1117 | NE_NAMEINFO *pNameInfo = (NE_NAMEINFO*)((char*)pModule + hRsrc); |
| 1118 | return (DWORD)pNameInfo->length << sizeShift; |
| 1119 | } |
| 1120 | if (pModule->module32) |
| 1121 | { |
| 1122 | /* 32-bit PE module */ |
| 1123 | return SizeofResource( pModule->module32, MapHRsrc16To32( pModule, hRsrc ) ); |
| 1124 | } |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | |
| 1129 | typedef WORD (WINAPI *pDestroyIcon32Proc)( HGLOBAL16 handle, UINT16 flags ); |
| 1130 | |
| 1131 | /********************************************************************** |
| 1132 | * FreeResource (KERNEL.63) |
| 1133 | */ |
| 1134 | BOOL16 WINAPI FreeResource16( HGLOBAL16 handle ) |
| 1135 | { |
| 1136 | pDestroyIcon32Proc proc; |
| 1137 | HMODULE user; |
| 1138 | NE_MODULE *pModule = NE_GetPtr( FarGetOwner16( handle ) ); |
| 1139 | |
| 1140 | TRACE("(%04x)\n", handle ); |
| 1141 | |
| 1142 | /* Try NE resource first */ |
| 1143 | |
| 1144 | if (pModule && pModule->res_table) |
| 1145 | { |
| 1146 | NE_TYPEINFO *pTypeInfo = (NE_TYPEINFO *)((char *)pModule + pModule->res_table + 2); |
| 1147 | while (pTypeInfo->type_id) |
| 1148 | { |
| 1149 | WORD count; |
| 1150 | NE_NAMEINFO *pNameInfo = (NE_NAMEINFO *)(pTypeInfo + 1); |
| 1151 | for (count = pTypeInfo->count; count > 0; count--) |
| 1152 | { |
| 1153 | if (pNameInfo->handle == handle) |
| 1154 | { |
| 1155 | if (pNameInfo->usage > 0) pNameInfo->usage--; |
| 1156 | if (pNameInfo->usage == 0) |
| 1157 | { |
| 1158 | GlobalFree16( pNameInfo->handle ); |
| 1159 | pNameInfo->handle = 0; |
| 1160 | pNameInfo->flags &= ~NE_SEGFLAGS_LOADED; |
| 1161 | } |
| 1162 | return 0; |
| 1163 | } |
| 1164 | pNameInfo++; |
| 1165 | } |
| 1166 | pTypeInfo = (NE_TYPEINFO *)pNameInfo; |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | /* If this failed, call USER.DestroyIcon32; this will check |
| 1171 | whether it is a shared cursor/icon; if not it will call |
| 1172 | GlobalFree16() */ |
| 1173 | user = GetModuleHandleA( "user32.dll" ); |
| 1174 | if (user && (proc = (pDestroyIcon32Proc)GetProcAddress( user, "DestroyIcon32" ))) |
| 1175 | return proc( handle, 1 /*CID_RESOURCE*/ ); |
| 1176 | else |
| 1177 | return GlobalFree16( handle ); |
| 1178 | } |