Netware Programming in Visual Basic A Brief Overview

CKI Logo
 
Reviews Portfolio Tutorials and Papers Book Store
 
Divider Bar
   
 

Introduction

After watching the Comp.Lang.Basic.Visual news group for a while, I started to notice a lot of questions about making Netware API calls from Visual Basic. Most of the questions originated as specific API how-to's, but then soon became general "How do I any Netware API programming?". This paper is in response to these general question.

This paper will not be is an overview of Netware services, but it will show some common things applications need to do using Netware API calls.

All Calls Start Here

Most Netware API functions reside in NWCALLS.DLL. But before you can make calls to map drives, query connections, or get the server date and time, some housekeeping must be performed. This housekeeping is the primary item that novice Netware programmers do not do. They tend to just make the Netware API call they want and then wonder why id did not work.

The first Netware API call all applications must make is NWCallsInit. Without it, none of the other calls will work. The Visual Basic declare is:
Declare Function NWCallsInit Lib "NWCALLS.DLL" (inp As Any, oup As Any) As Integer
You should note that all Netware API calls return an integer return code. If the value is zero the call was successful, if non-zero the call failed.

Making this call is quite simple and should be placed in the application startup code, such as the Load event for the main form. Make the NwCallsInit call as follows:
Dim nwrc As Integer
nwrc = NWCallsInit(0,0)
If nwrc <> 0 then
MsgBox("NWCallsInit was not successful",....)
End If
Once you have initialized the Netware calls interface, you can make all of the other Netware API calls. However, most of the Netware API calls require a connection handle as their first argument. I usually make the API call to obtain this handle right after calling NWCallsInit. I place the handle in a global variable so that I can use it whenever I need it for other API calls. To get a connection handle for the station your application is running on, call NWGetDefaultConnectionID. Its Visual Basic declare is:
Declare Function NWGetDefaultConnectionID Lib "NWCALLS.DLL" (connhdl As Integer) As Integer
This API function will place a connection handle in the passed integer variable. Get the connection handle like this:
Global gConnHandle As Integer
Dim nwrc As integer
nwrc = NWGetDefaultConnectionID(gConnHandle)
if nwrc <> 0 then
MsgBox("NWGetDefaultConnectionIDt was not successful",....)
End If
Once you have initialized NWCalls and obtained a connection a handle the world of Netware API is open.

Obtaining Server Information

At this point I will show a simple Netware API call that gets information about the server that the workstation is attached to. The Netware API function NWGetFileServerInformation will return the server name, the server Netware version information, connection information as well as few other pieces of information about the server. The Visual Basic declare is:
Declare Function NWGetFileServerInformation Lib "NWCALLS.DLL" (ByVal connhdl As Integer, ByVal serverName as String,
majorVersion as Integer, minorVersion as Integer, revision As Integer, maxConnections As Integer, maxConnectionsUsed as Integer,
connectionsInUse as integer, numVolumes As Integer, SFTLevel As Integer, TTSLevel As Inetger) As Integer
You can make this call as follows:
Dim ret As Integer
Dim serverName As String * 48
Dim majorVersion As Integer
Dim minorVersion As Integer
Dim revision As Integer
Dim maxConnections As Integer
Dim maxConnectionsUsed As Integer
Dim connectionsInUse As Integer
Dim numVolumes As Integer
Dim SFTLevel As Integer
Dim TTSLevel As Integer
ret = NWGetFileServerInformation(connid, serverName, majorVersion, minorVersion, revision, maxConnections, maxConnectionsUsed,
connectionsInUse, numVolumes, SFTLevel, TTSLevel)
Notice that the serverName variable is a fixed length string. This is required by the Netware API call because does not know how work with Visual Basic variable length strings. Any time a string is required for a Netware API call, make certain you define it as fixed length.

If you wanted to get the date and time from the File Server you would use NWGetFileServerDateAndTime. The Visual Basic declare is:
Declare Function NWGetFileServerDateAndTime Lib "NWCALLS.DLL" (ByVal connhdl As Integer, ByVal dtetme As String) As Integer
This functions returns the date and time in a special byte layout that needs to be parsed. This code sample shows how this done.
Dim ret As Integer
Dim datetime As String * 8
ret = NWGetFileServerDateAndTime(connid, datetime)

Month.Text = Asc(Mid$(datetime, 2, 1))
Day.Text = Asc(Mid$(datetime, 3, 1))
Year.Text = Asc(Mid$(datetime, 1, 1))
Hour.Text = ASC(Mid$(datetime,4,1))
Minute.Text = ASC(Mid$(datetime,5,1))
Second.Text = ASC(Mid$(datetime,6,1))
DayOfWeek = ASC(MID$(datetime,7,1)) ' 0 = Sunday

Conclusion

Netware programming is not difficult one you know how to start. Trying to get your Netware API call to work without the proper initialization can be quite trying. One further recommendation if you plan to do a lot of Netware programming, Novell has produced a CD-ROM that contains all of the API documentation, it sells for approximately $40.00 US. You should try to get a copy of this. It will make life as a Novell Netware programming much easier.

Back