http://www.perlmonks.org?node_id=164195

mothra has asked for the wisdom of the Perl Monks concerning the following question:

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?