Release 951226
[wine/gsoc-2012-control.git] / library / libres.c
blob5f4c5b52c5b7aac6da962bc9d95398d0b732506e
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 "windows.h"
11 #include "xmalloc.h"
13 typedef struct RLE
15 const struct resource* const * Resources; /* NULL-terminated array of pointers */
16 struct RLE* next;
17 } ResListE;
19 static ResListE* ResourceList=NULL;
21 void LIBRES_RegisterResources(const struct resource* const * Res)
23 ResListE** Curr;
24 ResListE* n;
25 for(Curr=&ResourceList; *Curr; Curr=&((*Curr)->next)) { }
26 n=xmalloc(sizeof(ResListE));
27 n->Resources=Res;
28 n->next=NULL;
29 *Curr=n;
32 /**********************************************************************
33 * LIBRES_FindResource
35 HRSRC LIBRES_FindResource( HINSTANCE hModule, LPCSTR name, LPCSTR type )
37 int nameid=0,typeid;
38 ResListE* ResBlock;
39 const struct resource* const * Res;
41 if(HIWORD(name))
43 if(*name=='#')
45 nameid=atoi(name+1);
46 name=NULL;
49 else
51 nameid=LOWORD(name);
52 name=NULL;
54 if(HIWORD(type))
56 if(*type=='#')
57 typeid=atoi(type+1);
58 else
60 WINELIB_UNIMP("LIBRES_FindResource(*,*,type=string)");
61 return 0;
64 else
65 typeid=LOWORD(type);
67 for(ResBlock=ResourceList; ResBlock; ResBlock=ResBlock->next)
68 for(Res=ResBlock->Resources; *Res; Res++)
69 if(name)
71 if((*Res)->type==typeid && !strcmp((*Res)->name,name))
72 return (HRSRC)*Res;
74 else
75 if((*Res)->type==typeid && (*Res)->id==nameid)
76 return (HRSRC)*Res;
77 return 0;
81 /**********************************************************************
82 * LIBRES_LoadResource
84 HGLOBAL LIBRES_LoadResource( HINSTANCE hModule, HRSRC hRsrc )
86 return (HGLOBAL)(((struct resource*)hRsrc)->bytes);
90 /**********************************************************************
91 * LIBRES_LockResource
93 LPVOID LIBRES_LockResource( HGLOBAL handle )
95 return handle;
99 /**********************************************************************
100 * LIBRES_FreeResource
102 BOOL LIBRES_FreeResource( HGLOBAL handle )
104 WINELIB_UNIMP("LIBRES_FreeResource()");
105 return 0; /* Obsolete in Win32 */
109 /**********************************************************************
110 * LIBRES_AccessResource
112 INT LIBRES_AccessResource( HINSTANCE hModule, HRSRC hRsrc )
114 WINELIB_UNIMP("LIBRES_AccessResource()");
115 return -1; /* Obsolete in Win32 */
119 /**********************************************************************
120 * LIBRES_SizeofResource
122 DWORD LIBRES_SizeofResource( HINSTANCE hModule, HRSRC hRsrc )
124 return (DWORD)(((struct resource*)hRsrc)->size);
128 /**********************************************************************
129 * LIBRES_AllocResource
131 HGLOBAL LIBRES_AllocResource( HINSTANCE hModule, HRSRC hRsrc, DWORD size )
133 WINELIB_UNIMP("LIBRES_AllocResource()");
134 return 0; /* Obsolete in Win32 */