Home

Custom Libraries

   

Introduction

The Windows controls featured in the .NET Framework are highly varied and provide all the necessary regular functionality a normal application would need. They do this using their associated classes that are equipped with various properties and their different methods. To enhance their functionality and speed up application development, you can either create your own new library or use a library created in another language.

 

Microsoft Visual Basic offers a very large set of functions.  You can use most of those functions in your application.

Using a Library

If the .NET Framework doesn't have a class you are looking for, you can create one and be able to use it over and over again in different programs. You can even create a commercial class and be able to distribute or sell it. To make this possible, you can "package" one or more classes.

A library is a program that contains classes and/or other resources that other programs can use. Such a program is created with the same approach as the programs we have done so far. Because a library is not an executable, it doesn't need the Main() function. A library usually has the extension .dll.

A library can be made of a single file or as many files as necessary. A file that is part of a library can contain one or more classes. Each class should implement a behavior that can eventually be useful and accessible to other classes. The classes in a library are created exactly like those we have used so far. Everything depends on how you compile it.

To create a library, start by typing its code in a text file. Once the library is ready, to compile it, at the Command Prompt, you would type:

vbc /target:library NameOfFile.vb

and press Enter. After doing this, a library with the name of the file and the extension .dll would be created. If you want a custom name, use the following syntax:

vbc /target:library /out:DesiredNameOfLibrary.dll NameOfFile.vb

Using a Visual C++/CLI Library

One of the most important sought goals in .NET is to allow different languages to collaborate, such as sharing code. One way this can happen is to be able to use the functionality of one language into another. As no library is ever complete, you may still need functionality that is not easily found. Furthermore, you may be working with a team of C++ programmers who have already created a set of functions or complex operations. You should be able to use that existing code.

In previous years, it used to be a challenge to create a library, especially in C++. Fortunately, Microsoft Visual C++ now makes it particularly easy to create one, because a wizard highly assists you. To create a library, first display the New Project dialog box. After specifying Visual C++, in the middle list, click Class Library and give it a name. In the body of the file, you can create the classes and/or functions as you see fit.

Using the Win32 Library

The Microsoft Windows operating system was originally written in C, the parent language of C++ (also of C#, Java, and JavaScript). To allow programmers to create applications, Microsoft released a library called Win32. This is a series of functions and classes, etc, that you previously had to use. As time has changed, you don't need to exclusively use Win32 anymore to create a Windows application. Nonetheless, Win32 is still everywhere and it is not completely avoidable because many or some of the actions you would want to perform in a Windows application are still available only in Win32. Fortunately, in most cases, it is not always difficult to use some of these functions in a Visual Basic application, as long as you observe some rules. Here is an example:

Module Exercise

    Declare Auto Function SpecifyTitle Lib "Kernel32.dll" Alias "SetConsoleTitle" (ByVal msg As String) As Boolean

    Public Function Main() As Integer

        SpecifyTitle("Microsoft Visual Basic Application")

        Return 0
    End Function

End Module
 
 
     
 

Home Copyright © 2010-2016, FunctionX