perlquestion
mothra
I'm <i>confused</i>.
<p>I'm trying to pack() the Win32 structure <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/time_8bqq.asp">TIME_ZONE_INFORMATION</a> and the seemingly much simpler <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/time_6sfm.asp">SYSTEMTIME</a> structure within that. The purpose for this is to preallocate the memory for the parameters to pass to <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/time_3lim.asp">GetTimeZoneInformation</a> (which I'm accessing via Win32::GUI) to pull out both the timezone string (e.g. "CST") and the time bias from UTC.
<p>Currently, I'm using the following code:
<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;
}
</code>
<p>However, when I run this code, I get an error like "Perl has caused an error in MSVCRT.DLL. Perl will now close."
<p>I'm almost sure the bug is in the pack()ing. What would be the proper pack() template for this structure?