- Formatting fix. No code change

svn path=/trunk/; revision=38646
This commit is contained in:
Dmitry Chapyshev 2009-01-08 17:21:16 +00:00
parent 8560b3bcc3
commit 174b42a736

View file

@ -20,12 +20,11 @@ typedef DWORD (WINAPI *CMP_UNREGNOTIFY) (ULONG );
static HINSTANCE hSetupApi = NULL; static HINSTANCE hSetupApi = NULL;
BOOL WINAPI _InternalLoadString BOOL
( WINAPI
HINSTANCE hInstance, _InternalLoadString(HINSTANCE hInstance,
UINT uID, UINT uID,
PUNICODE_STRING pwstrDest PUNICODE_STRING pwstrDest)
)
{ {
HRSRC hrsStringTable; HRSRC hrsStringTable;
HGLOBAL hResource; HGLOBAL hResource;
@ -34,7 +33,7 @@ BOOL WINAPI _InternalLoadString
unsigned l = uID % 16; /* (1) */ unsigned l = uID % 16; /* (1) */
/* parameter validation */ /* parameter validation */
if(IsBadWritePtr(pwstrDest, sizeof(UNICODE_STRING))) if (IsBadWritePtr(pwstrDest, sizeof(UNICODE_STRING)))
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
@ -47,27 +46,24 @@ BOOL WINAPI _InternalLoadString
(actual resource ids) start from 1. See (1) and (2) (actual resource ids) start from 1. See (1) and (2)
*/ */
/* TODO: some sort of cache, here, would be great */ /* TODO: some sort of cache, here, would be great */
hrsStringTable = FindResourceW hrsStringTable = FindResourceW((HMODULE)hInstance,
(
(HMODULE)hInstance,
MAKEINTRESOURCEW((uID / 16) + 1), /* (2) */ MAKEINTRESOURCEW((uID / 16) + 1), /* (2) */
RT_STRING RT_STRING);
);
/* failure */ /* failure */
if(hrsStringTable == NULL) return FALSE; if (hrsStringTable == NULL) return FALSE;
/* load the string table into memory */ /* load the string table into memory */
hResource = LoadResource((HMODULE)hInstance, hrsStringTable); hResource = LoadResource((HMODULE)hInstance, hrsStringTable);
/* failure */ /* failure */
if(hResource == NULL) return FALSE; if (hResource == NULL) return FALSE;
/* lock the resource into memory */ /* lock the resource into memory */
pStringTable = LockResource(hResource); pStringTable = LockResource(hResource);
/* failure */ /* failure */
if(pStringTable == NULL) return FALSE; if (pStringTable == NULL) return FALSE;
/* /*
string tables are packed Unicode Pascal strings. The first WCHAR contains the string tables are packed Unicode Pascal strings. The first WCHAR contains the
@ -82,7 +78,7 @@ BOOL WINAPI _InternalLoadString
} }
/* we've reached the string of interest */ /* we've reached the string of interest */
if((*pStringTable) == 0) if ((*pStringTable) == 0)
{ {
/* the string is empty (unallocated) */ /* the string is empty (unallocated) */
SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND); SetLastError(ERROR_RESOURCE_NAME_NOT_FOUND);
@ -103,13 +99,12 @@ BOOL WINAPI _InternalLoadString
/* /*
* @implemented * @implemented
*/ */
int WINAPI LoadStringA int
( WINAPI
HINSTANCE hInstance, LoadStringA(HINSTANCE hInstance,
UINT uID, UINT uID,
LPSTR lpBuffer, LPSTR lpBuffer,
int nBufferMax int nBufferMax)
)
{ {
UNICODE_STRING wstrResStr; UNICODE_STRING wstrResStr;
ANSI_STRING strBuf; ANSI_STRING strBuf;
@ -117,19 +112,19 @@ int WINAPI LoadStringA
/* parameter validation */ /* parameter validation */
if(nBufferMax < 1) if (nBufferMax < 1)
{ {
return -1; return -1;
} }
if(IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0]))) if (IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0])))
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return 0; return 0;
} }
/* get the UNICODE_STRING descriptor of the in-memory image of the string */ /* get the UNICODE_STRING descriptor of the in-memory image of the string */
if(!_InternalLoadString(hInstance, uID, &wstrResStr)) if (!_InternalLoadString(hInstance, uID, &wstrResStr))
{ {
/* failure */ /* failure */
return 0; return 0;
@ -144,11 +139,16 @@ int WINAPI LoadStringA
strBuf.MaximumLength = nBufferMax * sizeof(CHAR); strBuf.MaximumLength = nBufferMax * sizeof(CHAR);
strBuf.Buffer = lpBuffer; strBuf.Buffer = lpBuffer;
retSize = WideCharToMultiByte(CP_ACP, 0, wstrResStr.Buffer, retSize = WideCharToMultiByte(CP_ACP,
0,
wstrResStr.Buffer,
wstrResStr.Length / sizeof(WCHAR), wstrResStr.Length / sizeof(WCHAR),
strBuf.Buffer, strBuf.MaximumLength, NULL, NULL); strBuf.Buffer,
strBuf.MaximumLength,
NULL,
NULL);
if(!retSize) if (!retSize)
{ {
/* failure */ /* failure */
return 0; return 0;
@ -159,7 +159,7 @@ int WINAPI LoadStringA
} }
/* the ANSI string may not be null-terminated */ /* the ANSI string may not be null-terminated */
if(strBuf.Length >= strBuf.MaximumLength) if (strBuf.Length >= strBuf.MaximumLength)
{ {
/* length greater than the buffer? whatever */ /* length greater than the buffer? whatever */
int nStringLen = strBuf.MaximumLength / sizeof(CHAR) - 1; int nStringLen = strBuf.MaximumLength / sizeof(CHAR) - 1;
@ -184,35 +184,30 @@ int WINAPI LoadStringA
/* /*
* @implemented * @implemented
*/ */
int WINAPI LoadStringW int
( WINAPI
HINSTANCE hInstance, LoadStringW(HINSTANCE hInstance,
UINT uID, UINT uID,
LPWSTR lpBuffer, LPWSTR lpBuffer,
int nBufferMax int nBufferMax)
)
{ {
UNICODE_STRING wstrResStr; UNICODE_STRING wstrResStr;
int nStringLen; int nStringLen;
/* parameter validation */ /* parameter validation */
if if ((nBufferMax < 0) || (lpBuffer == NULL) ||
(
(nBufferMax < 0) ||
(lpBuffer == NULL) ||
((nBufferMax > 0) && IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0]))) || ((nBufferMax > 0) && IsBadWritePtr(lpBuffer, nBufferMax * sizeof(lpBuffer[0]))) ||
/* undocumented: If nBufferMax is 0, LoadStringW will copy a pointer to the /* undocumented: If nBufferMax is 0, LoadStringW will copy a pointer to the
in-memory image of the string to the specified buffer and return the length in-memory image of the string to the specified buffer and return the length
of the string in WCHARs */ of the string in WCHARs */
((nBufferMax == 0) && IsBadWritePtr(lpBuffer, sizeof(lpBuffer))) ((nBufferMax == 0) && IsBadWritePtr(lpBuffer, sizeof(lpBuffer))))
)
{ {
SetLastError(ERROR_INVALID_PARAMETER); SetLastError(ERROR_INVALID_PARAMETER);
return 0; return 0;
} }
/* get the UNICODE_STRING descriptor of the in-memory image of the string */ /* get the UNICODE_STRING descriptor of the in-memory image of the string */
if(!_InternalLoadString(hInstance, uID, &wstrResStr)) if (!_InternalLoadString(hInstance, uID, &wstrResStr))
{ {
/* failure */ /* failure */
return 0; return 0;
@ -224,7 +219,7 @@ int WINAPI LoadStringW
if (nBufferMax > 0) if (nBufferMax > 0)
{ {
/* the buffer must be enough to contain the string and the null terminator */ /* the buffer must be enough to contain the string and the null terminator */
if(nBufferMax < (nStringLen + 1)) if (nBufferMax < (nStringLen + 1))
{ {
/* otherwise, the string is truncated */ /* otherwise, the string is truncated */
nStringLen = nBufferMax - 1; nStringLen = nBufferMax - 1;
@ -250,25 +245,26 @@ int WINAPI LoadStringW
*/ */
HDEVNOTIFY HDEVNOTIFY
WINAPI WINAPI
RegisterDeviceNotificationW( RegisterDeviceNotificationW(HANDLE hRecipient,
HANDLE hRecipient,
LPVOID NotificationFilter, LPVOID NotificationFilter,
DWORD Flags DWORD Flags)
)
{ {
DWORD ConfigRet = 0; DWORD ConfigRet = 0;
CMP_REGNOTIFY RegNotify = NULL; CMP_REGNOTIFY RegNotify = NULL;
HDEVNOTIFY hDevNotify = NULL; HDEVNOTIFY hDevNotify = NULL;
if ( hSetupApi == NULL ) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
if ( hSetupApi == NULL ) return NULL; if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
RegNotify = (CMP_REGNOTIFY) GetProcAddress ( hSetupApi, "CMP_RegisterNotification"); if (hSetupApi == NULL) return NULL;
RegNotify = (CMP_REGNOTIFY) GetProcAddress(hSetupApi, "CMP_RegisterNotification");
if (RegNotify == NULL) if (RegNotify == NULL)
{ {
FreeLibrary ( hSetupApi ); FreeLibrary(hSetupApi);
hSetupApi = NULL; hSetupApi = NULL;
return NULL; return NULL;
} }
ConfigRet = RegNotify ( hRecipient, NotificationFilter, Flags, (PULONG) &hDevNotify);
ConfigRet = RegNotify(hRecipient, NotificationFilter, Flags, (PULONG) &hDevNotify);
if (ConfigRet != CR_SUCCESS) if (ConfigRet != CR_SUCCESS)
{ {
switch (ConfigRet) switch (ConfigRet)
@ -276,17 +272,21 @@ RegisterDeviceNotificationW(
case CR_OUT_OF_MEMORY: case CR_OUT_OF_MEMORY:
SetLastError (ERROR_NOT_ENOUGH_MEMORY); SetLastError (ERROR_NOT_ENOUGH_MEMORY);
break; break;
case CR_INVALID_POINTER: case CR_INVALID_POINTER:
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
break; break;
case CR_INVALID_DATA: case CR_INVALID_DATA:
SetLastError (ERROR_INVALID_DATA); SetLastError (ERROR_INVALID_DATA);
break; break;
default: default:
SetLastError (ERROR_SERVICE_SPECIFIC_ERROR); SetLastError (ERROR_SERVICE_SPECIFIC_ERROR);
break; break;
} }
} }
return hDevNotify; return hDevNotify;
} }
@ -296,21 +296,23 @@ RegisterDeviceNotificationW(
*/ */
BOOL BOOL
WINAPI WINAPI
UnregisterDeviceNotification( UnregisterDeviceNotification(HDEVNOTIFY Handle)
HDEVNOTIFY Handle)
{ {
DWORD ConfigRet = 0; DWORD ConfigRet = 0;
CMP_UNREGNOTIFY UnRegNotify = NULL; CMP_UNREGNOTIFY UnRegNotify = NULL;
if ( hSetupApi == NULL ) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
if ( hSetupApi == NULL ) return FALSE; if (hSetupApi == NULL) hSetupApi = LoadLibraryA("SETUPAPI.DLL");
UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress ( hSetupApi, "CMP_UnregisterNotification"); if (hSetupApi == NULL) return FALSE;
UnRegNotify = (CMP_UNREGNOTIFY) GetProcAddress(hSetupApi, "CMP_UnregisterNotification");
if (UnRegNotify == NULL) if (UnRegNotify == NULL)
{ {
FreeLibrary ( hSetupApi ); FreeLibrary(hSetupApi);
hSetupApi = NULL; hSetupApi = NULL;
return FALSE; return FALSE;
} }
ConfigRet = UnRegNotify ( (ULONG) Handle );
ConfigRet = UnRegNotify((ULONG) Handle );
if (ConfigRet != CR_SUCCESS) if (ConfigRet != CR_SUCCESS)
{ {
switch (ConfigRet) switch (ConfigRet)
@ -318,15 +320,18 @@ UnregisterDeviceNotification(
case CR_INVALID_POINTER: case CR_INVALID_POINTER:
SetLastError (ERROR_INVALID_PARAMETER); SetLastError (ERROR_INVALID_PARAMETER);
break; break;
case CR_INVALID_DATA: case CR_INVALID_DATA:
SetLastError (ERROR_INVALID_DATA); SetLastError (ERROR_INVALID_DATA);
break; break;
default: default:
SetLastError (ERROR_SERVICE_SPECIFIC_ERROR); SetLastError (ERROR_SERVICE_SPECIFIC_ERROR);
break; break;
} }
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }