in reply to x64 Win32::GUI TreeView broken, question and "fix" included

Changing TVI_FIRST fixes the problem for me with 64-bit (but I didn't try 32-bit yet!):
sub TVI_FIRST () { -0x0FFFF }

Here is its definition in CommCtrl.h:
#define TVI_FIRST   ((HTREEITEM)(ULONG_PTR)-0x0FFFF)

Replies are listed 'Best First'.
Re^2: x64 Win32::GUI TreeView broken, question and "fix" included
by tomsell (Acolyte) on Mar 17, 2016 at 09:51 UTC

    Nice! Using the TVI_* values defined in commctrl.h instead of the ones documented in Win32::GUI works, both for x64 and x86.

    Not that I'm any the wiser why it does. I had looked up the macro but was intimidated by the ULONG_PTR part (is that a cast?). I can also make no sense of the HTREEITEM macro but tend to think that it is not the same as a HWND used by handle_From() which screws up the advertised 0xFFFF000* values.

      Yeah, the negative inte value gets cast to a ULONG_PTR, which is an unsigned integral type whose size is big enough to hold a pointer value -- an unsigned long in x86 builds and an unsigned __int64 (equivalent to unsigned long long) with x64. So with this cast, on x64, the negative int value is sign-extended and all upper bits in the ULONG_PTR end up being set to 1. HTREEITEM is actually a typedef of a pointer to a unique dummy struct type, so it is the same size as ULONG_PTR.