Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I'm confused.

I'm trying to pack() the Win32 structure TIME_ZONE_INFORMATION and the seemingly much simpler SYSTEMTIME structure within that. The purpose for this is to preallocate the memory for the parameters to pass to GetTimeZoneInformation (which I'm accessing via Win32::GUI) to pull out both the timezone string (e.g. "CST") and the time bias from UTC.

Currently, I'm using the following code:

sub convertUTC2LocalTime { # convert the time passed to the timezone of the machine my $utc = shift; my $return; my $systime_struct; my $tz_struct; $systime_struct = pack("S8", 0, 0, 0, 0, 0, 0, 0, 0); $tz_struct = pack("Lu32PLu32PL", 0, " " x 32, $systime_struct, 0, " " x 32, $systime_struct, +0); print "$systime_struct\n"; print "$tz_struct\n"; my $GetTimeZoneInformation = new Win32::API( "kernel32", "GetTimeZoneInformation", "P", "N" ); die "Failed to import API GetTimeZoneInformation: $!" unless defined($GetTimeZoneInformation); $return = $GetTimeZoneInformation->Call($tz_struct); $bias = (unpack("Lu32PLu32PL", $tz_struct))[0]; print $bias; }

However, when I run this code, I get an error like "Perl has caused an error in MSVCRT.DLL. Perl will now close."

I'm almost sure the bug is in the pack()ing. What would be the proper pack() template for this structure?

In reply to pack()ing Win32 Structures by mothra

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (7)
    As of 2021-04-15 13:56 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found