Win32::API::Struct->sizeof() seems not to compute correctly struct size when nesting them:

use strict; use warnings; use Win32::API; Win32::API::Struct->typedef('POINT', qw( LONG x; LONG y; )); my $Point = Win32::API::Struct->new('POINT'); print "sizeof('POINT') = " . $Point->sizeof() . "\n"; Win32::API::Struct->typedef('CURSORINFO', qw( DWORD cbSize; DWORD flags; HANDLE hCursor; POINT ptScreenPos; )); my $CursorInfo = Win32::API::Struct->new('CURSORINFO'); print "sizeof('CURSORINFO') = " . $CursorInfo->sizeof() . "\n"; Win32::API::Struct->typedef('MYSTRUCT', qw( DWORD cbSize; DWORD flags; HANDLE hCursor; )); my $Struct = Win32::API::Struct->new('MYSTRUCT'); print "sizeof('MYSTRUCT') = " . $Struct->sizeof() . "\n"; __DATA__ sizeof('POINT') = 8 sizeof('CURSORINFO') = 16 sizeof('MYSTRUCT') = 12

8 + 12 != 16

Update: investigating a bit more, the problem seems linked with structure member alignment computations used in sizeof method (and require more knowledge than I've available for now :-)).

Bug discovered in v0.40 of Win32::API::Struct and reported as bug#6757 "Win32::API::Struct->sizeof() seems not to compute correctly struct size when nesting them".

____
HTH, Dominique
My two favorites:
If the only tool you have is a hammer, you will see every problem as a nail. --Abraham Maslow
Bien faire, et le faire savoir...


In reply to Re: Win32::API::Struct and GetCursorInfo with PCURSORINFO by dfaure
in thread Win32::API::Struct and GetCursorInfo with PCURSORINFO by EdwardG

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.