ReactOS 0.4.17-dev-1343-g8fe3cee
resources.c File Reference
#include <user32.h>
Include dependency graph for resources.c:

Go to the source code of this file.

Macros

#define CR_SUCCESS   0x00000000
 
#define CR_OUT_OF_MEMORY   0x00000002
 
#define CR_INVALID_POINTER   0x00000003
 
#define CR_INVALID_DATA   0x0000001F
 

Typedefs

typedef DWORD(WINAPI * CMP_REGNOTIFY) (HANDLE, LPVOID, DWORD, PHDEVNOTIFY)
 
typedef DWORD(WINAPI * CMP_UNREGNOTIFY) (HDEVNOTIFY)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (resource)
 
INT WINAPI DECLSPEC_HOTPATCH LoadStringW (HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
 
INT WINAPI DECLSPEC_HOTPATCH LoadStringA (HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen)
 
HDEVNOTIFY WINAPI RegisterDeviceNotificationW (HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags)
 
BOOL WINAPI UnregisterDeviceNotification (HDEVNOTIFY Handle)
 

Variables

static HINSTANCE hSetupApi = NULL
 

Macro Definition Documentation

◆ CR_INVALID_DATA

#define CR_INVALID_DATA   0x0000001F

Definition at line 9 of file resources.c.

◆ CR_INVALID_POINTER

#define CR_INVALID_POINTER   0x00000003

Definition at line 8 of file resources.c.

◆ CR_OUT_OF_MEMORY

#define CR_OUT_OF_MEMORY   0x00000002

Definition at line 7 of file resources.c.

◆ CR_SUCCESS

#define CR_SUCCESS   0x00000000

Definition at line 6 of file resources.c.

Typedef Documentation

◆ CMP_REGNOTIFY

typedef DWORD(WINAPI * CMP_REGNOTIFY) (HANDLE, LPVOID, DWORD, PHDEVNOTIFY)

Definition at line 12 of file resources.c.

◆ CMP_UNREGNOTIFY

typedef DWORD(WINAPI * CMP_UNREGNOTIFY) (HDEVNOTIFY)

Definition at line 13 of file resources.c.

Function Documentation

◆ LoadStringA()

INT WINAPI DECLSPEC_HOTPATCH LoadStringA ( HINSTANCE  instance,
UINT  resource_id,
LPSTR  buffer,
INT  buflen 
)

Definition at line 71 of file resources.c.

72{
73 HGLOBAL hmem;
74 HRSRC hrsrc;
75 DWORD retval = 0;
76
77 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
78 instance, resource_id, buffer, buflen);
79
80 if (!buflen) return -1;
81
82 /* Use loword (incremented by 1) as resourceid */
83 if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
84 (LPWSTR)RT_STRING )) &&
85 (hmem = LoadResource( instance, hrsrc )))
86 {
87 const WCHAR *p = LockResource(hmem);
88 unsigned int id = resource_id & 0x000f;
89
90 while (id--) p += *p + 1;
91
92 RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, p + 1, *p * sizeof(WCHAR) );
93 }
94 buffer[retval] = 0;
95 TRACE("returning %s\n", debugstr_a(buffer));
96 return retval;
97}
static HINSTANCE instance
Definition: main.c:35
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint buffer
Definition: glext.h:5915
GLfloat GLfloat p
Definition: glext.h:8902
#define debugstr_a
Definition: kernel32.h:31
_Use_decl_annotations_ NTSTATUS NTAPI RtlUnicodeToMultiByteN(_Out_ PCHAR MbString, _In_ ULONG MbSize, _Out_opt_ PULONG ResultSize, _In_ PCWCH UnicodeString, _In_ ULONG UnicodeSize)
Definition: nlsboot.c:108
#define LOWORD(l)
Definition: pedump.c:82
#define RT_STRING
Definition: pedump.c:368
short WCHAR
Definition: pedump.c:58
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define TRACE(s)
Definition: solgame.cpp:4
uint16_t * LPWSTR
Definition: typedefs.h:56
int retval
Definition: wcstombs.cpp:91

◆ LoadStringW()

INT WINAPI DECLSPEC_HOTPATCH LoadStringW ( HINSTANCE  instance,
UINT  resource_id,
LPWSTR  buffer,
INT  buflen 
)

Definition at line 21 of file resources.c.

23{
24 HGLOBAL hmem;
25 HRSRC hrsrc;
26 WCHAR *p;
27 int string_num;
28 int i;
29
30 TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
31 instance, resource_id, buffer, buflen);
32
33 if(buffer == NULL)
34 return 0;
35
36 if (!(hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING )) ||
37 !(hmem = LoadResource( instance, hrsrc )))
38 {
39 TRACE( "Failed to load string.\n" );
40 if (buflen > 0) buffer[0] = 0;
41 return 0;
42 }
43
44 p = LockResource(hmem);
45 string_num = resource_id & 0x000f;
46 for (i = 0; i < string_num; i++)
47 p += *p + 1;
48
49 TRACE("strlen = %d\n", (int)*p );
50
51 /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
52 it is assumed that buffer is actually a (LPWSTR *) */
53 if(buflen == 0)
54 {
55 *((LPWSTR *)buffer) = p + 1;
56 return *p;
57 }
58
59 i = min(buflen - 1, *p);
60 memcpy(buffer, p + 1, i * sizeof(WCHAR));
61 buffer[i] = 0;
62
63 TRACE("returning %s\n", debugstr_w(buffer));
64 return i;
65}
#define NULL
Definition: types.h:112
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55

◆ RegisterDeviceNotificationW()

HDEVNOTIFY WINAPI RegisterDeviceNotificationW ( HANDLE  hRecipient,
LPVOID  NotificationFilter,
DWORD  Flags 
)

Definition at line 104 of file resources.c.

107{
108 DWORD ConfigRet = 0;
109 CMP_REGNOTIFY RegNotify = NULL;
110 HDEVNOTIFY hDevNotify = NULL;
111
112 if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
113 if (hSetupApi == NULL) return NULL;
114
115 RegNotify = (CMP_REGNOTIFY) GetProcAddress(hSetupApi, "CMP_RegisterNotification");
116 if (RegNotify == NULL)
117 {
119 hSetupApi = NULL;
120 return NULL;
121 }
122
123 ConfigRet = RegNotify(hRecipient, NotificationFilter, Flags, &hDevNotify);
124 if (ConfigRet != CR_SUCCESS)
125 {
126 switch (ConfigRet)
127 {
128 case CR_OUT_OF_MEMORY:
130 break;
131
134 break;
135
136 case CR_INVALID_DATA:
138 break;
139
140 default:
142 break;
143 }
144 }
145
146 return hDevNotify;
147}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define CR_INVALID_DATA
Definition: resources.c:9
#define CR_OUT_OF_MEMORY
Definition: resources.c:7
static HINSTANCE hSetupApi
Definition: resources.c:15
#define CR_INVALID_POINTER
Definition: resources.c:8
#define CR_SUCCESS
Definition: resources.c:6
DWORD(WINAPI * CMP_REGNOTIFY)(HANDLE, LPVOID, DWORD, PHDEVNOTIFY)
Definition: resources.c:12
#define ERROR_SERVICE_SPECIFIC_ERROR
Definition: winerror.h:941
#define ERROR_INVALID_DATA
Definition: winerror.h:238

Referenced by RegisterForDeviceNotifications().

◆ UnregisterDeviceNotification()

BOOL WINAPI UnregisterDeviceNotification ( HDEVNOTIFY  Handle)

Definition at line 155 of file resources.c.

156{
157 DWORD ConfigRet = 0;
158 CMP_UNREGNOTIFY UnRegNotify = NULL;
159
160 if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
161 if (hSetupApi == NULL) return FALSE;
162
163 UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress(hSetupApi, "CMP_UnregisterNotification");
164 if (UnRegNotify == NULL)
165 {
167 hSetupApi = NULL;
168 return FALSE;
169 }
170
171 ConfigRet = UnRegNotify(Handle);
172 if (ConfigRet != CR_SUCCESS)
173 {
174 switch (ConfigRet)
175 {
178 break;
179
180 case CR_INVALID_DATA:
182 break;
183
184 default:
186 break;
187 }
188 return FALSE;
189 }
190
191 return TRUE;
192}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ULONG Handle
Definition: gdb_input.c:15
DWORD(WINAPI * CMP_UNREGNOTIFY)(HDEVNOTIFY)
Definition: resources.c:13

Referenced by test_UnregisterDeviceNotification(), and UnregisterDeviceNotifications().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( resource  )

Variable Documentation

◆ hSetupApi

HINSTANCE hSetupApi = NULL
static

Definition at line 15 of file resources.c.

Referenced by RegisterDeviceNotificationW(), and UnregisterDeviceNotification().