Click here to Skip to main content
Click here to Skip to main content

VB 9.0, C# 3.0 API Viewer

By , 24 May 2012
 

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:

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)

About the Author

rspercy65
Retired
United States United States
Member
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)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionneed helpmemberMember 999349622 Apr '13 - 21:57 
do you know about .sdf files? sdf is a sql database for mobile devices (sql compact version)
i am going to make a sdf viewer but i dont know where to start.
can you help me?
i need to make a sdf viewer application using vb.net (window-based)
QuestionMessage RemovedmemberLe Silencieux27 Mar '13 - 1:52 
Message Removed
AnswerRe: Please explainmemberrspercy6527 Mar '13 - 4:41 
sKey is equal to parts 1 of the input string.
Example...
input = "1010 0101"
skey = Split(input, " ")(1).ToString
 
(1).ToString is equal to "0101" and is passed to skey.
 
input is split into 2 parts in this ex. using a space as the delimiter.
There could also be any number of parts(n) in the string
you are splitting. The index number for the Split command
always starts at 0(zero).
 
"1010" is parts 0, " "(space) is the delimiter, "0101" is parts 1
therefore skey is equal to "0101" or in this case '(1).ToString'
End Example...
 
Hope this helped you.
rspercy65

GeneralRe: Please explainmemberLe Silencieux28 Mar '13 - 19:21 
Thank you so much, I just realized it yesterday.
QuestionInt vs. UInt / Long vs. IntPtrmemberjma240021 May '12 - 2:49 
Is there an updated API32.txt using e.g. (the correct) IntPtr arguments instead of 'Long'?
Jens
AnswerRe: Int vs. UInt / Long vs. IntPtrmemberrspercy6521 May '12 - 12:02 
I currently do not know.
There is a real good API viewer at Planet-Source-Code[^]. Wether or not it does the changes you asked and shown, I dont know. But you can go to the site and check it out.
 
I have thought about going over the whole file and changing what you are asking. That would be a good days work and it would give me something todo.
 

P.S. I will get back to you when I finish with it. I decided to do all the changes that
need to be changed.
rspercy65

GeneralMy vote of 4membermanoj kumar choubey24 Feb '12 - 1:34 
Nice
GeneralMy vote of 3memberBigdeak17 Aug '10 - 3:18 
Very nice approach, it could be really useful for me if i need some Api functions. But at the moment it need some improvements to be helpful.
 
Instead of using text files for the list of Api Const, Functions, Subs and Types, a xml file or a database (maybe sqlite) should be in use, so there is more freedom for upgrade the Api Viewer.
 
A multi selection of the items would be nice, so i can get the source code for more than one entry in one step.
Searching of the single functions is a good approach too, but i think filtering to the search result would be more helpful.
 
There is a lot of potential to make a really helpful and nice Api lexicon Tool out of it, maybe in a high state it could be a saleable tool.
Questionhttp://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable?memberxiakunpeng25 Jul '10 - 6:04 
it seemed that i can not down load file from this link,still in status missing text file.
AnswerRe: http://dl.dropbox.com/u/2291617/ViewerNet.zip seemed unvailable?memberrspercy6025 Jul '10 - 6:09 
I just downloaded from both sites and all files are in zip files.
Re-download from codeproject.
Sorry for this inconvienience.
rspercy
A roll of toilet paper has more value than a 4 year
computer science degree.

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 24 May 2012
Article Copyright 2010 by rspercy65
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid