Bugfix: memory overwrite bug.
[wine/multimedia.git] / loader / libres.c
blob3579b0a7434f5445bfe47c5b3ec9f68c53295b95
1 /*
2 * WINElib-Resources
4 * Copied and modified heavily from loader/resource.c
5 */
7 #include <stdlib.h>
8 #include "debug.h"
9 #include "libres.h"
10 #include "heap.h"
11 #include "windows.h"
12 #include "xmalloc.h"
14 typedef struct RLE
16 const wrc_resource32_t * const * Resources; /* NULL-terminated array of pointers */
17 struct RLE* next;
18 } ResListE;
20 static ResListE* ResourceList=NULL;
22 void LIBRES_RegisterResources(const wrc_resource32_t * const * Res)
24 ResListE** Curr;
25 ResListE* n;
26 for(Curr=&ResourceList; *Curr; Curr=&((*Curr)->next)) { }
27 n=xmalloc(sizeof(ResListE));
28 n->Resources=Res;
29 n->next=NULL;
30 *Curr=n;
33 /**********************************************************************
34 * LIBRES_FindResource
36 HRSRC32 LIBRES_FindResource( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
38 int nameid=0,typeid;
39 ResListE* ResBlock;
40 const wrc_resource32_t* const * Res;
42 if(HIWORD(name))
44 if(*name=='#')
46 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
47 nameid = atoi(nameA+1);
48 HeapFree( GetProcessHeap(), 0, nameA );
49 name=NULL;
52 else
54 nameid=LOWORD(name);
55 name=NULL;
57 if(HIWORD(type))
59 if(*type=='#')
61 LPSTR typeA = HEAP_strdupWtoA( GetProcessHeap(), 0, type );
62 typeid=atoi(typeA+1);
63 HeapFree( GetProcessHeap(), 0, typeA );
65 else
67 TRACE(resource, "(*,*,type=string): Returning 0\n");
68 return 0;
71 else
72 typeid=LOWORD(type);
74 /* FIXME: types can be strings */
75 for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
76 for(Res=ResBlock->Resources; *Res; Res++)
77 if(name)
79 if((*Res)->restype==typeid && !lstrncmpi32W((LPCWSTR)((*Res)->resname+1), name, *((*Res)->resname)))
80 return (HRSRC32)*Res;
82 else
83 if((*Res)->restype==typeid && (*Res)->resid==nameid)
84 return (HRSRC32)*Res;
85 return 0;
89 /**********************************************************************
90 * LIBRES_LoadResource
92 HGLOBAL32 LIBRES_LoadResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
94 return (HGLOBAL32)(((wrc_resource32_t*)hRsrc)->data);
98 /**********************************************************************
99 * LIBRES_SizeofResource
101 DWORD LIBRES_SizeofResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
103 return (DWORD)(((wrc_resource32_t*)hRsrc)->datasize);