Changeset 3625 for trunk/src/kernel32/winres.cpp
- Timestamp:
- May 28, 2000, 6:45:14 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kernel32/winres.cpp
r2802 r3625 1 /* $Id: winres.cpp,v 1.2 6 2000-02-16 14:22:12sandervl Exp $ */1 /* $Id: winres.cpp,v 1.27 2000-05-28 16:45:14 sandervl Exp $ */ 2 2 3 3 /* … … 26 26 #define INCL_WINRES 27 27 #include <win32type.h> 28 #include <win32api.h> 29 #include <winconst.h> 28 30 #include <winres.h> 29 31 #include <misc.h> 30 #include <winexepe2lx.h> 31 #include <windllpe2lx.h> 32 #include <winimagebase.h> 33 #include <winexebase.h> 34 #include <windllbase.h> 32 35 #include "cvtresource.h" 33 #include <vmutex.h>34 36 35 37 #define DBG_LOCALLOG DBG_winres 36 38 #include "dbglocal.h" 37 39 38 VMutex resmutex;39 40 char *ResTypes[MAX_RES] =41 {"niks", "CURSOR", "BITMAP", "ICON", "MENU", "DIALOG", "STRING",42 "FONTDIR", "FONT", "ACCELERATOR", "RCDATA", "MESSAGETABLE",43 "GROUP_CURSOR", "niks", "GROUP_ICON", "niks", "VERSION"};44 45 40 //****************************************************************************** 46 41 //****************************************************************************** 47 Win32Resource::Win32Resource() : 48 os2resdata(NULL), winresdata(NULL), resType(RSRC_CUSTOMNODATA) 42 PVOID WIN32API ConvertResourceToOS2(HINSTANCE hInstance, LPSTR restype, HRSRC hResource) 49 43 { 50 next = NULL; 51 module = NULL; 44 PIMAGE_RESOURCE_DATA_ENTRY pData = (PIMAGE_RESOURCE_DATA_ENTRY)hResource; 45 Win32ImageBase *module; 46 char *resdata; 47 int ressize, cvtressize; 52 48 53 id = -1; 54 type = -1; 55 hres = 0; 56 OS2ResHandle = 0; 57 //resources are in Unicode format by default; indirectly created resources 58 //can also be in ascii format 59 isUnicode = TRUE; 60 } 61 //****************************************************************************** 62 //****************************************************************************** 63 Win32Resource::Win32Resource(Win32ImageBase *module, ULONG id, ULONG type, 64 ULONG size, char *resdata) : hres(NULL), 65 os2resdata(NULL), winresdata(NULL), resType(RSRC_PELOADER) 66 { 67 resmutex.enter(); 68 next = module->winres; 69 module->winres = this; 70 resmutex.leave(); 71 72 this->module = module; 73 this->id = id; 74 this->type = type; 75 this->ressize = size; 76 winresdata = (char *)malloc(size+sizeof(WCHAR)); 77 if(winresdata == NULL) { 78 DebugInt3(); 79 return; 80 } 81 OS2ResHandle = 0; 82 83 if(type == NTRT_STRING) { 84 memcpy(winresdata, resdata, size); 85 ((USHORT *)winresdata)[size/sizeof(WCHAR)] = 0; 86 // ((USHORT *)winresdata)[size/sizeof(WCHAR)-1] = 0; 87 } 88 else memcpy(winresdata, resdata, size); 89 90 //resources are in Unicode format by default 91 isUnicode = TRUE; 92 } 93 //****************************************************************************** 94 //****************************************************************************** 95 Win32Resource::~Win32Resource() 96 { 97 Win32Resource *res = module->winres; 98 99 if(os2resdata && (resType == RSRC_PELOADER || resType == RSRC_CUSTOMINDIRECT)) 100 free(os2resdata); 101 102 if(winresdata) free(winresdata); 103 104 resmutex.enter(); 105 if(res == this) { 106 module->winres = res->next; 49 if(hInstance == 0 || hInstance == -1 || (WinExe && hInstance == WinExe->getInstanceHandle())) { 50 module = (Win32ImageBase *)WinExe; 107 51 } 108 52 else { 109 while(res->next != this) { 110 res = res->next; 111 } 112 if(res) 113 res->next = next; 53 module = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 114 54 } 115 resmutex.leave(); 116 } 117 //****************************************************************************** 118 //****************************************************************************** 119 PVOID Win32Resource::lockResource() 120 { 121 dprintf(("Win32Resource::lockResource %d %x\n", id, winresdata)); 55 resdata = (char *)LockResource(LoadResource(hInstance, hResource)); 56 ressize = SizeofResource(hInstance, hResource); 122 57 123 if(winresdata) 124 return(winresdata); 125 126 dprintf(("Win32Resource::lockResource: NO windows resource!")); 127 return NULL; 128 } 129 //****************************************************************************** 130 //****************************************************************************** 131 PVOID Win32Resource::lockOS2Resource() 132 { 133 APIRET rc; 134 PVOID resdata; 135 136 dprintf(("Win32Resource::lockOS2Resource %d\n", id)); 137 if(os2resdata == NULL) { 138 os2resdata = convertResource(winresdata); 139 } 140 return os2resdata; 141 } 142 //****************************************************************************** 143 //return size of converted win32 resource 144 //****************************************************************************** 145 ULONG Win32Resource::getOS2Size() 146 { 147 switch(type) { 58 switch((int)restype) { 148 59 case NTRT_NEWBITMAP: 149 60 case NTRT_BITMAP: 150 return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)winresdata,ressize);61 return ConvertBitmap((WINBITMAPINFOHEADER *)resdata, ressize, (PULONG)&cvtressize); 151 62 152 63 case NTRT_CURSOR: 153 return QueryConvertedCursorSize((CursorComponent *)winresdata, ressize); 64 return ConvertCursor((CursorComponent *)resdata, ressize, &cvtressize); 65 66 case NTRT_GROUP_CURSOR: 67 return ConvertCursorGroup((CursorHeader *)resdata, ressize, module); 68 69 case NTRT_GROUP_ICON: 70 return ConvertIconGroup((IconHeader *)resdata, ressize, module); 154 71 155 72 case NTRT_ICON: 156 return QueryConvertedIconSize((WINBITMAPINFOHEADER *)winresdata, ressize); 157 158 case NTRT_GROUP_ICON: 159 case NTRT_GROUP_CURSOR: 160 case NTRT_ACCELERATORS: 161 case NTRT_NEWMENU: 162 case NTRT_MENU: 163 case NTRT_NEWDIALOG: 164 case NTRT_DIALOG: 165 case NTRT_FONTDIR: 166 case NTRT_FONT: 167 case NTRT_MESSAGETABLE: 168 case NTRT_RCDATA: 169 case NTRT_VERSION: 170 case NTRT_STRING: 171 default: 172 dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", type)); 173 break; 174 } 175 return 0; 176 } 177 //****************************************************************************** 178 //****************************************************************************** 179 PVOID Win32Resource::convertResource(void *win32res) 180 { 181 int cvtressize; 182 183 switch(type) { 184 case NTRT_NEWBITMAP: 185 case NTRT_BITMAP: 186 return ConvertBitmap((WINBITMAPINFOHEADER *)win32res, ressize, &ressize); 187 188 case NTRT_CURSOR: 189 return ConvertCursor((CursorComponent *)win32res, ressize, &cvtressize); 190 191 case NTRT_GROUP_CURSOR: 192 return ConvertCursorGroup((CursorHeader *)win32res, ressize, module); 193 194 case NTRT_GROUP_ICON: 195 return ConvertIconGroup((IconHeader *)win32res, ressize, module); 196 197 case NTRT_ICON: 198 return ConvertIcon((WINBITMAPINFOHEADER *)win32res, ressize, &cvtressize); 73 return ConvertIcon((WINBITMAPINFOHEADER *)resdata, ressize, &cvtressize); 199 74 200 75 case NTRT_ACCELERATORS: 201 return ConvertAccelerator((WINACCEL *) win32res, ressize);76 return ConvertAccelerator((WINACCEL *)resdata, ressize); 202 77 203 78 case NTRT_NEWMENU: … … 216 91 break; 217 92 } 218 dprintf((" Win32Resource::convertResource: Can't convert resource %d (type %d)", id, type));93 dprintf(("ConvertResourceToOS2: Can't convert resource %x (inst %x)", hResource, hInstance)); 219 94 return 0; 220 95 } 221 96 //****************************************************************************** 222 97 //****************************************************************************** 223 void Win32Resource::destroyAll(Win32ImageBase *module)98 ULONG WIN32API QueryConvertedResourceSize(HINSTANCE hInstance, LPSTR restype, HRSRC hResource) 224 99 { 225 Win32Resource *res = module->winres, *next; 100 PIMAGE_RESOURCE_DATA_ENTRY pData = (PIMAGE_RESOURCE_DATA_ENTRY)hResource; 101 Win32ImageBase *module; 102 char *resdata; 103 int ressize, cvtressize; 226 104 227 while(res) { 228 next = res->next; 229 delete(res); 230 res = next; 231 } 105 if(hInstance == 0 || hInstance == -1 || (WinExe && hInstance == WinExe->getInstanceHandle())) { 106 module = (Win32ImageBase *)WinExe; 107 } 108 else { 109 module = (Win32ImageBase *)Win32DllBase::findModule(hInstance); 110 } 111 resdata = (char *)LockResource(LoadResource(hInstance, hResource)); 112 ressize = SizeofResource(hInstance, hResource); 113 114 switch((int)restype) { 115 case NTRT_NEWBITMAP: 116 case NTRT_BITMAP: 117 return QueryConvertedBitmapSize((WINBITMAPINFOHEADER *)resdata, ressize); 118 119 case NTRT_CURSOR: 120 return QueryConvertedCursorSize((CursorComponent *)resdata, ressize); 121 122 case NTRT_ICON: 123 return QueryConvertedIconSize((WINBITMAPINFOHEADER *)resdata, ressize); 124 125 case NTRT_GROUP_ICON: 126 case NTRT_GROUP_CURSOR: 127 case NTRT_ACCELERATORS: 128 case NTRT_NEWMENU: 129 case NTRT_MENU: 130 case NTRT_NEWDIALOG: 131 case NTRT_DIALOG: 132 case NTRT_FONTDIR: 133 case NTRT_FONT: 134 case NTRT_MESSAGETABLE: 135 case NTRT_RCDATA: 136 case NTRT_VERSION: 137 case NTRT_STRING: 138 default: 139 dprintf(("Win32Resource::getOS2Size SHOULDN'T BE CALLED for this resource type (%d) (NOT IMPLEMENTED)!!", restype)); 140 break; 141 } 142 return 0; 232 143 } 233 144 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.