Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * WINElib-Resources |
| 3 | * |
| 4 | * Copied and modified heavily from loader/resource.c |
| 5 | */ |
| 6 | |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 7 | #include <stdlib.h> |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 8 | #include "wine/winestring.h" |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 9 | #include "libres.h" |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 10 | #include "resource.h" |
Alexandre Julliard | a099a55 | 1999-06-12 15:45:58 +0000 | [diff] [blame] | 11 | #include "debugtools.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 12 | #include "heap.h" |
Alexandre Julliard | 89f079b | 1999-08-08 18:54:47 +0000 | [diff] [blame] | 13 | #include "crtdll.h" |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 14 | #include "xmalloc.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 15 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 16 | DEFAULT_DEBUG_CHANNEL(resource) |
| 17 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 18 | typedef struct RLE |
| 19 | { |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 20 | const wrc_resource32_t * const * Resources; /* NULL-terminated array of pointers */ |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 21 | struct RLE* next; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 22 | } ResListE; |
| 23 | |
| 24 | static ResListE* ResourceList=NULL; |
| 25 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 26 | void LIBRES_RegisterResources(const wrc_resource32_t * const * Res) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 27 | { |
| 28 | ResListE** Curr; |
| 29 | ResListE* n; |
| 30 | for(Curr=&ResourceList; *Curr; Curr=&((*Curr)->next)) { } |
Alexandre Julliard | d471965 | 1995-12-12 18:49:11 +0000 | [diff] [blame] | 31 | n=xmalloc(sizeof(ResListE)); |
Alexandre Julliard | d7d4fdf | 1995-12-26 15:05:24 +0000 | [diff] [blame] | 32 | n->Resources=Res; |
| 33 | n->next=NULL; |
| 34 | *Curr=n; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /********************************************************************** |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 38 | * LIBRES_FindResource |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 39 | */ |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 40 | typedef int (*CmpFunc_t)(LPCWSTR a, LPCWSTR b, int c); |
| 41 | |
| 42 | int CompareOrdinal(LPCWSTR ordinal, LPCWSTR resstr, int resid) |
| 43 | { |
| 44 | return !resstr && (resid == LOWORD(ordinal)); |
| 45 | } |
| 46 | |
| 47 | int CompareName(LPCWSTR name, LPCWSTR resstr, int resid) |
| 48 | { |
| 49 | return resstr && !CRTDLL__wcsnicmp(resstr+1, name, *(resstr)); |
| 50 | } |
| 51 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 52 | HRSRC LIBRES_FindResource( HINSTANCE hModule, LPCWSTR name, LPCWSTR type ) |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 53 | { |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 54 | LPCWSTR nameid = name, typeid = type; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 55 | ResListE* ResBlock; |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 56 | const wrc_resource32_t* const * Res; |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 57 | CmpFunc_t EqualNames = CompareOrdinal; |
| 58 | CmpFunc_t EqualTypes = CompareOrdinal; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 59 | |
| 60 | if(HIWORD(name)) |
| 61 | { |
| 62 | if(*name=='#') |
| 63 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 64 | LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name ); |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 65 | nameid = (LPCWSTR) atoi(nameA+1); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 66 | HeapFree( GetProcessHeap(), 0, nameA ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 67 | } |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 68 | else |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 69 | EqualNames = CompareName; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 70 | } |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 71 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 72 | if(HIWORD(type)) |
| 73 | { |
| 74 | if(*type=='#') |
| 75 | { |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 76 | LPSTR typeA = HEAP_strdupWtoA( GetProcessHeap(), 0, type ); |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 77 | typeid= (LPCWSTR) atoi(typeA+1); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 78 | HeapFree( GetProcessHeap(), 0, typeA ); |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 79 | } |
| 80 | else |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 81 | EqualTypes = CompareName; |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 82 | } |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 83 | |
| 84 | for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next) |
| 85 | for(Res=ResBlock->Resources; *Res; Res++) |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 86 | if (EqualNames(nameid, (*Res)->resname, (*Res)->resid) && |
| 87 | EqualTypes(typeid, (*Res)->restypename, (*Res)->restype)) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 88 | return (HRSRC)*Res; |
Ulrich Czekalla | e91d976 | 1999-09-27 13:31:47 +0000 | [diff] [blame] | 89 | |
Alexandre Julliard | 75d86e1 | 1996-11-17 18:59:11 +0000 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 93 | |
| 94 | /********************************************************************** |
| 95 | * LIBRES_LoadResource |
| 96 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 97 | HGLOBAL LIBRES_LoadResource( HINSTANCE hModule, HRSRC hRsrc ) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 98 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 99 | return (HGLOBAL)(((wrc_resource32_t*)hRsrc)->data); |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | |
| 103 | /********************************************************************** |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 104 | * LIBRES_SizeofResource |
| 105 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 106 | DWORD LIBRES_SizeofResource( HINSTANCE hModule, HRSRC hRsrc ) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 107 | { |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 108 | return (DWORD)(((wrc_resource32_t*)hRsrc)->datasize); |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 109 | } |