diff --git a/modules/rostests/winetests/gdi32/palette.c b/modules/rostests/winetests/gdi32/palette.c index aac16097fba..90a37690a42 100644 --- a/modules/rostests/winetests/gdi32/palette.c +++ b/modules/rostests/winetests/gdi32/palette.c @@ -153,7 +153,7 @@ static void test_palette_entries(void) ok(memcmp(&palEntry, &getEntryResult, sizeof(PALETTEENTRY)), "entries should not match\n"); } -static void test_halftone_palette(void) +static void test_halftone_palette(HDC hdc) { HDC hdc; HPALETTE pal; @@ -161,12 +161,12 @@ static void test_halftone_palette(void) PALETTEENTRY defpal[20]; int i, count; - hdc = GetDC(0); - count = GetPaletteEntries( GetStockObject(DEFAULT_PALETTE), 0, 20, defpal ); ok( count == 20, "wrong size %u\n", count ); pal = CreateHalftonePalette( hdc ); + ok( pal != NULL, "error=%ld\n", GetLastError() ); + count = GetPaletteEntries( pal, 0, 256, entries ); ok( count == 256 || broken(count <= 20), /* nt 4 */ "wrong size %u\n", count ); @@ -331,6 +331,7 @@ START_TEST(palette) { test_DIB_PAL_COLORS(); test_palette_entries(); - test_halftone_palette(); + test_halftone_palette(GetDC(0)); + test_halftone_palette(NULL); test_system_palette_entries(); } diff --git a/win32ss/gdi/ntgdi/palette.c b/win32ss/gdi/ntgdi/palette.c index 41a3d9639c9..ac22959e40d 100644 --- a/win32ss/gdi/ntgdi/palette.c +++ b/win32ss/gdi/ntgdi/palette.c @@ -528,12 +528,12 @@ NtGdiCreateHalftonePalette(HDC hDC) { int i, r, g, b; PALETTEENTRY PalEntries[256]; - PPALETTE ppal; - PDC pdc; + PPALETTE ppal = NULL; + PDC pdc = NULL; HPALETTE hpal = NULL; pdc = DC_LockDc(hDC); - if (!pdc) + if (hDC && !pdc) { EngSetLastError(ERROR_INVALID_HANDLE); return NULL; @@ -553,7 +553,9 @@ NtGdiCreateHalftonePalette(HDC hDC) PalEntries[246 + i].peBlue = g_sysPalTemplate[10 + i].peBlue; } - ppal = PALETTE_ShareLockPalette(pdc->dclevel.hpal); + if (pdc) + ppal = PALETTE_ShareLockPalette(pdc->dclevel.hpal); + if (ppal && (ppal->flFlags & PAL_INDEXED)) { /* FIXME: optimize the palette for the current palette */ @@ -587,7 +589,8 @@ NtGdiCreateHalftonePalette(HDC hDC) if (ppal) PALETTE_ShareUnlockPalette(ppal); - DC_UnlockDc(pdc); + if (pdc) + DC_UnlockDc(pdc); ppal = PALETTE_AllocPalWithHandle(PAL_INDEXED, 256, PalEntries, 0, 0, 0); if (ppal)