kernel32: GlobalSize() should also work with GMEM_MOVEABLE data pointers received from GlobalLock().

This commit is contained in:
David Hedberg 2011-06-13 08:22:15 +02:00 committed by Alexandre Julliard
parent 43c648ecdc
commit fed025fd42
2 changed files with 37 additions and 1 deletions

View file

@ -820,6 +820,12 @@ SIZE_T WINAPI GlobalSize(HGLOBAL hmem)
if(ISPOINTER(hmem))
{
retval=HeapSize(GetProcessHeap(), 0, hmem);
if (retval == (DWORD)-1) /* It might be a GMEM_MOVEABLE data pointer */
{
retval = HeapSize(GetProcessHeap(), 0, (char*)(hmem) - HGLOBAL_STORAGE);
if (retval != (DWORD)-1) retval -= HGLOBAL_STORAGE;
}
}
else
{

View file

@ -85,7 +85,7 @@ static void test_heap(void)
UINT flags;
HGLOBAL gbl;
HGLOBAL hsecond;
SIZE_T size;
SIZE_T size, size2;
/* Heap*() functions */
mem = HeapAlloc(GetProcessHeap(), 0, 0);
@ -403,6 +403,36 @@ static void test_heap(void)
"MAGIC_DEAD)\n", mem, GetLastError(), GetLastError());
GlobalFree(gbl);
/* trying to get size from data pointer (GMEM_MOVEABLE) */
gbl = GlobalAlloc(GMEM_MOVEABLE, 0x123);
ok(gbl != NULL, "returned NULL\n");
mem = GlobalLock(gbl);
ok(mem != NULL, "returned NULL.\n");
ok(gbl != mem, "unexpectedly equal.\n");
size = GlobalSize(gbl);
size2 = GlobalSize(mem);
ok(size == 0x123, "got %lu\n", size);
ok(size2 == 0x123, "got %lu\n", size2);
GlobalFree(gbl);
/* trying to get size from data pointer (GMEM_FIXED) */
gbl = GlobalAlloc(GMEM_FIXED, 0x123);
ok(gbl != NULL, "returned NULL\n");
mem = GlobalLock(gbl);
ok(mem != NULL, "returned NULL.\n");
ok(gbl == mem, "got %p, %p.\n", gbl, mem);
size = GlobalSize(gbl);
ok(size == 0x123, "got %lu\n", size);
GlobalFree(gbl);
size = GlobalSize((void *)0xdeadbee0);
ok(size == 0, "got %lu\n", size);
}
static void test_obsolete_flags(void)