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