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?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.