PRESLINK AllocResLink( PRES pRes) { PRESLINK prl; PRES pResNew; PRES2 pRes2; LPTSTR pszName; INT cbName; LPTSTR pszType; if (!(prl = (PRESLINK)MyAlloc(sizeof(RESLINK)))) return NULL; prl->prlNext = NULL; prl->cbRes = ResourceSize(pRes); if (!(prl->hRes = GlobalAlloc(GMEM_MOVEABLE, prl->cbRes))) { MyFree(prl); Message(MSG_OUTOFMEMORY); return NULL; } pResNew = (PRES)GlobalLock(prl->hRes); memcpy(pResNew, pRes, prl->cbRes); GlobalUnlock(prl->hRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == ORDID_RT_DIALOG) { prl->fDlgResource = TRUE; pszName = ResourceName(pRes); cbName = NameOrdLen(pszName); if (!(prl->pszName = MyAlloc(cbName))) { GlobalFree(prl->hRes); MyFree(prl); return NULL; } NameOrdCpy(prl->pszName, pszName); pRes2 = ResourcePart2(pRes); prl->wLanguage = pRes2->LanguageId; } else { prl->fDlgResource = FALSE; prl->pszName = NULL; prl->wLanguage = 0; } return prl; }
GetIndString(char *str, int id, short num) { struct StringTable **tp, *st = NULL; Handle h; tp = &StringTables; while (*tp) { if ((*tp)->id == id) { st = *tp; break; } tp = &((*tp)->next); } if (!st) { QUAD i, lines, size; char *buf; st = (struct StringTable *)ckalloc(sizeof (struct StringTable)); st->id = id; h = GetResource("stri", id); size = ResourceSize(h); buf = (char *)*h; for (i=0, lines=0; i<size; i++) if (buf[i] == '\n') { buf[i] = 0; lines++; } st->lines = lines; st->strings = (char **)ckalloc(size * sizeof(char *)); for (i=0; i<lines; i++) { st->strings[i] = buf; buf += strlen(buf) + 1; } st->next = StringTables; StringTables = st; } if ((num < 1) || (num > st->lines)) { fprintf(stderr, "Out of range string index: %d\n", num); strcpy(str, "Well I'll be a monkey's uncle!"); } { strcpy(str, st->strings[num-1]); } }
static HWND SearchResource(LPCSTR lpName, int type, DLGPROC pDialogProc, LPARAM param, char *lpFileBase, int TotalFileSize, HWND parentWnd) { char *pResAll = lpFileBase + TotalFileSize; PRES pRes = (PRES)lpFileBase; char pszSearchedName[256]; char *pszType = ResourceType(pRes); char *pszName; int size = ResourceSize(pRes); char Name[512],*bb; PDIALOGBOXHEADER pdbh; HWND result; UINT_PTR ul; ul = (UINT_PTR)lpName; if (HIWORD(ul) == 0) { sprintf(pszSearchedName,"%d",LOWORD(ul)); } else if (IsOrd((char *)lpName)) { sprintf(pszSearchedName,"%d",OrdID(lpName)); } else if (lpName[1] == 0 && lpName[3] == 0) { ConvertWideString((char *)lpName,(char *)pszSearchedName); } else { strcpy(pszSearchedName,lpName); } do { if (pRes->HeaderSize+pRes->DataSize == 0) break; if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) { /* Ignore include files */ ; } else if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_RESOURCE32) { /* * This is the dummy resource that identifies a * 32 bit resource file. This resource should be * skipped also. */ } else { /* This is some other kind of a resource. See if it matches */ if (pRes->DataSize) { int size = ResourceSize(pRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == type) { pszName = ResourceName(pRes); if (!IsOrd(pszName)) { if (pszName[1] == 0 && pszName[3] == 0) ConvertWideString(pszName,Name); else strcpy(Name,pszName); } else { sprintf(Name,"%d",OrdID(pszName)); } if (!strcmp(Name,pszSearchedName)) { /* found it.*/ if (type == 5) { /* Build a dialog box */ pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes); bb = malloc(size); memcpy(bb,pdbh,size); result = CreateDialogIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)bb, parentWnd, pDialogProc,param); free(bb); return result; } else if (type == 4) { /* Build a menu */ return (HWND) ReadMenu((char *)SkipResHeader(pRes)); } else if (type == 3) { /* Build an Icon */ HICON hicon; hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, TRUE, 0x30000); return (HWND)hicon; } else if (type == 1) { /* Build a cursor */ return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, FALSE, 0x30000); } else if (type == 2 || type == 14) { /* Build bitmap */ char *start = SkipResHeader(pRes); bb = malloc(size); memcpy(bb,start,size); return (HWND) bb; } } } } } /* Move to the next resource. */ pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize); DWordAlign((PBYTE *)&pRes); } while (pRes < (PRES) ((char *) pResAll + size)); return (HWND) 0; }