Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Trying for FILETIME to local time and failing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Just_a_fan@home.net - 16 Mar 2008 20:08 GMT
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
jason.cipriani@gmail.com - 16 Mar 2008 20:48 GMT
On Mar 16, 3:08 pm, Just_a_...@home.net wrote:
>   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
Herfried K. Wagner [MVP] - 17 Mar 2008 01:27 GMT
<jason.cipriani@gmail.com> schrieb:
>>   Private Declare Function FileTimeToSystemTime Lib "kernel32" (ByVal
>> lpFileTime As FILETIME, ByVal lpSystemTime As SYSTEMTIME) As Long
[quoted text clipped - 4 lines]
> "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
///

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>

jason.cipriani@gmail.com - 17 Mar 2008 05:24 GMT
On Mar 16, 8:27 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.at> wrote:
> <jason.cipri...@gmail.com> schrieb:
>
[quoted text clipped - 9 lines]
> 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.

> \\\
> Private Declare Function FileTimeToSystemTime Lib "kernel32.dll" ( _
[quoted text clipped - 7 lines]
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.