Hello,
I spotted this bug while trying to fix mouse pointer trails problem in Warlords Battlecry. All widths, heights and left/top coordinates are of DWORD type, so substracting them from each other always give positive numbers. Thus h and w are always >= 0, so DDERR_INVALIDRECT is returned only in a couple of boundary cases.
I just added explicit casting to int where needed. It didn't fix the mouse trails, but previously missing mouseover effect on icons at the main screen appeared, so I guess it is a change in the right direction :)
Patch attached.