CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Win32 Programming Help:
Win32::API::Prototype and FILETIME



Apr 21, 2007, 3:31 AM

Post #1 of 2 (7644 views)
Win32::API::Prototype and FILETIME Can't Post

Hi All,

I am trying to use the Win32::API::Prototype module to write some files to the Internet cache. I can create the cache entry ok by calling CreateUrlCacheEntry and CommitUrlCacheEntry. But now I'd like to specify the expire date of this cache entry and that's where trouble start: I understand Win32 FILETIME structure is like this:

typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;

First of all, does anybody knows what these LowDateTime and HighDateTime actually mean ?

Then how do I convert the SYSTEMTIME to a FILETIME ?

- First I need to create the SYSTEMTIME structure. I did:

 my $pSystemTime = pack("S8",$wYear,$wMonth,$wDayofWeek,$wDay,$wHour,$wMin, $wSec,$wMilli); 

- Then I need to convert it to a FILETIME. Like this:



At that point, the perl interpreter crashes. So I guess I must be doing something wrong, either because the pack() uses a wrong template or because I use the SystemTimeToFileTime function incorrectly...

- Then I would need to extract the LowDateTime and HighDateTime from that resulting structure but I have no clue how to do this.

As always any help would be greatly appreciated.




Apr 21, 2007, 11:13 PM

Post #2 of 2 (7638 views)
Re: [jbenezech] Win32::API::Prototype and FILETIME [In reply to] Can't Post

Finally got this thing working. Problem was that I did not initialize the FILETIME structure. Here is the working code for future reference:

 sub getFileTime { 
# Create a SYSTEMTIME object
my $wYear = '2099';
my $wMonth = '12';
my $wDayofWeek = '6';
my $wDay = '1';
my $wHour = '10';
my $wMin = '12';
my $wSec = '30';
my $wMilli = '0'; # Now, pack the object. The SYSTEMTIME object is basically 8 WORDs
# packed into a structure.
my $pSystemTime = pack("S8",$wYear,$wMonth,$wDayofWeek,$wDay,$wHour,$wMin, $wSec,$wMilli); # Convert the SYSTEMTIME to a FILETIME object
my $pFileTime = ' ' x 2 x 8;
if (SystemTimeToFileTime($pSystemTime,$pFileTime)) {
my ($low, $high) = unpack("L2", $pFileTime);
print "Got file time low $low\n";
print "Got file time high $high\n";
return ($low, $high);
} else {
print "Could not convert time: $!\n";
return (0,0);


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives