Contacting the Win32::GUI maintainer seems somewhat difficult, so would an XS hacker please set me straight? As this post also contains a, cough, "fix", others might find this useful.

Issue is this: the Win32::GUI TreeView->InsertItem() method works correctly on 32bit perl but does not on 64bit perl (this is Win32::GUI 1.12 under Strawberry 5.22.1 on Win7).

Run this code on both perl versions and compare the order of items in the tree (or run on x64 only and be baffled):

use strict; use Win32::GUI; sub TVI_FIRST { 0xFFFF0001 } my $Window = new Win32::GUI::Window( -name => "Window", -text => "Win32::GUI v. $Win32::GUI::VERSION TreeView: 32bit vs. + 64bit", -height => 200, -width => 350, -left => 100, -top => 100, ); my $TV = $Window->AddTreeView( -width => $Window->ScaleWidth, -height => $Window->ScaleHeight, -left => 0, -top => 0, -lines => 1, -rootlines => 1, -buttons => 1 ); my $rootNode = $TV->InsertItem( -text => "rootNode", ); my $childNode = $TV->InsertItem( -parent => $rootNode, -text => "childNode", -item => TVI_FIRST ); my $childAtt2 = $TV->InsertItem( -parent => $childNode, -text => "childAtt2", -item => TVI_FIRST ); my $childAtt1 = $TV->InsertItem( -parent => $childNode, -text => "childAtt1", -item => TVI_FIRST ); # root attribute inserted _after_ inserting child nodes, but should # display _before_ child nodes my $rootAtt1 = $TV->InsertItem( -parent => $rootNode, -text => "rootAtt1", -item => TVI_FIRST ); $TV->Expand($_) for($rootNode, $childNode); $Window->Show(); Win32::GUI::Dialog(); # eof

Since this is a bitness issue, my hunch is that it must be related to pointers. I think I tracked this down as far as GUI_Helpers.cpp::handle_From() where the conversion of integers to pointers for InsertItem() takes place.

I "fixed" the issue in the definiton of InsertItem() in TreeView.xs by replacing line 815

Insert.hInsertAfter = (HTREEITEM) handle_From(NOTXSCALL ST(next_i));

with

switch(SvIV(ST(next_i))){ case 0xFFFF0001: Insert.hInsertAfter = TVI_FIRST; break; case 0xFFFF0002: Insert.hInsertAfter = TVI_LAST; break; case 0xFFFF0003: Insert.hInsertAfter = TVI_SORT; break; default: Insert.hInsertAfter = (HTREEITEM) handle_From(NOTXSCALL ST(next_i) +); break; }

This looks pretty awful, even to me as a non-XS hacker.

So my question: what is the underlying problem and how is it fixed properly?


In reply to x64 Win32::GUI TreeView broken, question and "fix" included by tomsell

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.