[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 407
  • Last Modified:

NetRemoteTOD

I work in VB3 and I want use the NetRemoteTOD function of NETAPI.DLL
 I have:
Type TIME_OF_DAY_INFO
 tod_elapsedt As Long
 tod_msecs As Long
 tod_hours As Long
 tod_mins As Long
 tod_secs As Long
 tod_hunds As Long
 tod_timezone As Long
 tod_tinterval As Long
 tod_day As Long
 tod_month As Long
 tod_year As Long
 tod_weekday As Long
End Type
Global TOD1 As TIME_OF_DAY_INFO
Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal SName&, TOD As TIME_OF_DAY_INFO) As Integer

when I use the NetRemoteTOD function obtain GPF.

How can I use (in VB3) the NetRemoteTOD function for obtain the time of day information from a specified server ?

I want a sample please !!!
0
miguelpf
Asked:
miguelpf
  • 5
  • 4
  • 3
  • +1
1 Solution
 
mrmickCommented:
A sample doesn't fall into to the easy (50-point) category!  But for 50...

1) The declare is wrong:

Declare Function NetRemoteTOD Lib "NETAPI32.DLL" (ByVal SName as String, TOD As TIME_OF_DAY_INFO) As Long

2) WinNT: Yes  Win95: No  Win32: No

3) The SName string must be in Unicode format, VB3 doesn't save strings in Unicode format.  I believe you could convert the string to Unicode format, but I don't know if VB3 strings can contain chr$(0) bytes (It's been so long since I've worked in VB3).

0
 
miguelpfAuthor Commented:
thanks, but i need obtain the time of day information from a specified server in VB3 without use "NET TIME \\SERVER" of DOS
0
 
rantanenCommented:
Are you targeting to NT, 'cause

NetRemoteTOD
...
Windows NT: Use version 3.1 and later.
Windows: Unsupported.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
alamoCommented:
If I recall, VB3 was 16-bit only.... so the chances that any of what has been said are correct is very small ;-) "NETAPI.DLL" in the original question was a tipoff also. (Though the declarations were the 32 bit versions... no wonder it GPFed :-)

By the way, mrmick, your Win32 prototype was wrong (just in case it ever comes up - look at it more closely and you'll see).

Here is the prototype and sample code for 16-bits.

' 16-bit declares - note they are different than the 32 bit ones!
Type TIME_OF_DAY_INFO
 tod_elapsedt   As Long      '/* time from 1-1-1970 in seconds */
 tod_msecs As Long           '/* milliseconds */
 tod_hours As Byte           '/* hours */
 tod_mins As Byte            '/* minutes */
 tod_secs As Byte            '/* seconds */
 tod_hunds As Byte           '/* hundredths */
 tod_timezone As Integer     '/* time zone in minutes from GMT */
 tod_tinterval As Integer    '/* timer interval (units = 0.0001 sec) */
 tod_day As Byte             '/* day */
 tod_month As Byte           '/* month */
 tod_year As Integer         '/* year */
 tod_weekday As Byte         '/* day of week */
End Type
Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal pszServer As String, pbBuffer As TIME_OF_DAY_INFO, ByVal cbBuffer As Integer) As Integer


Dim tTime As TIME_OF_DAY_INFO
Dim lLength As Integer
Dim lReturn As Integer
Dim swServername As String

lLength = Len(tTime)
swServername = ""    ' server, blank works

lReturn = NetRemoteTOD(swServername, tTime, lLength)

Debug.Print "lReturn     = " & lReturn
Debug.Print "Elapsed     = " & tTime.tod_elapsedt
Debug.Print "Milliseconds= " & tTime.tod_msecs
Debug.Print "Hours       = " & tTime.tod_hours
Debug.Print "Minutes     = " & tTime.tod_mins
Debug.Print "Seconds     = " & tTime.tod_secs
Debug.Print "Hundreds    = " & tTime.tod_hunds
Debug.Print "Time Zone   = " & tTime.tod_timezone
Debug.Print "Time Intervl= " & tTime.tod_tinterval
Debug.Print "Day         = " & tTime.tod_day
Debug.Print "Month       = " & tTime.tod_month
Debug.Print "Year        = " & tTime.tod_year
Debug.Print "Weekday     = " & tTime.tod_weekday

miguelpf, hope this is what you need. By the way, I would really appreciate it if you would increase the points before you grade,  it did take a while to track all this down and get it to work.

Let me know if you ahve problems with this, and good luck!
0
 
rantanenCommented:
Alamo,

did you test it with VB3 or VB4/16, because VB3 does not have data type BYTE, so probably some difficulties ahead. (See your type definition TIME_OF_DAY_INFO ).
0
 
alamoCommented:
Oooh, thanks, rantanen - I was switching between 32 and 16 bit VBs and endd up in VB4/16 - made a mental note to adjust for the lack of byte and forgot completely!

I just converted it to VB3 and it still works fine I changed only the Type definition and the Debug.print statements (easy) but I might as well post the whoile thing again:

' 16-bit VB3 declares - note they are different than the 32 bit ones!
Type TIME_OF_DAY_INFO
 tod_elapsedt   As Long      '/* time from 1-1-1970 in seconds */
 tod_msecs As Long           '/* milliseconds */
 tod_hours As String * 1         '/* hours */
 tod_mins As String * 1          '/* minutes */
 tod_secs As String * 1          '/* seconds */
 tod_hunds As String * 1         '/* hundredths */
 tod_timezone As Integer     '/* time zone in minutes from GMT */
 tod_tinterval As Integer    '/* timer interval (units = 0.0001 sec) */
 tod_day As String * 1           '/* day */
 tod_month As String * 1         '/* month */
 tod_year As Integer         '/* year */
 tod_weekday As String * 1       '/* day of week */
End Type

Declare Function NetRemoteTOD Lib "NETAPI.DLL" (ByVal pszServer As String, pbBuffer As TIME_OF_DAY_INFO, ByVal cbBuffer As Integer) As Integer

Code:

Dim tTime As TIME_OF_DAY_INFO
Dim lLength As Integer
Dim lReturn As Integer
Dim sServername As String

lLength = Len(tTime)
sServername = ""
lReturn = NetRemoteTOD(ByVal sServername, tTime, lLength)

Debug.Print "lReturn=" & lReturn
Debug.Print "Elapsed    = " & tTime.tod_elapsedt
Debug.Print "Milliseconds= " & tTime.tod_msecs
Debug.Print "Hours     = " & Asc(tTime.tod_hours)
Debug.Print "Minutes   = " & Asc(tTime.tod_mins)
Debug.Print "Seconds   = " & Asc(tTime.tod_secs)
Debug.Print "Hundreds  = " & Asc(tTime.tod_hunds)
Debug.Print "Time Zone = " & tTime.tod_timezone
Debug.Print "Time Interval = " & tTime.tod_tinterval
Debug.Print "Day     = " & Asc(tTime.tod_day)
Debug.Print "Month   = " & Asc(tTime.tod_month)
Debug.Print "Year    = " & tTime.tod_year
Debug.Print "Weekday = " & Asc(tTime.tod_weekday)


Sorry about that miguelpf, and thanks rantanen!
0
 
mrmickCommented:
Sorry alamo, but what do you see that I didn't?
0
 
alamoCommented:
mrmick, the second argument in NetRemoteTOD isn't TIME_OF_DAY_INFO, it's a pointer (passed ByRef) which the API sets to point to the TIME_OF_DAY_INFO buffer which it has allocated itself (and which you must deallocate when you're done with it).
0
 
mrmickCommented:
alamo,

uh, huh huh, huh huh, uh?  So... you actually think there's a difference in these two lines?

My declaration: TOD As TIME_OF_DAY_INFO
Your declaration: pbBuffer As TIME_OF_DAY_INFO

0
 
miguelpfAuthor Commented:
thanks !!!
0
 
alamoCommented:
Actually, mrmick, that was my 16 bit declaration - it's the WinNT declaration you posted which is wrong, which should be the address not of the structurebut instead the address of a pointer which the API sets to the address of the structure.

The actual call is something like:
Dim ptrTime As Long
...
lReturn = NetRemoteTOD(swServerName, ptrTime)
0
 
miguelpfAuthor Commented:
thanks !!!
0
 
alamoCommented:
You are welcome miguelpf... and thanks for the points!
0
 
miguelpfAuthor Commented:
happy new year !!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now