ReactOS  0.4.14-dev-115-g4576127
resources.c
Go to the documentation of this file.
1 #include <user32.h>
2 
4 
5 #ifndef _CFGMGR32_H_
6 #define CR_SUCCESS 0x00000000
7 #define CR_OUT_OF_MEMORY 0x00000002
8 #define CR_INVALID_POINTER 0x00000003
9 #define CR_INVALID_DATA 0x0000001F
10 #endif
11 
14 
16 
17 /**********************************************************************
18  * LoadStringW (USER32.@)
19  * Synced with Wine Staging 1.7.55
20  */
22  LPWSTR buffer, INT buflen )
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  /* Use loword (incremented by 1) as resourceid */
37  hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
38  (LPWSTR)RT_STRING );
39  if (!hrsrc) return 0;
40  hmem = LoadResource( instance, hrsrc );
41  if (!hmem) return 0;
42 
43  p = LockResource(hmem);
44  string_num = resource_id & 0x000f;
45  for (i = 0; i < string_num; i++)
46  p += *p + 1;
47 
48  TRACE("strlen = %d\n", (int)*p );
49 
50  /*if buflen == 0, then return a read-only pointer to the resource itself in buffer
51  it is assumed that buffer is actually a (LPWSTR *) */
52  if(buflen == 0)
53  {
54  *((LPWSTR *)buffer) = p + 1;
55  return *p;
56  }
57 
58  i = min(buflen - 1, *p);
59  if (i > 0) {
60  memcpy(buffer, p + 1, i * sizeof (WCHAR));
61  buffer[i] = 0;
62  } else {
63  if (buflen > 1) {
64  buffer[0] = 0;
65  return 0;
66  }
67  }
68 
69  TRACE("%s loaded !\n", debugstr_w(buffer));
70  return i;
71 }
72 
73 /**********************************************************************
74  * LoadStringA (USER32.@)
75  * Synced with Wine Staging 1.7.55
76  */
78 {
79  HGLOBAL hmem;
80  HRSRC hrsrc;
81  DWORD retval = 0;
82 
83  TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
84  instance, resource_id, buffer, buflen);
85 
86  if (!buflen) return -1;
87 
88  /* Use loword (incremented by 1) as resourceid */
89  if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
90  (LPWSTR)RT_STRING )) &&
91  (hmem = LoadResource( instance, hrsrc )))
92  {
93  const WCHAR *p = LockResource(hmem);
94  unsigned int id = resource_id & 0x000f;
95 
96  while (id--) p += *p + 1;
97 
98  if (buflen != 1)
99  RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, (PWSTR)(p + 1), *p * sizeof(WCHAR) );
100  }
101  buffer[retval] = 0;
102  TRACE("returning %s\n", debugstr_a(buffer));
103  return retval;
104 }
105 
106 /*
107  * @implemented
108  */
109 HDEVNOTIFY
110 WINAPI
112  LPVOID NotificationFilter,
113  DWORD Flags)
114 {
115  DWORD ConfigRet = 0;
116  CMP_REGNOTIFY RegNotify = NULL;
117  HDEVNOTIFY hDevNotify = NULL;
118 
119  if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
120  if (hSetupApi == NULL) return NULL;
121 
122  RegNotify = (CMP_REGNOTIFY) GetProcAddress(hSetupApi, "CMP_RegisterNotification");
123  if (RegNotify == NULL)
124  {
126  hSetupApi = NULL;
127  return NULL;
128  }
129 
130  ConfigRet = RegNotify(hRecipient, NotificationFilter, Flags, (PULONG) &hDevNotify);
131  if (ConfigRet != CR_SUCCESS)
132  {
133  switch (ConfigRet)
134  {
135  case CR_OUT_OF_MEMORY:
137  break;
138 
139  case CR_INVALID_POINTER:
141  break;
142 
143  case CR_INVALID_DATA:
145  break;
146 
147  default:
149  break;
150  }
151  }
152 
153  return hDevNotify;
154 }
155 
156 
157 /*
158  * @implemented
159  */
160 BOOL
161 WINAPI
163 {
164  DWORD ConfigRet = 0;
165  CMP_UNREGNOTIFY UnRegNotify = NULL;
166 
167  if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
168  if (hSetupApi == NULL) return FALSE;
169 
170  UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress(hSetupApi, "CMP_UnregisterNotification");
171  if (UnRegNotify == NULL)
172  {
174  hSetupApi = NULL;
175  return FALSE;
176  }
177 
178  ConfigRet = UnRegNotify((ULONG_PTR)Handle );
179  if (ConfigRet != CR_SUCCESS)
180  {
181  switch (ConfigRet)
182  {
183  case CR_INVALID_POINTER:
185  break;
186 
187  case CR_INVALID_DATA:
189  break;
190 
191  default:
193  break;
194  }
195  return FALSE;
196  }
197 
198  return TRUE;
199 }
200 
201 /* EOF */
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CR_INVALID_DATA
Definition: resources.c:9
#define TRUE
Definition: types.h:120
static HINSTANCE hSetupApi
Definition: resources.c:15
uint16_t * PWSTR
Definition: typedefs.h:54
#define ERROR_SERVICE_SPECIFIC_ERROR
Definition: winerror.h:617
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
INT WINAPI LoadStringA(HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen)
Definition: resources.c:77
LPVOID WINAPI LockResource(HGLOBAL handle)
Definition: res.c:550
GLuint buffer
Definition: glext.h:5915
char * LPSTR
Definition: xmlstorage.h:182
#define DWORD
Definition: nt_native.h:44
int32_t INT
Definition: typedefs.h:56
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
INT WINAPI LoadStringW(HINSTANCE instance, UINT resource_id, LPWSTR buffer, INT buflen)
Definition: resources.c:21
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define CR_OUT_OF_MEMORY
Definition: resources.c:7
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
unsigned int BOOL
Definition: ntddk_ex.h:94
#define debugstr_w
Definition: kernel32.h:32
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
smooth NULL
Definition: ftsmooth.c:416
DWORD(WINAPI * CMP_UNREGNOTIFY)(ULONG)
Definition: resources.c:13
BOOL WINAPI UnregisterDeviceNotification(HDEVNOTIFY Handle)
Definition: resources.c:162
_In_ HANDLE Handle
Definition: extypes.h:390
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:405
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define debugstr_a
Definition: kernel32.h:31
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID HANDLE
Definition: typedefs.h:71
#define SetLastError(x)
Definition: compat.h:409
#define LPVOID
Definition: nt_native.h:45
NTSYSAPI NTSTATUS NTAPI RtlUnicodeToMultiByteN(PCHAR MbString, ULONG MbSize, PULONG ResultSize, PCWCH UnicodeString, ULONG UnicodeSize)
WINE_DEFAULT_DEBUG_CHANNEL(resource)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define RT_STRING
Definition: pedump.c:368
#define CR_SUCCESS
Definition: resources.c:6
#define ERROR_INVALID_DATA
Definition: winerror.h:116
HDEVNOTIFY WINAPI RegisterDeviceNotificationW(HANDLE hRecipient, LPVOID NotificationFilter, DWORD Flags)
Definition: resources.c:111
#define CR_INVALID_POINTER
Definition: resources.c:8
static HINSTANCE instance
Definition: main.c:40
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
unsigned int ULONG
Definition: retypes.h:1
#define GetProcAddress(x, y)
Definition: compat.h:410
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
DWORD(WINAPI * CMP_REGNOTIFY)(HANDLE, LPVOID, DWORD, PULONG)
Definition: resources.c:12
#define LOWORD(l)
Definition: pedump.c:82