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