Changeset 1356 for trunk/src


Ignore:
Timestamp:
Oct 19, 1999, 2:51:25 PM (26 years ago)
Author:
sandervl
Message:

Resource support for DIB type (DISABLED)

Location:
trunk/src/kernel32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/winimgres.cpp

    r1274 r1356  
    1 /* $Id: winimgres.cpp,v 1.23 1999-10-14 01:37:56 bird Exp $ */
     1/* $Id: winimgres.cpp,v 1.24 1999-10-19 12:51:25 sandervl Exp $ */
    22
    33/*
     
    1212 * TODO: Once the resource handling in PE2LX/win32k is changed,
    1313 *       getVersionStruct/Size can be moved into the Win32ImageBase class
     14 * TODO: Support for 'DIB' resource type (VPBuddy)
    1415 *
    1516 */
     
    3132#include "oslibmisc.h"
    3233
     34//SvL: VPBuddy bugfix, seems to load bitmaps with type name 'DIB'
     35#define BITMAP_TYPENAME2    "DIB"
     36
    3337//******************************************************************************
    3438//Assuming names are case insensitive
     
    6367  if(HIWORD(type) != 0) {//string id?
    6468    for(i=0;i<MAX_RES;i++) {
    65          if(stricmp((char *)type, ResTypes[i]) == 0)
     69        if(stricmp((char *)type, ResTypes[i]) == 0)
    6670                break;
    6771    }
     72//TODO:
     73#if 0
     74    if(stricmp((char *)type, BITMAP_TYPENAME2) == 0) {
     75        i = (int)RT_BITMAPA;
     76    }
     77#endif
     78
    6879    if(i == MAX_RES) {//custom resource type
    6980         fNumType = FALSE;
     
    7990    {//name or id entry?
    8091        //SvL: 30-10-'97, high bit is set, so clear to get real offset
    81     nameOffset = prde->u1.Name & ~0x80000000;
     92        nameOffset = prde->u1.Name & ~0x80000000;
    8293
    8394        pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + nameOffset);
    84     char *typename = (char *)malloc(pstring->Length+1);
     95        char *typename = (char *)malloc(pstring->Length+1);
    8596        lstrcpynWtoA(typename, pstring->NameString, pstring->Length+1);
    86     typename[pstring->Length] = 0;
     97        typename[pstring->Length] = 0;
    8798
    8899        if(!fNumType) {
     
    100111            }
    101112        }
    102     free(typename);
     113        free(typename);
    103114    }
    104115    else {
     
    171182    else
    172183        if(!fNumId) {//name or id entry?
    173         nameOffset = prde->u1.Name;
     184            nameOffset = prde->u1.Name;
    174185            if(prde->u1.s.NameIsString) //unicode directory string /*PLF Sat  97-06-21 22:30:35*/
    175186                    nameOffset &= ~0x80000000;
     
    177188            pstring = (PIMAGE_RESOURCE_DIR_STRING_U)((ULONG)pResDir + nameOffset);
    178189
    179         resname = (char *)malloc(pstring->Length+1);
     190            resname = (char *)malloc(pstring->Length+1);
    180191            lstrcpynWtoA(resname, pstring->NameString, pstring->Length+1);
    181         resname[pstring->Length] = 0;
     192            resname[pstring->Length] = 0;
    182193            if(stricmp(resname, (char *)*nodeData) == 0) {
    183194                    fFound = TRUE;
    184195            }
    185         free(resname);
     196            free(resname);
    186197        }
    187198        else {
     
    190201        }
    191202
    192     if(fFound) {
     203        if(fFound) {
    193204            if((ULONG)prdType2 & 0x80000000) {//subdirectory?
    194205                    return ProcessResSubDir(prdType2, nodeData+1, 3);
     
    197208                    pData = (PIMAGE_RESOURCE_DATA_ENTRY)prdType2;
    198209                    if(pData->Size) {//winamp17 winzip archive has resource with size 0
    199                         return(pData);
     210                            return(pData);
    200211                    }
    201212                    else    return(NULL);
     
    212223 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
    213224
    214   pData = getPEResourceEntry(id, type, lang);
    215   if(pData == NULL) {
    216     dprintf(("Win32ImageBase::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));
    217     return 0;
    218   }
    219   return pData->Size;
     225    pData = getPEResourceEntry(id, type, lang);
     226    if(pData == NULL) {
     227        dprintf(("Win32ImageBase::getPEResourceSize: couldn't find resource %d (type %d, lang %d)", id, type, lang));
     228        return 0;
     229    }
     230    return pData->Size;
    220231}
    221232//******************************************************************************
     
    230241 int    i, stringid = -1, j;
    231242
    232   fNumType = TRUE;    //assume numeric
    233   if(HIWORD(lpszType) != 0) {//string id?
     243    fNumType = TRUE;    //assume numeric
     244    if(HIWORD(lpszType) != 0) {//string id?
    234245        for(i=0;i<MAX_RES;i++) {
    235246            if(stricmp(lpszType, ResTypes[i]) == 0)
    236247                    break;
    237248        }
     249//TODO:
     250#if 0
     251        if(stricmp((char *)lpszType, BITMAP_TYPENAME2) == 0) {
     252            i = (int)RT_BITMAPA;
     253        }
     254#endif
    238255        if(i == MAX_RES) {//custom resource type
    239256            fNumType = FALSE;
    240         type = (ULONG)lpszType;
    241         }
    242         else    type = i;
    243   }
    244   else  type = (ULONG)lpszType;
    245 
    246   //String format: tables of 16 strings stored as one resource
    247   //upper 12 bits of resource id passed by user determines block (res id)
    248   //lower 4 bits are an index into the string table
    249   if(fNumType) {
    250     if(type == NTRT_STRING) {
    251          stringid = (ULONG)lpszName & 0xF;
    252          id       = (((ULONG)lpszName) >> 4)+1;
    253     }
    254     else id = (ULONG)lpszName;
    255   }
    256   else {
    257     if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {
    258          stringid = (ULONG)lpszName & 0xF;
    259          id       = (((ULONG)lpszName) >> 4)+1;
    260     }
    261     else id = (ULONG)lpszName;
    262   }
    263 
    264   pData = getPEResourceEntry(id, type, lang);
    265   if(pData == NULL) {
    266     if(HIWORD(id)) {
     257            type = (ULONG)lpszType;
     258        }
     259        else type = i;
     260    }
     261    else  type = (ULONG)lpszType;
     262
     263    //String format: tables of 16 strings stored as one resource
     264    //upper 12 bits of resource id passed by user determines block (res id)
     265    //lower 4 bits are an index into the string table
     266    if(fNumType) {
     267        if(type == NTRT_STRING) {
     268            stringid = (ULONG)lpszName & 0xF;
     269            id       = (((ULONG)lpszName) >> 4)+1;
     270        }
     271        else id = (ULONG)lpszName;
     272    }
     273    else {
     274        if(stricmp((char *)type, ResTypes[NTRT_STRING]) == 0) {
     275            stringid = (ULONG)lpszName & 0xF;
     276            id       = (((ULONG)lpszName) >> 4)+1;
     277        }
     278        else id = (ULONG)lpszName;
     279    }
     280
     281    pData = getPEResourceEntry(id, type, lang);
     282    if(pData == NULL) {
     283        if(HIWORD(id)) {
    267284                dprintf(("Win32ImageBase::getPEResource %s: couldn't find resource %s (type %d, lang %d)", szModule, id, type, lang));
    268     }
     285        }
    269286        else    dprintf(("Win32ImageBase::getPEResource %s: couldn't find resource %d (type %d, lang %d)", szModule, id, type, lang));
    270     return 0;
    271   }
    272   //pResourceSectionStart contains the virtual address of the imagebase in the PE header
    273   //for the resource section (images loaded by the pe.exe)
    274   //For LX images, this is 0 as OffsetToData contains a relative offset
    275   char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
    276   if(stringid != -1) {//search for string in table
     287        return 0;
     288    }
     289    //pResourceSectionStart contains the virtual address of the imagebase in the PE header
     290    //for the resource section (images loaded by the pe.exe)
     291    //For LX images, this is 0 as OffsetToData contains a relative offset
     292    char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
     293    if(stringid != -1) {//search for string in table
    277294        USHORT *unicodestr = (USHORT *)resdata;
    278295
     
    286303            return(NULL);
    287304        }
    288   }
    289   else {
    290     switch(type) {
    291     case NTRT_MENU:
     305    }
     306    else
     307    {
     308        switch(type) {
     309        case NTRT_MENU:
    292310            res = new Win32MenuRes(this, id, type, pData->Size, resdata);
    293         break;
    294     default:
     311            break;
     312        default:
    295313            res = new Win32Resource(this, id, type, pData->Size, resdata);
    296         break;
    297     }
    298 
    299   }
    300 
    301   return (HRSRC) res;
    302 }
    303 //******************************************************************************
    304 //******************************************************************************
    305 #if 0
    306 HRSRC Win32Pe2LxImage::findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang)
    307 {
    308  Win32Resource *res = NULL;
    309  HRSRC hres;
    310  int   i;
    311  LPSTR szType = (LPSTR)lpszType;
    312 
    313     if(HIWORD(lpszType) != 0) {//type name, translate to id
    314         for(i=0;i<MAX_RES;i++) {
    315             if(strcmp(lpszType, ResTypes[i]) == 0)
    316                 break;
    317         }
    318         if(i == MAX_RES) {//custom resource type, stored as rcdata
    319                 dprintf(("FindResourceA custom type %s\n", lpszType));
    320                lpszType = (LPSTR)NTRT_RCDATA;
    321         }
    322         else    lpszType = (LPSTR)i;
    323 
    324         szType = (LPSTR)lpszType;
    325     }
    326     switch((int)szType) {
    327     case NTRT_GROUP_ICON:
    328         szType = (LPSTR)NTRT_ICON;
    329         break;
    330     case NTRT_GROUP_CURSOR:
    331         szType = (LPSTR)NTRT_CURSOR;
    332         break;
    333     case NTRT_VERSION:
    334         szType = (LPSTR)NTRT_RCDATA;
    335         break;
    336     case NTRT_STRING:
    337     case NTRT_MENU:
    338     case NTRT_ICON:
    339     case NTRT_BITMAP:
    340     case NTRT_CURSOR:
    341     case NTRT_DIALOG:
    342     case NTRT_RCDATA:
    343     case NTRT_ACCELERATORS:
    344         szType = lpszType;
    345         break;
    346     default: //unknown are stored as rcdata
    347         szType = (LPSTR)NTRT_RCDATA;
    348         break;
    349     }
    350     dprintf(("FindResourceA from %X type %d (%X)\n", hinstance, szType, lpszType));
    351 
    352     if(HIWORD(lpszName) != 0) {//convert string name identifier to numeric id
    353         dprintf(("FindResource %s\n", lpszName));
    354         if(lpszName[0] == '#') {// #344
    355                 lpszName = (LPCSTR)atoi(&lpszName[1]);
    356         }
    357         else    lpszName = (LPCSTR)convertNameId((char *)lpszName);
    358     }
    359     else dprintf(("FindResource %d\n", (int)lpszName));
    360 
    361     hres = O32_FindResource(hinstance, lpszName, szType);
    362     if(hres)
    363     {
    364     switch((ULONG)szType) {
    365     case NTRT_MENU:
    366             res = new Win32MenuRes(this, hres, (ULONG)lpszName, (ULONG)szType);
    367         break;
    368     default:
    369             res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType);
    370         break;
    371     }
    372     }
    373 
    374     if(hres == NULL && HIWORD(lpszName) == 0 && (int)szType == NTRT_STRING) {
    375         hres = O32_FindResource(hinstance, (LPCSTR)(((int)lpszName - 1)*16), (LPCSTR)NTRT_RCDATA);
    376         if(hres)
    377         {
    378             res = new Win32Resource(this, hres, (ULONG)lpszName, (ULONG)szType);
    379         }
    380         else    dprintf(("FindResourceA can't find string %d\n", (int)lpszName));
    381     }
    382     dprintf(("FindResourceA returned %X (%X)\n", hres, GetLastError()));
    383 
    384     return (HRSRC)res;
    385 }
    386 #endif
     314            break;
     315        }
     316
     317    }
     318
     319    return (HRSRC) res;
     320}
    387321//******************************************************************************
    388322//******************************************************************************
     
    483417 PIMAGE_RESOURCE_DATA_ENTRY      pData = NULL;
    484418
    485   if(verstruct == NULL || bufLength == 0) {
    486     SetLastError(ERROR_INVALID_PARAMETER);
    487     return FALSE;
    488   }
    489   pData = getPEResourceEntry(ID_GETFIRST, NTRT_VERSION);
    490   if(pData == NULL) {
    491     dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));
    492     return 0;
    493   }
    494   char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
    495   memcpy(verstruct, resdata, min(bufLength, pData->Size));
    496   return TRUE;
    497 }
    498 //******************************************************************************
    499 //******************************************************************************
     419    if(verstruct == NULL || bufLength == 0) {
     420        SetLastError(ERROR_INVALID_PARAMETER);
     421        return FALSE;
     422    }
     423    pData = getPEResourceEntry(ID_GETFIRST, NTRT_VERSION);
     424    if(pData == NULL) {
     425        dprintf(("Win32PeLdrImage::getVersionStruct: couldn't find version resource!"));
     426        return 0;
     427    }
     428    char *resdata = (char *)((char *)pResDir + pData->OffsetToData - pResourceSectionStart);
     429    memcpy(verstruct, resdata, min(bufLength, pData->Size));
     430    return TRUE;
     431}
     432//******************************************************************************
     433//******************************************************************************
  • trunk/src/kernel32/winres.cpp

    r956 r1356  
    1 /* $Id: winres.cpp,v 1.19 1999-09-15 23:38:02 sandervl Exp $ */
     1/* $Id: winres.cpp,v 1.20 1999-10-19 12:51:25 sandervl Exp $ */
    22
    33/*
     
    1616#define INCL_BITMAPFILEFORMAT
    1717#define INCL_DOSMODULEMGR
    18 #include <os2wrap.h>    //Odin32 OS/2 api wrappers
     18#include <os2wrap.h>    //Odin32 OS/2 api wrappers
    1919#include <stdarg.h>
    2020#ifdef __IBMCPP__
     
    107107  //resources are in Unicode format by default; indirectly created resources
    108108  //can also be in ascii format
    109   isUnicode  = TRUE; 
     109  isUnicode  = TRUE;
    110110}
    111111//******************************************************************************
     
    129129    case NTRT_NEWBITMAP:
    130130    case NTRT_BITMAP:
    131         orgos2type = RT_BITMAP;
     131        orgos2type = RT_BITMAP;
    132132        break;
    133133    case NTRT_CURSOR:
     
    135135    case NTRT_GROUP_ICON:
    136136    case NTRT_ICON:
    137         orgos2type = RT_POINTER;
    138         break;
     137        orgos2type = RT_POINTER;
     138        break;
    139139    case NTRT_ACCELERATORS:
    140         orgos2type = RT_ACCELTABLE;
    141         break;
     140        orgos2type = RT_ACCELTABLE;
     141    break;
    142142    case NTRT_NEWMENU:
    143143    case NTRT_MENU:
    144         orgos2type = RT_MENU;
    145         break;
     144        orgos2type = RT_MENU;
     145        break;
    146146    case NTRT_NEWDIALOG:
    147147    case NTRT_DIALOG:
    148         orgos2type = RT_DIALOG;
    149         break;
     148        orgos2type = RT_DIALOG;
     149        break;
    150150    case NTRT_FONTDIR:
    151151    case NTRT_FONT:
     
    166166  }
    167167  //resources are in Unicode format by default
    168   isUnicode  = TRUE; 
     168  isUnicode  = TRUE;
    169169}
    170170//******************************************************************************
     
    192192
    193193  if(type == NTRT_STRING) {
    194         memcpy(winresdata, resdata, size-sizeof(WCHAR));
    195         ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0;
    196   }
    197   else  memcpy(winresdata, resdata, size);
     194    memcpy(winresdata, resdata, size-sizeof(WCHAR));
     195    ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0;
     196  }
     197  else  memcpy(winresdata, resdata, size);
    198198
    199199  //resources are in Unicode format by default
    200   isUnicode  = TRUE; 
     200  isUnicode  = TRUE;
    201201}
    202202//******************************************************************************
     
    208208  //returned by DosGetResource, so we don't (and mustn't) free it
    209209  if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT))
    210         free(os2resdata);
     210    free(os2resdata);
    211211
    212212  if(winresdata)    free(winresdata);
     
    235235
    236236  dprintf(("Win32Resource::lockResource %d\n", id));
     237
    237238  if(winresdata)
    238239    return(winresdata);
     
    290291        winresdata = malloc(ressize+sizeof(WCHAR));
    291292        memcpy(winresdata, resdata, ressize);
    292         *(USHORT *)(&((char *)winresdata)[ressize]) = 0;
     293    *(USHORT *)(&((char *)winresdata)[ressize]) = 0;
    293294        DosFreeResource(resdata);
    294295        return((PVOID)((ULONG)winresdata+2));   //skip length word
     
    303304
    304305  if(winresdata == NULL) {
    305         rc = DosGetResource((HMODULE)module->hinstance, os2type, id, (PPVOID)&resdata);
    306         if(rc) {
    307                 dprintf(("Can't find original resource!!!\n"));
    308                 return(NULL);
    309         }
    310         winresdata = (char *)malloc(ressize);
    311         memcpy(winresdata, resdata, ressize);
     306        rc = DosGetResource((HMODULE)module->hinstance, os2type, id, (PPVOID)&resdata);
     307        if(rc) {
     308            dprintf(("Can't find original resource!!!\n"));
     309            return(NULL);
     310        }
     311        winresdata = (char *)malloc(ressize);
     312        memcpy(winresdata, resdata, ressize);
    312313  }
    313314  if(resdata)
    314         DosFreeResource(resdata);
     315        DosFreeResource(resdata);
    315316
    316317  return winresdata;
     
    325326   dprintf(("Win32Resource::lockOS2Resource %d\n", id));
    326327   if(os2resdata == NULL) {
    327         if(resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT) {
    328                 os2resdata = convertResource(winresdata);
    329         }
    330         else {
    331                 rc = DosGetResource((HMODULE)module->hinstance, orgos2type, id, (PPVOID)&resdata);
    332                 if(rc)  return(NULL);
    333                 os2resdata = resdata;
    334         }
     328    if(resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT) {
     329        os2resdata = convertResource(winresdata);
     330    }
     331    else {
     332        rc = DosGetResource((HMODULE)module->hinstance, orgos2type, id, (PPVOID)&resdata);
     333        if(rc)  return(NULL);
     334        os2resdata = resdata;
     335    }
    335336   }
    336337   return os2resdata;
     
    344345    case NTRT_NEWBITMAP:
    345346    case NTRT_BITMAP:
    346         return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize);
     347    return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata, ressize);
    347348
    348349    case NTRT_CURSOR:
    349         return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize);
     350    return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize);
    350351
    351352    case NTRT_ICON:
    352         return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize);
     353    return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize);
    353354
    354355    case NTRT_GROUP_ICON:
     
    366367    case NTRT_STRING:
    367368    default:
    368         dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type));
    369         break;
     369    dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type));
     370    break;
    370371  }
    371372  return 0;
     
    380381    case NTRT_NEWBITMAP:
    381382    case NTRT_BITMAP:
    382         return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize);
     383    return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize);
    383384
    384385    case NTRT_CURSOR:
    385         return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize);
     386    return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize);
    386387
    387388    case NTRT_GROUP_CURSOR:
    388         return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
     389    return ConvertCursorGroup((CursorHeader *)win32res, ressize, module);
    389390
    390391    case NTRT_GROUP_ICON:
    391         return ConvertIconGroup((IconHeader *)win32res, ressize, module);
     392    return ConvertIconGroup((IconHeader *)win32res, ressize, module);
    392393
    393394    case NTRT_ICON:
    394         return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize);
     395    return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize);
    395396
    396397    case NTRT_ACCELERATORS:
    397         return ConvertAccelerator((WINACCEL *)win32res, ressize);
     398    return ConvertAccelerator((WINACCEL *)win32res, ressize);
    398399
    399400    case NTRT_NEWMENU:
    400401    case NTRT_MENU:
    401         return ConvertMenu((MenuHeader *)win32res, ressize, isUnicode);
     402    return ConvertMenu((MenuHeader *)win32res, ressize, isUnicode);
    402403
    403404    case NTRT_NEWDIALOG:
    404405    case NTRT_DIALOG:
    405         break;
     406    break;
    406407    case NTRT_FONTDIR:
    407408    case NTRT_FONT:
     
    410411    case NTRT_VERSION:
    411412    case NTRT_STRING:
    412         break;
     413    break;
    413414
    414415    default:
Note: See TracChangeset for help on using the changeset viewer.