Fixed a bunch of compiler warnings.
[wine] / loader / libres.c
1 /*
2  * WINElib-Resources
3  *
4  * Copied and modified heavily from loader/resource.c
5  */
6
7 #include <stdlib.h>
8 #include "debug.h"
9 #include "libres.h"
10 #include "heap.h"
11 #include "windows.h"
12 #include "xmalloc.h"
13
14 typedef struct RLE
15 {
16     const wrc_resource32_t * const * Resources;  /* NULL-terminated array of pointers */
17     struct RLE* next;
18 } ResListE;
19
20 static ResListE* ResourceList=NULL;
21
22 void LIBRES_RegisterResources(const wrc_resource32_t * const * Res)
23 {
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;
31 }
32
33 /**********************************************************************
34  *          LIBRES_FindResource
35  */
36 HRSRC32 LIBRES_FindResource( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
37 {
38   int nameid=0,typeid;
39   ResListE* ResBlock;
40   const wrc_resource32_t* const * Res;
41
42   if(HIWORD(name))
43   {
44     if(*name=='#')
45     {
46         LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
47         nameid = atoi(nameA+1);
48         HeapFree( GetProcessHeap(), 0, nameA );
49         name=NULL;
50     }
51   }
52   else
53   {
54     nameid=LOWORD(name);
55     name=NULL;
56   }
57   if(HIWORD(type))
58   {
59     if(*type=='#')
60     {
61         LPSTR typeA = HEAP_strdupWtoA( GetProcessHeap(), 0, type );
62         typeid=atoi(typeA+1);
63         HeapFree( GetProcessHeap(), 0, typeA );
64     }
65     else
66     {
67       TRACE(resource, "(*,*,type=string): Returning 0\n");
68       return 0;
69     }
70   }
71   else
72     typeid=LOWORD(type);
73   
74   /* FIXME: types can be strings */
75   for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
76     for(Res=ResBlock->Resources; *Res; Res++)
77       if(name)
78       {
79         if((*Res)->restype==typeid && !lstrncmpi32W((LPCWSTR)((*Res)->resname+1), name, *((*Res)->resname)))
80           return (HRSRC32)*Res;
81       }
82       else
83         if((*Res)->restype==typeid && (*Res)->resid==nameid)
84           return (HRSRC32)*Res;
85   return 0;
86 }
87
88
89 /**********************************************************************
90  *          LIBRES_LoadResource    
91  */
92 HGLOBAL32 LIBRES_LoadResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
93 {
94   return (HGLOBAL32)(((wrc_resource32_t*)hRsrc)->data);
95 }
96
97
98 /**********************************************************************
99  *          LIBRES_SizeofResource    
100  */
101 DWORD LIBRES_SizeofResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
102 {
103   return (DWORD)(((wrc_resource32_t*)hRsrc)->datasize);
104 }