2005-06-19 18:06:53 +00:00
|
|
|
#include <user32.h>
|
2001-06-18 03:05:54 +00:00
|
|
|
|
2015-11-27 22:49:47 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(resource);
|
2006-06-26 13:16:43 +00:00
|
|
|
|
2007-09-25 22:28:35 +00:00
|
|
|
#ifndef _CFGMGR32_H_
|
|
|
|
#define CR_SUCCESS 0x00000000
|
|
|
|
#define CR_OUT_OF_MEMORY 0x00000002
|
|
|
|
#define CR_INVALID_POINTER 0x00000003
|
|
|
|
#define CR_INVALID_DATA 0x0000001F
|
|
|
|
#endif
|
|
|
|
|
2008-11-30 11:42:05 +00:00
|
|
|
typedef DWORD (WINAPI *CMP_REGNOTIFY) (HANDLE, LPVOID, DWORD, PULONG);
|
|
|
|
typedef DWORD (WINAPI *CMP_UNREGNOTIFY) (ULONG );
|
2007-09-25 22:28:35 +00:00
|
|
|
|
2007-09-26 01:10:51 +00:00
|
|
|
static HINSTANCE hSetupApi = NULL;
|
|
|
|
|
2015-11-27 22:49:47 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* LoadStringW (USER32.@)
|
|
|
|
* Synced with Wine Staging 1.7.55
|
2003-07-10 21:04:32 +00:00
|
|
|
*/
|
2015-11-27 22:49:47 +00:00
|
|
|
INT WINAPI LoadStringW( HINSTANCE instance, UINT resource_id,
|
|
|
|
LPWSTR buffer, INT buflen )
|
2003-02-02 17:35:30 +00:00
|
|
|
{
|
2009-01-08 19:47:29 +00:00
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
WCHAR *p;
|
|
|
|
int string_num;
|
|
|
|
int i;
|
|
|
|
|
2015-11-27 22:49:47 +00:00
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
|
|
|
|
2009-01-08 19:47:29 +00:00
|
|
|
if(buffer == NULL)
|
2009-01-08 17:21:16 +00:00
|
|
|
return 0;
|
2007-05-28 00:35:55 +00:00
|
|
|
|
2009-01-08 19:47:29 +00:00
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
|
|
|
(LPWSTR)RT_STRING );
|
|
|
|
if (!hrsrc) return 0;
|
|
|
|
hmem = LoadResource( instance, hrsrc );
|
|
|
|
if (!hmem) return 0;
|
|
|
|
|
|
|
|
p = LockResource(hmem);
|
|
|
|
string_num = resource_id & 0x000f;
|
|
|
|
for (i = 0; i < string_num; i++)
|
2015-11-27 22:49:47 +00:00
|
|
|
p += *p + 1;
|
|
|
|
|
|
|
|
TRACE("strlen = %d\n", (int)*p );
|
2009-01-08 19:47:29 +00:00
|
|
|
|
|
|
|
/*if buflen == 0, then return a read-only pointer to the resource itself in buffer
|
|
|
|
it is assumed that buffer is actually a (LPWSTR *) */
|
|
|
|
if(buflen == 0)
|
2007-05-28 00:35:55 +00:00
|
|
|
{
|
2009-01-08 19:47:29 +00:00
|
|
|
*((LPWSTR *)buffer) = p + 1;
|
|
|
|
return *p;
|
2007-05-28 00:35:55 +00:00
|
|
|
}
|
|
|
|
|
2009-01-08 19:47:29 +00:00
|
|
|
i = min(buflen - 1, *p);
|
|
|
|
if (i > 0) {
|
2015-11-27 22:49:47 +00:00
|
|
|
memcpy(buffer, p + 1, i * sizeof (WCHAR));
|
2009-01-08 19:47:29 +00:00
|
|
|
buffer[i] = 0;
|
|
|
|
} else {
|
2015-11-27 22:49:47 +00:00
|
|
|
if (buflen > 1) {
|
2009-01-08 19:47:29 +00:00
|
|
|
buffer[0] = 0;
|
2015-11-27 22:49:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-08 17:21:16 +00:00
|
|
|
}
|
2009-01-08 19:47:29 +00:00
|
|
|
|
2015-11-27 22:49:47 +00:00
|
|
|
TRACE("%s loaded !\n", debugstr_w(buffer));
|
2009-01-08 19:47:29 +00:00
|
|
|
return i;
|
2003-02-02 17:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 22:49:47 +00:00
|
|
|
/**********************************************************************
|
|
|
|
* LoadStringA (USER32.@)
|
|
|
|
* Synced with Wine Staging 1.7.55
|
|
|
|
*/
|
|
|
|
INT WINAPI LoadStringA( HINSTANCE instance, UINT resource_id, LPSTR buffer, INT buflen )
|
|
|
|
{
|
|
|
|
HGLOBAL hmem;
|
|
|
|
HRSRC hrsrc;
|
|
|
|
DWORD retval = 0;
|
|
|
|
|
|
|
|
TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",
|
|
|
|
instance, resource_id, buffer, buflen);
|
|
|
|
|
|
|
|
if (!buflen) return -1;
|
|
|
|
|
|
|
|
/* Use loword (incremented by 1) as resourceid */
|
|
|
|
if ((hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
|
|
|
|
(LPWSTR)RT_STRING )) &&
|
|
|
|
(hmem = LoadResource( instance, hrsrc )))
|
|
|
|
{
|
|
|
|
const WCHAR *p = LockResource(hmem);
|
|
|
|
unsigned int id = resource_id & 0x000f;
|
|
|
|
|
|
|
|
while (id--) p += *p + 1;
|
|
|
|
|
|
|
|
if (buflen != 1)
|
|
|
|
RtlUnicodeToMultiByteN( buffer, buflen - 1, &retval, (PWSTR)(p + 1), *p * sizeof(WCHAR) );
|
|
|
|
}
|
|
|
|
buffer[retval] = 0;
|
|
|
|
TRACE("returning %s\n", debugstr_a(buffer));
|
|
|
|
return retval;
|
|
|
|
}
|
2007-09-25 22:28:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
HDEVNOTIFY
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2009-01-08 17:21:16 +00:00
|
|
|
RegisterDeviceNotificationW(HANDLE hRecipient,
|
|
|
|
LPVOID NotificationFilter,
|
|
|
|
DWORD Flags)
|
2007-09-25 22:28:35 +00:00
|
|
|
{
|
2009-01-08 17:21:16 +00:00
|
|
|
DWORD ConfigRet = 0;
|
|
|
|
CMP_REGNOTIFY RegNotify = NULL;
|
|
|
|
HDEVNOTIFY hDevNotify = NULL;
|
|
|
|
|
|
|
|
if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
|
|
|
|
if (hSetupApi == NULL) return NULL;
|
|
|
|
|
|
|
|
RegNotify = (CMP_REGNOTIFY) GetProcAddress(hSetupApi, "CMP_RegisterNotification");
|
|
|
|
if (RegNotify == NULL)
|
|
|
|
{
|
|
|
|
FreeLibrary(hSetupApi);
|
|
|
|
hSetupApi = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConfigRet = RegNotify(hRecipient, NotificationFilter, Flags, (PULONG) &hDevNotify);
|
|
|
|
if (ConfigRet != CR_SUCCESS)
|
2007-09-25 22:28:35 +00:00
|
|
|
{
|
2009-01-08 17:21:16 +00:00
|
|
|
switch (ConfigRet)
|
|
|
|
{
|
|
|
|
case CR_OUT_OF_MEMORY:
|
|
|
|
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CR_INVALID_POINTER:
|
|
|
|
SetLastError (ERROR_INVALID_PARAMETER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CR_INVALID_DATA:
|
|
|
|
SetLastError (ERROR_INVALID_DATA);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetLastError (ERROR_SERVICE_SPECIFIC_ERROR);
|
|
|
|
break;
|
|
|
|
}
|
2007-09-25 22:28:35 +00:00
|
|
|
}
|
2009-01-08 17:21:16 +00:00
|
|
|
|
|
|
|
return hDevNotify;
|
2007-09-25 22:28:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
2008-11-30 11:42:05 +00:00
|
|
|
WINAPI
|
2009-01-08 17:21:16 +00:00
|
|
|
UnregisterDeviceNotification(HDEVNOTIFY Handle)
|
2007-09-25 22:28:35 +00:00
|
|
|
{
|
2009-01-08 17:21:16 +00:00
|
|
|
DWORD ConfigRet = 0;
|
|
|
|
CMP_UNREGNOTIFY UnRegNotify = NULL;
|
|
|
|
|
|
|
|
if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
|
|
|
|
if (hSetupApi == NULL) return FALSE;
|
|
|
|
|
|
|
|
UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress(hSetupApi, "CMP_UnregisterNotification");
|
|
|
|
if (UnRegNotify == NULL)
|
2007-09-25 22:28:35 +00:00
|
|
|
{
|
2009-01-08 17:21:16 +00:00
|
|
|
FreeLibrary(hSetupApi);
|
|
|
|
hSetupApi = NULL;
|
|
|
|
return FALSE;
|
2007-09-25 22:28:35 +00:00
|
|
|
}
|
2009-01-08 17:21:16 +00:00
|
|
|
|
2010-06-27 22:19:17 +00:00
|
|
|
ConfigRet = UnRegNotify((ULONG_PTR)Handle );
|
2009-01-08 17:21:16 +00:00
|
|
|
if (ConfigRet != CR_SUCCESS)
|
|
|
|
{
|
|
|
|
switch (ConfigRet)
|
|
|
|
{
|
|
|
|
case CR_INVALID_POINTER:
|
|
|
|
SetLastError (ERROR_INVALID_PARAMETER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CR_INVALID_DATA:
|
|
|
|
SetLastError (ERROR_INVALID_DATA);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
SetLastError (ERROR_SERVICE_SPECIFIC_ERROR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2007-09-25 22:28:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 15:34:48 +00:00
|
|
|
/* EOF */
|