Using the SMS API with Visual Basic

The SMS SDK provides a sample Visual Basic interface to the SMS API, and two sample applications that use this interface. These components are located in the \MSSDK\SAMPLES\SYSMGMT\SMS\VBSMSAPI directory of the Platform SDK CD-ROM.

The VBSMSAPI directory contains three subdirectories: COMMON, DLLS, and SAMPLES.

The COMMON directory contains five Visual Basic header files (two of them in the VB4SMS32 subdirectory of COMMON), which must be included by any sample applications that use the SMS API. These files provide all of the declarations needed so that a Visual Basic application can use the SMS API.

In order to write a Visual Basic application that uses the SMS API, the files in the COMMON directory must be copied to a location where your Visual Basic application can access them. The five .BAS files must also be added to your Visual Basic project. The Visual Basic .MAK file may need to be edited manually so that the files added appear in the correct order. The order is important because some of the files depend on definitions made in the preceding files. The correct order is: SMSINFO.BAS, QRYCODES.BAS, OBJECTTY.BAS, SMSAPI.BAS, VB4SMS32.BAS.

The DLLS directory contains another subdirectory called VB4SMS32, which contains the VB4SMS32.OLB (and source code to build the OLB). This OLB provides a set of cover routines that allow a 32-bit Visual Basic application to call the 32-bit SMSAPI.DLL. It must be added to your Visual Basic project using the References item in the Tools menu.

The VB4SMS32.OLB source code is also included in the DLLS directory. You can look at this source to see how certain functions and data structures in the SMS API were implemented under Visual Basic.

The SAMPLES directory contains the BROWSER and the REPORT sample programs. Both samples also use code in the SAMPLES\COMMON subdirectory (for instance, there is code there to present the database login dialog box). The two sample applications are described in more detail below.

Note If you are running a previous version of the SMS SDK (prior to version 1.2), and want to use the SMS API with Visual Basic 3.0, please see Using the SMS API with Visual Basic 3.0.

The Browser Sample

The browser sample provides a way to explore the SMS object hierarchy. The user can add any of the SMS container objects as root nodes in the sample's left-pane outline control. Expanding a container will enumerate its folders and display them as child nodes in the outline control. Expanding a folder does the same thing, except that scalars are enumerated as well.

The sample's right pane shows the type of the object selected in the left pane, along with information relevant for that object. With a container selected, the allowable subfolders and filters are listed. With a folder selected, the allowable subfolders and scalars are listed. With a scalar selected, the value of that scalar is shown.

The Report Sample

The report sample provides a simple, flexible framework for reporting information in the SMS database. The code illustrates how to use the SMS functions to obtain data for reporting purposes, and how to use the SMS filter functions to select desired data. The code implements two types of reports, and can be used as a generic report module to generate additional report types. There is even a skeleton report module called Generic that can be used to develop new reports.

The two implemented reports are a site hierarchy report and a machine group report. The site hierarchy report simply acquires the entire hierarchy of primary sites, secondary sites, and domains. The machine group report acquires the machine properties for all the machines in the desired machine group.

The user can create a new report of either type by choosing New in the File menu. The report data acquired from the SMS database is captured in an access database (*.MDB file) which can subsequently be saved and reopened later with the File menu's Open command. An open report can then be previewed and printed.

The sample uses Crystal Reports for Visual Basic (which is part of the Professional Edition) to do layout and printing of the reports. This provides Print, Preview, and Export to Text File capabilities as well as sophisticated report layout capabilities.

In addition, all information collected from Systems Management Server by the report application is stored in a Microsoft Access version 1.0 database file. This makes it possible to regenerate past reports by simply opening and reprinting saved reports. The saved report data can be further manipulated with a variety of ODBC-compliant tools, such as Microsoft Access.

Visual Basic Samples: Functions

The following SMS API routines are used in the sample programs. Those noted with an asterisk have calling conventions that differ from the corresponding SMS API routine, and are used only in the browser sample. The differences are due to the way that data structures are handled in C versus Visual Basic. See the sample code in the DLLS\VB4SMS32 directory to learn more about how and why these functions are different.

SmsApiVer
SmsDataSourceConnect
SmsDataSourceDisconnect
SmsEnumContainers*
SmsDescribeFolder*
SmsOpenContainer
SmsPopulate
SmsCloseContainer
SmsGetNextFolder
SmsRewind
SmsGetFolderID
SmsGetFolderType
SmsCloseFolder
SmsGetNextScalar
SmsGetScalarByName

Creating Your Own Sample Application

If you want to create your own sample Visual Basic application which uses the SMS API, you must follow these steps:

As previously noted, your application must have access to the five .BAS files from the COMMON directory, and these files must be added (in the proper order) to your Visual Basic project.

In addition, your application must have access to the SMSAPI.DLL included in the SMS SDK CD-ROM.

You must use the Microsoft Visual Basic version 4.0 32-bit Professional Edition. The VB4SMS32.OLB must be copied into a directory in your search path (a reasonable location would be in the same directory as SMSAPI.DLL). Finally, you must add this OLB to your Visual Basic project using the References item in the Tools menu.