Release 961222
[wine/multimedia.git] / library / libres.c
blobebe155d69b8de290564cb1787f4e781dbde86915
1 /*
2 * WINElib-Resources
4 * Copied and modified heavily from loader/resource.c
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "libres.h"
10 #include "heap.h"
11 #include "windows.h"
12 #include "xmalloc.h"
14 typedef struct RLE
16 const struct resource* const * Resources; /* NULL-terminated array of pointers */
17 struct RLE* next;
18 } ResListE;
20 static ResListE* ResourceList=NULL;
22 void LIBRES_RegisterResources(const struct resource* 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_FindResource16
36 HRSRC32 LIBRES_FindResource16( HINSTANCE32 hModule, LPCSTR name, LPCSTR type )
38 int nameid=0,typeid;
39 ResListE* ResBlock;
40 const struct resource* const * Res;
42 if(HIWORD(name))
44 if(*name=='#')
46 nameid=atoi(name+1);
47 name=NULL;
50 else
52 nameid=LOWORD(name);
53 name=NULL;
55 if(HIWORD(type))
57 if(*type=='#')
58 typeid=atoi(type+1);
59 else
61 WINELIB_UNIMP("LIBRES_FindResource16(*,*,type=string)");
62 return 0;
65 else
66 typeid=LOWORD(type);
68 for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
69 for(Res=ResBlock->Resources; *Res; Res++)
70 if(name)
72 if((*Res)->type==typeid && !lstrcmpi32A((*Res)->name,name))
73 return (HRSRC32)*Res;
75 else
76 if((*Res)->type==typeid && (*Res)->id==nameid)
77 return (HRSRC32)*Res;
78 return 0;
81 /**********************************************************************
82 * LIBRES_FindResource32
84 HRSRC32 LIBRES_FindResource32( HINSTANCE32 hModule, LPCWSTR name, LPCWSTR type )
86 int nameid=0,typeid;
87 ResListE* ResBlock;
88 const struct resource* const * Res;
90 if(HIWORD(name))
92 if(*name=='#')
94 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
95 nameid = atoi(nameA+1);
96 HeapFree( GetProcessHeap(), 0, nameA );
97 name=NULL;
100 else
102 nameid=LOWORD(name);
103 name=NULL;
105 if(HIWORD(type))
107 if(*type=='#')
109 LPSTR typeA = HEAP_strdupWtoA( GetProcessHeap(), 0, type );
110 typeid=atoi(typeA+1);
111 HeapFree( GetProcessHeap(), 0, typeA );
113 else
115 WINELIB_UNIMP("LIBRES_FindResource32(*,*,type=string)");
116 return 0;
119 else
120 typeid=LOWORD(type);
122 for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
123 for(Res=ResBlock->Resources; *Res; Res++)
124 if(name)
126 if((*Res)->type==typeid && !lstrcmpi32W((*Res)->name,name))
127 return (HRSRC32)*Res;
129 else
130 if((*Res)->type==typeid && (*Res)->id==nameid)
131 return (HRSRC32)*Res;
132 return 0;
136 /**********************************************************************
137 * LIBRES_LoadResource
139 HGLOBAL32 LIBRES_LoadResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
141 return (HGLOBAL32)(((struct resource*)hRsrc)->bytes);
145 /**********************************************************************
146 * LIBRES_LockResource
148 LPVOID LIBRES_LockResource( HGLOBAL32 handle )
150 return (LPVOID)handle;
154 /**********************************************************************
155 * LIBRES_FreeResource
157 BOOL LIBRES_FreeResource( HGLOBAL32 handle )
159 return 0; /* Obsolete in Win32 */
163 /**********************************************************************
164 * LIBRES_AccessResource
166 INT32 LIBRES_AccessResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
168 WINELIB_UNIMP("LIBRES_AccessResource()");
169 return -1; /* Obsolete in Win32 */
173 /**********************************************************************
174 * LIBRES_SizeofResource
176 DWORD LIBRES_SizeofResource( HINSTANCE32 hModule, HRSRC32 hRsrc )
178 return (DWORD)(((struct resource*)hRsrc)->size);
182 /**********************************************************************
183 * LIBRES_AllocResource
185 HGLOBAL32 LIBRES_AllocResource( HINSTANCE32 hModule, HRSRC32 hRsrc, DWORD size)
187 WINELIB_UNIMP("LIBRES_AllocResource()");
188 return 0; /* Obsolete in Win32 */