Click here to Skip to main content
Click here to Skip to main content
Go to top

VB 9.0, C# 3.0 API Viewer

, 24 May 2012
Rate this:
Please Sign up or sign in to vote.
This is a remake of Pramod Kumar Sing's 2002 API Viewer.

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. Smile | :) 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:

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:

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.

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:

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.

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.

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:

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)

Share

About the Author

rspercy65
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 PinmemberMember 999349622-Apr-13 21:57 
QuestionMessage Removed PinmemberLe Silencieux27-Mar-13 1:52 
AnswerRe: Please explain Pinmemberrspercy6527-Mar-13 4:41 
GeneralRe: Please explain PinmemberLe Silencieux28-Mar-13 19:21 
QuestionInt vs. UInt / Long vs. IntPtr Pinmemberjma240021-May-12 2:49 
AnswerRe: Int vs. UInt / Long vs. IntPtr Pinmemberrspercy6521-May-12 12:02 
GeneralMy vote of 4 Pinmembermanoj kumar choubey24-Feb-12 1:34 
Nice
GeneralMy vote of 3 PinmemberBigdeak17-Aug-10 3:18 
Questionhttp://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable? Pinmemberxiakunpeng25-Jul-10 6:04 
AnswerRe: http://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable? Pinmemberrspercy6025-Jul-10 6:09 
Generalmissing API text file Pinmemberarcticbrew19-Jul-10 9:33 
GeneralRe: missing API text file Pinmemberrspercy6019-Jul-10 23:42 
GeneralRe: missing API text file Pinmemberrspercy6020-Jul-10 0:06 
GeneralMy vote of 5 PinmemberDigital Thunder19-Jul-10 1:24 
QuestionRedundant Code? PinmemberDigital Thunder14-Jul-10 9:26 
AnswerRe: Redundant Code? Pinmemberrspercy6014-Jul-10 9:33 
GeneralRe: Redundant Code? PinmemberDigital Thunder14-Jul-10 9:39 
Generalnice background color Pinmemberfreakyit9-Jul-10 10:11 
GeneralRe: nice background color Pinmemberrspercy609-Jul-10 13:44 
GeneralRe: nice background color Pinmembernewbius14-Jul-10 9:20 
GeneralRe: nice background color PinmemberDigital Thunder14-Jul-10 9:27 
GeneralRe: nice background color Pinmemberrspercy6014-Jul-10 9:35 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140922.1 | Last Updated 24 May 2012
Article Copyright 2010 by rspercy65
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid