Click here to Skip to main content
15,860,861 members
Articles / General Programming / File

VB 9.0, C# 3.0 API Viewer

Rate me:
Please Sign up or sign in to vote.
4.35/5 (10 votes)
24 May 2012CPOL5 min read 79.5K   4.2K   42   22
This is a remake of Pramod Kumar Sing's 2002 API Viewer.

Image 1

Introduction

Have you been looking for an API viewer for VB 9 and C# 3? Has the old API viewers not been able to work in Vista® or Windows 7®? VSAPIVIEWER is a remake of Pramod Kumar Singh's 2002 API Viewer. Pramod's version, I believe, was written in VB.NET 7.0®.

As I was searching for an API viewer, I came across a lot of questions in the MSDN forums that were asking if anyone knew of a site where they could get a current API viewer for VS 2008®, and the answer was always "No". I believe that this is a well needed utility.

Background

After I had downloaded Pramod's app and started to read his code, I started to finally get hold of what he was trying to do.

Dissecting the old app to the new

If you look at Pramod's actual form, you will see that I tried to keep mine pretty much the same, except some of the controls are in different locations and I changed the color back to Control. :) Updating the data file from WIN32API.txt to API32.txt was a chore. API32.txt is two times larger than the WIN32API.txt file. I could not get it to load during the application start-up. I couldn't figure out the reason for this, so I broke the API32.txt file into four different, smaller files (which are included) in the Bin\Debug\API\ folder. This seemed to work very well, so I stuck with it.

Loading the API files!

The constants, functions, subs, and types are loaded when the app starts. A splash-screen (written by Digital Thunder), and changed to accommodate this app, displays what is being loaded. This is done from within the Form_Load event. The code is given below:

VB
Private Sub frmViewerNet_Load(ByVal sender As Object, _
            ByVal e As System.EventArgs) Handles Me.Load

    FormSplash.Status("Loading Constants!")
    LoadConstants()

    FormSplash.Status("Loading Functions!")
    LoadFunctions()

    FormSplash.Status("Loading Subs!")
    LoadSubs()

    FormSplash.Status("Loading Types!")
    LoadTypes()
End Sub

The splash-screen is updated on a different thread via Private Delegate Sub UpdateStatus(ByVal text As String). The FormSplash.Status sub takes a string (code above) to display what we are doing, then we just call the sub or function that does the work that we want. The subs being called in the above code are all pretty much the same code. Here is one sub's code:

VB
Public Sub LoadConstants()
    Dim m As RSP.ParseAPI = New RSP.ParseAPI(strFile1)
    Dim ThreadConst As Thread

    RSP.Constants = New RSP.CConst()

    ThreadConst = New Thread(AddressOf m.GetConstInfo)
    ThreadConst.Start()

    Try
        ThreadConst.Join()
    Catch e As Exception
        MessageBox.Show("Error occured reading file..." & vbCrLf & strFile1, _
                        "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try

    Thread.Sleep(250)
End Sub

The ParseAPI class is where ninety percent or so of the work is done. This is where we open up a file, one of the four API32 text files, for reading, searching, and adding the constants that are found in the module FileHandling.vb which contains 50 public constants that we use in our code for VB® or C#®. One of the subs in the ParseAPI class file is Public Sub GetConstInfo(). The code for this is below.

VB
Public Sub GetConstInfo()
    Dim sKey As String
    Dim sCSharp As String

    If pFile <> "" Then
        If Not File.Exists(pFile) Then
            Types = Nothing
            Return
        End If

        Dim sr As StreamReader = File.OpenText(pFile)
        Dim input As String

        input = sr.ReadLine()

        While Not input Is Nothing
            If InStr(1, input, APISTARTCONST) <> 0 Then
                'Check for the Comment
                If Not input.StartsWith("'") Then
                    'Look Ahead for false data
                    If Split(input, "=").Length() <= 2 Then
                        sKey = Split(input, " ")(1).ToString()
                        input = APISCOPE & input
                        sCSharp = input
                        sCSharp = sCSharp.Replace("Const", "const int") + ";"
                        sCSharp = sCSharp.Replace("'", "//")
                        Constants.Add(sKey, input)
                        Constants.Add(sKey, sCSharp, True)
                    End If
                End If
            End If
            input = sr.ReadLine()
        End While
        sr.Close()
        Return
    Else
        Return
    End If
End Sub

After all the data that is found in the four API files is stored in the app, and the app is finally displayed, we finally get to use it.

One important part of the application that was pointed out to me was if someone accidentally pressed the Add button twice, duplicates were added. Deleting these out manually is somewhat time consuming, so I came up with this code:

VB
Private Sub btnAdd_Click(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles btnAdd.Click

    If lstItems.Items.Count > 0 Then
        Select Case cmbAPI.Text
            Case RSP.CMB_TYPES, RSP.CMB_CONSTANTS, RSP.CMB_DECLARES, RSP.CMB_SUBS
                If txtSelectedItems.Text = "" Then
                    Exit Sub
                Else
                    strTemp = Trim(txtSelectedItems.Text)
                    If InStr(txtAddSelected.Text(), strTemp) > 0 Then
                    'Checking for duplicates.
                        MessageBox.Show("Selection already exists...", "Oops!", _
                             MessageBoxButtons.OK, MessageBoxIcon.Information)
                        txtSelectedItems.Text = ""  'Clearing the textbox.
                    Else
                        txtAddSelected.Text += txtSelectedItems.Text & vbCrLf & vbCrLf
                        txtSelectedItems.Text = ""  'Clearing the textbox.
                    End If
                End If
            Case Else
        End Select
    End If
End Sub

The first thing that we do is check to see if the ListBox has any items in it. If so, we continue. We then check the Combobox's text. It doesn't matter if it is "Constants", "Declares", "Subs", or "Types". It will check for any type of duplicate. If we find a duplicate, then we display a MessageBox (shown below) to the user telling that we have found a duplicate and that we are erasing it from the TextBox. If no duplicates are found, then we add it to the correct TextBox.

VSAPIVIEWER/_A_Alert.png

Classes

The CConst, CDeclare, CSubs, and CTypes classes have pretty much the same properties and variables. Here is a list of the class properties and variables. They all implement the IStore Interface.

Properties

  • ReadOnly Property Count() As Integer Implements IStore.Count
  • ReadOnly Property GetKey(ByVal index As Integer) As String Implements IStore.GetKey
  • Overloads Function GetDataCSharp(ByVal Key As String) As String Implements IStore.GetDataCSharp
  • Overloads Function GetDataCSharp(ByVal index As Integer) As String Implements IStore.GetDataCSharp

Variables and class files they are in

  • Dim ConstList As SortedList.............CConst.vb
  • Dim ConstListCSharp As SortedList.......CConst.vb
  • Dim DeclareList As SortedList...........CDeclare.vb
  • Dim DeclareListCSharp As SortedList.....CDeclare.vb
  • Dim TorpedoeList As SortedList..........CSubs.vb
  • Dim TorpedoeListCSharp As SortedList....CSubs.vb
  • Dim TypeList As SortedList..............CTypes.vb
  • Dim TypeListCSharp As SortedList........CTypes.vb

Duplicate code

While going through the old API Viewer code, I noticed an awful lot of duplicate code in all the radio buttons, combo, and listboxes. As I did not understand why all this duplicate code was in there, a friend told me to delete it all out and start from scratch. This was done and the cmbAPI_SelectedIndexChanged (code below) was created using the old code from two different places. The Select Case statement is from the original combobox.click event, and the code inside the Case statements is from the FileHandling.vb file.

VB
Private Sub cmbAPI_SelectedIndexChanged(ByVal sender As Object, _
        ByVal e As System.EventArgs) Handles cmbAPI.SelectedIndexChanged

    txtSelectedItems.Text = ""
    'Load the listbox from the selected arrayed strings.
    Select Case cmbAPI.Text
        Case RSP.CMB_CONSTANTS
            lstItems.Items.Clear()
            For i As Integer = 0 To RSP.Constants.Count - 1
                Dim sKey As String
                sKey = RSP.Constants.GetKey(i)
                If sKey <> "" Then lstItems.Items.Add(RSP.Constants.GetKey(i).ToString())
            Next
        Case RSP.CMB_DECLARES
            lstItems.Items.Clear()
            For i As Integer = 0 To RSP.Declares.Count - 1
                Dim sKey As String
                sKey = RSP.Declares.GetKey(i)
                If sKey <> "" Then lstItems.Items.Add(RSP.Declares.GetKey(i).ToString())
            Next
        Case RSP.CMB_TYPES
            lstItems.Items.Clear()
            For i As Integer = 0 To RSP.Types.Count - 1
                Dim sKey As String
                sKey = RSP.Types.GetKey(i)
                If sKey <> "" Then lstItems.Items.Add(RSP.Types.GetKey(i).ToString())
            Next
        Case RSP.CMB_SUBS
            lstItems.Items.Clear()
            For i As Integer = 0 To RSP.Torpedoes.Count - 1
                Dim sKey As String
                sKey = RSP.Torpedoes.GetKey(i)
                If sKey <> "" Then lstItems.Items.Add(RSP.Torpedoes.GetKey(i).ToString())
            Next
        Case Else

    End Select

End Sub

This is a simple routine for searching a listbox with typed text in a TextBox.

VB
Private Sub txtSearch_TextChanged(ByVal sender As Object, _
                ByVal e As System.EventArgs) Handles txtSearch.TextChanged
    If lstItems.Items.Count > 0 Then
        lstItems.SelectedIndex = lstItems.FindString(txtSearch.Text)
    End If
End Sub

Copy the text for pasting in your code:

VB
Private Sub btnCopy_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles btnCopy.Click
    Clipboard.SetText(txtAddSelected.Text)  'Add text to clipboard for pasting.
End Sub

I added an Online Help with the use of the WebControl. When an Item is clicked in the listbox, It automatically does a Google search. Now all you have todo is find a good corresponding link that will help you if you do not know how to use the currently selected API.

That's all folks. Hope all of you can make use of this application.

History

  • Uploaded project on 07/09/2010.
  • Updated project and article on 07/18/2010.
  • Updated project and article on 05/24/2012.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Retired
United States United States
I am currently retired.
I have no degree but I have some programming experience
when I was in college(Cobol, Pascal).

My accomplishments thus far are;
Best VB.Net article for January(2009)
Best VB.Net article for July(2009)

Comments and Discussions

 
Questionneed help Pin
Member 999349622-Apr-13 21:57
Member 999349622-Apr-13 21:57 
QuestionMessage Closed Pin
27-Mar-13 1:52
Le Silencieux27-Mar-13 1:52 
AnswerRe: Please explain Pin
rspercy6527-Mar-13 4:41
rspercy6527-Mar-13 4:41 
GeneralRe: Please explain Pin
Le Silencieux28-Mar-13 19:21
Le Silencieux28-Mar-13 19:21 
QuestionInt vs. UInt / Long vs. IntPtr Pin
jma240021-May-12 2:49
jma240021-May-12 2:49 
AnswerRe: Int vs. UInt / Long vs. IntPtr Pin
rspercy6521-May-12 12:02
rspercy6521-May-12 12:02 
GeneralMy vote of 4 Pin
Manoj Kumar Choubey24-Feb-12 1:34
professionalManoj Kumar Choubey24-Feb-12 1:34 
GeneralMy vote of 3 Pin
Bigdeak17-Aug-10 3:18
Bigdeak17-Aug-10 3:18 
Questionhttp://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable? Pin
xiakunpeng25-Jul-10 6:04
xiakunpeng25-Jul-10 6:04 
AnswerRe: http://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable? Pin
rspercy6525-Jul-10 6:09
rspercy6525-Jul-10 6:09 
Generalmissing API text file Pin
arcticbrew19-Jul-10 9:33
arcticbrew19-Jul-10 9:33 
GeneralRe: missing API text file Pin
rspercy6519-Jul-10 23:42
rspercy6519-Jul-10 23:42 
GeneralRe: missing API text file Pin
rspercy6520-Jul-10 0:06
rspercy6520-Jul-10 0:06 
Here is a link to the complete file.
ViewerNet.zip[^]
rspercy
1 + 1 = 184,000, Depending on the species.

GeneralMy vote of 5 Pin
Euhemerus19-Jul-10 1:24
Euhemerus19-Jul-10 1:24 
QuestionRedundant Code? Pin
Euhemerus14-Jul-10 9:26
Euhemerus14-Jul-10 9:26 
AnswerRe: Redundant Code? Pin
rspercy6514-Jul-10 9:33
rspercy6514-Jul-10 9:33 
GeneralRe: Redundant Code? Pin
Euhemerus14-Jul-10 9:39
Euhemerus14-Jul-10 9:39 
Generalnice background color Pin
freakyit9-Jul-10 10:11
freakyit9-Jul-10 10:11 
GeneralRe: nice background color Pin
rspercy659-Jul-10 13:44
rspercy659-Jul-10 13:44 
GeneralRe: nice background color Pin
newbius14-Jul-10 9:20
newbius14-Jul-10 9:20 
GeneralRe: nice background color Pin
Euhemerus14-Jul-10 9:27
Euhemerus14-Jul-10 9:27 
GeneralRe: nice background color Pin
rspercy6514-Jul-10 9:35
rspercy6514-Jul-10 9:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.