Link to home
Start Free TrialLog in
Avatar of miguelpf
miguelpf

asked on

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 !!!
Avatar of mrmick
mrmick

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).

Avatar of miguelpf

ASKER

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

NetRemoteTOD
...
Windows NT: Use version 3.1 and later.
Windows: Unsupported.
ASKER CERTIFIED SOLUTION
Avatar of alamo
alamo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ).
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!
Sorry alamo, but what do you see that I didn't?
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).
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

thanks !!!
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)
thanks !!!
You are welcome miguelpf... and thanks for the points!
happy new year !!!