diff --git a/dlls/kernel/heap.c b/dlls/kernel/heap.c index c76f876d532..730379c5258 100644 --- a/dlls/kernel/heap.c +++ b/dlls/kernel/heap.c @@ -751,13 +751,19 @@ HGLOBAL WINAPI GlobalFree(HGLOBAL hmem) * * Get the size of a global memory object. * + * PARAMS + * hmem [I] Handle of the global memory object + * * RETURNS - * Size in bytes of the global memory object - * 0: Failure + * Failure: 0 + * Success: Size in Bytes of the global memory object + * + * NOTES + * When the handle is invalid, last error is set to ERROR_INVALID_HANDLE + * */ -SIZE_T WINAPI GlobalSize( - HGLOBAL hmem /* [in] Handle of global memory object */ -) { +SIZE_T WINAPI GlobalSize(HGLOBAL hmem) +{ DWORD retval; PGLOBAL32_INTERN pintern; @@ -785,7 +791,8 @@ SIZE_T WINAPI GlobalSize( } else { - WARN("invalid handle\n"); + WARN("invalid handle %p (Magic: 0x%04x)\n", hmem, pintern->Magic); + SetLastError(ERROR_INVALID_HANDLE); retval=0; } RtlUnlockHeap(GetProcessHeap()); diff --git a/dlls/kernel/tests/heap.c b/dlls/kernel/tests/heap.c index fee183096a1..089c5029e75 100644 --- a/dlls/kernel/tests/heap.c +++ b/dlls/kernel/tests/heap.c @@ -92,6 +92,11 @@ START_TEST(heap) ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), "returned 0x%04x with 0x%08lx (expected GMEM_INVALID_HANDLE with " \ "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); + SetLastError(MAGIC_DEAD); + size = GlobalSize(gbl); + ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), + "returned %ld with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", + size, GetLastError()); /* Local*() functions */ @@ -128,6 +133,11 @@ START_TEST(heap) ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE), "returned 0x%04x with 0x%08lx (expected LMEM_INVALID_HANDLE with " \ "ERROR_INVALID_HANDLE)\n", flags, GetLastError()); + SetLastError(MAGIC_DEAD); + size = LocalSize(gbl); + ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE), + "returned %ld with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n", + size, GetLastError()); /* trying to lock empty memory should give an error */