SAMPLE: WNetCOM Uses COM Object to Access WNet Functions from VB

ID: Q189515

The information in this article applies to:

SUMMARY

WNetCOM.exe is a sample that contains the WNet COM object. The WNet COM object demonstrates how to access complicated networking features from Visual Basic using COM. The object was created using the ATL COM Wizard in Visual C++ 5. This COM object is implemented as a DLL. Once the skeleton code is generated, click Insert and then click New Class to create a WNet class. This new class is defined as a Custom interface with just 1 interface. The new class contains the code to implement the various WNet features. From the Class View, you may add methods by right-clicking the interface and selecting Add Method.

From there, you can add the methods that you want to implement in the COM object. The sample code provided in this article is meant to be used as a tutorial for implementing your own controls that wrap up complex APIs. It is not meant to be used as production code.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ WNetCOM.exe (size: 41487 bytes) 

Release Date: Jul-15-1998

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE : How to Obtain Microsoft Support Files from Online Services

Installation and Use

After you have extracted the files into a directory, start Visual C++ and load the project. On the Build menu, click Rebuild All. This will compile the project and install the control into the system. In Visual Basic, you can now add the object to your project by going to the Project menu and clicking References. The COM object is listed as "NetwkObj 1.0 Type Library." While still in Visual Basic, you may use either early or late binding to instantiate these types of objects. The object (type) name is NetwkObj and the interface is WNet. Following is an example of early binding in Visual Basic:

   Dim x as NetwkObj.WNet

Following is an example of late binding:

   Dim x as Object

   Set x = CreateObject("NetwkObj.WNet")

Source Files

This file is associated with the WNet COM object.

Following are the files associated with this application:

Properties, Methods, and Events

The WNet COM object has the following methods:

Support Files

Along with the source code for the WNet COM object is a Visual Basic project that illustrates how to use the WNet COM object for network programming. The Visual Basic project consists of the following files:

   Form1.frm
   Project1.vbp
   Project1.vbw

This application is very simple. There is one section devoted to each of the WNet functions. The following five frames are on the form:

   Frame                Resource Viewed
   ------------------------------------------------------------------------

   Map Drive            Fill in the appropriate text boxes that
                        correspond to the function parameters, and
                        click Map It!

   Unmap Resource       Fill in the resource name, either local or
                        Remote, and click Unmap!

   Current User         Click Get Current User to fill in the text box with
                        the current user.

   Enumerate Resource   Select one of the four views, and enter a name,
                        if necessary. Click Enumerate, and the list box
                        will be populated with the results.

   Connection Info      Fill in the Local Name of the resource, and
                        click Get Info. The remote name will be filled with
                        the UNC name of the resource it is mapped to.

Each subroutine that calls a method on the WNet COM object has an "On Error" handler. Within the handler there is a simple MsgBox that calls the GetErrorText() method to retrieve an error string. You can implement more advanced error handling in the COM object relatively easily.

Additional query words: Keywords : kbfile kbnetwork kbAPI kbNTOS400 kbSDKPlatform kbWinOS95 kbWinOS98 kbWNet kbGrpNet

Last Reviewed: August 1, 1998