Trying for FILETIME to local time and failing

J

Just_a_fan

I looked at the help and googled a bit and decided I had the right idea.

Starting with KFTP from PSC, I wanted to get the remote file last write
time. The results was a GPF trying to write protected memory. Here's
the setup. Any pointers appreciated.

Standard stuff here:

Private Structure WIN32_FIND_DATA
Dim dwFileAttributes As Integer
Dim ftCreationTime As FILETIME
Dim ftLastAccessTime As FILETIME
Dim ftLastWriteTime As FILETIME
Dim nFileSizeHigh As Integer
Dim nFileSizeLow As Integer
Dim dwReserved0 As Integer
Dim dwReserved1 As Integer
<VBFixedString(MAX_PATH),
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,
SizeConst:=MAX_PATH)> Public cFileName As String
<VBFixedString(14),
System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,
SizeConst:=14)> Public cAlternate As String
End Structure

Private Structure FILETIME
Private dwLowDateTime As Int32
Private dwHighDateTime As Int32
End Structure

Private Declare Function FileTimeToSystemTime Lib "kernel32" (ByVal
lpFileTime As FILETIME, ByVal lpSystemTime As SYSTEMTIME) As Long

Dim pData As WIN32_FIND_DATA
Dim st As SYSTEMTIME

FileTimeToSystemTime(pData.ftLastWriteTime, st)

And there is the GPF.

The data in ftLastWriteTime looks good. Two words of numbers, high and
low. Immediate windows shows it just right.

If I am doing something just plain stupid, just let me know. Still
learning .NET here.

Mike
 
J

jason.cipriani

Private Declare Function FileTimeToSystemTime Lib "kernel32" (ByVal
lpFileTime As FILETIME, ByVal lpSystemTime As SYSTEMTIME) As Long

You want to pass those by reference, not by value. Try:

Private Declare Function FileTimeToSystemTime Lib
"kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As
Long

Instead.

Jason
 
H

Herfried K. Wagner [MVP]

You want to pass those by reference, not by value. Try:

Private Declare Function FileTimeToSystemTime Lib
"kernel32" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As
Long

With 'ByVal' being the default in VB.NET, you'd have to change the
declaration above like that:

\\\
Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" ( _
ByRef lpFileTime As FILETIME, _
ByRef lpSystemTime As SYSTEMTIME _
) As Boolean
///
 
J

jason.cipriani

With 'ByVal' being the default in VB.NET, you'd have to change the
declaration above like that:

Thanks for pointing that out, I am still using VB6. I'll have to file
that one away so I don't make a mistake later.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top