https://bugs.winehq.org/show_bug.cgi?id=39171
--- Comment #3 from Richard rw92672685@hotmail.com --- I've spent sometime on this and found it caused by an undocumented "feature" of GetSystemPaletteEntries().
MSDN makes no mention of it but the function will fill whatever it can of the nEntries buffer with the default system colours, even when returning 0 for failure. The passed device context may even be NULL.
I've attached an initial patch for the fix, along with a simple test program.
This is my second WINE patch so let me know of any problems with it.