用vb.net开发api viewer(4)

发表于:2007-06-30来源:作者:点击数: 标签:
在项目中添加新项---类(CTypes. vb ) 代码如下 Namespace API Public Class CTypes Implements IStore Dim TypeList As SortedList Dim TypeListCSharp As SortedList Sub New() TypeList = New SortedList() TypeListCSharp = New SortedList() End Sub Su
在项目中添加新项---类(CTypes.vb
代码如下
Namespace API
    Public Class CTypes
        Implements IStore
        Dim TypeList As SortedList
        Dim TypeListCSharp As SortedList
        Sub New()
            TypeList = New SortedList()
            TypeListCSharp = New SortedList()
        End Sub
        Sub Add(ByVal Key As String, ByVal Data As String, Optional ByVal bCSharp As Boolean = False) Implements IStore.Add
            If Not bCSharp Then
                If Not TypeList.ContainsKey(Key) Then
                    TypeList.Add(Key, Data)
                End If
            Else
                If Not TypeListCSharp.ContainsKey(Key) Then
                    TypeListCSharp.Add(Key, Data)
                End If
            End If
        End Sub

        Overloads Function GetData(ByVal Key As String) As String Implements IStore.GetData
            If TypeList.ContainsKey(Key) Then
                Return CType(TypeList.Item(Key), String)
            Else
                Return Nothing
            End If
        End Function
        Overloads Function GetData(ByVal index As Integer) As String Implements IStore.GetData
            If index < TypeList.Count Then
                Return CType(TypeList.GetByIndex(index), String)
            Else
                Return Nothing
            End If
        End Function
        ReadOnly Property Count() As Integer Implements IStore.Count
            Get
                Return TypeList.Count()
            End Get
        End Property
        ReadOnly Property GetKey(ByVal index As Integer) As String Implements IStore.GetKey
            Get
                If index < TypeList.Count Then
                    Return CType(TypeList.GetKey(index), String)
                Else
                    Return ""
                End If
            End Get
        End Property
        Overloads Function GetDataCSharp(ByVal Key As String) As String Implements IStore.GetDataCSharp
            If TypeListCSharp.ContainsKey(Key) Then
                Return CType(TypeListCSharp.Item(Key), String)
            Else
                Return Nothing
            End If
        End Function
        Overloads Function GetDataCSharp(ByVal index As Integer) As String Implements IStore.GetDataCSharp
            If index < TypeListCSharp.Count Then
                Return CType(TypeListCSharp.GetByIndex(index), String)
            Else
                Return Nothing
            End If
        End Function
    End Class
End Namespace
在项目中添加新项---类(FileHandling.vb)
代码如下
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic
Imports System.Threading

Namespace API
    Module FileHandling
        Public Const APISEPERATOR = " <@> "
        Public Const APISIZEOFARRAY = "SIZEOFARRAY"
        Public Const APILONG = "Long"
        Public Const APIINTEGER = "Integer"
        Public Const APISCOPE = "^^SCOPE^^ "
        Public Const APIPUBLIC = "Public "
        Public Const APIPRIVATE = "Private "
        Public Const APITYPE = "<StructLayout(LayoutKind.Sequential)> "
        Public Const APISTRING = "<MarshalAs(UnmanagedType.ByValTStr,SizeConst:=SIZEOFARRAY)>"
        Public Const APISTRUCT = "<MarshalAs(UnmanagedType.Struct)> ByRef "
        Public Const APIARRAY = "<MarshalAs(UnmanagedType.ByValArray,SizeConst:=SIZEOFARRAY)>"
        Public Const APIBYTEVB = "Byte"
        Public Const APIFLOATVB = "Double"
        Public Const APISTRVB = "String"
        Public Const APIANYVB = "Any"
        Public Const APISTRUCTUREVB = "Structure"
        Public Const APIBYREFVB = "ByRef"
        Public Const APIBYVALVB = "ByVal"

        Public Const APIDLLIMPORT = "<<DLLIMPORT>>"
        Public Const APIDLLIMPORTECSHARP = "[DllImport(<<DLLIMPORT>>)]"
        Public Const APITYPECSHARP = "[StructLayout(LayoutKind.Sequential)] "
        Public Const APISTRINGCSHARP = "[MarshalAs(UnmanagedType.ByValTStr,SizeConst:=SIZEOFARRAY)]"
        Public Const APISTRUCTCSHARP = "[MarshalAs(UnmanagedType.Struct)] ref "
        Public Const APIARRAYCSHARP = "[MarshalAs(UnmanagedType.ByValArray,SizeConst:=SIZEOFARRAY)]"
        Public Const APISTARTCSHARP = "static extern"
        Public Const APIPUBLICCSHARP = "public "
        Public Const APIPRIVATECSHARP = "private "
        Public Const APIINTEGERCSHARP = "int "
        Public Const APILONGCSHARP = "long "
        Public Const APIBYTECSHARP = "byte "
        Public Const APIFLOATCSHARP = "float "
        Public Const APISTRCSHARP = "string "
        Public Const APISTRUCTURECSHARP = "struct "
        Public Const APISTARTSCOPECSHARP = "{" + vbCrLf
        Public Const APIENDSCOPECSHARP = "}" + vbCrLf
        Public Const APIENDSTATEMENTCSHARP = ";" + vbCrLf
        Public Const APISEPERATORAS = " As "


        Public Const APISTARTCONST = "Const "
        Public Const APISTARTCOMMENT = "@#"
        Public Const APISTARTTYPE = "Type "
        Public Const APIENDTYPE = "End Type"
        Public Const APISTARTDECLARE = "Declare "
        Public Const CMB_CONSTANTS = "Constants"
        Public Const CMB_TYPES = "Types"
        Public Const CMB_DECLARES = "Declares"

        Public Types As CTypes
        Public Constants As CConst
        Public Declares As CDeclare
        Public frm As New frmViewer()

        Sub Main()
            frm.ShowDialog()
        End Sub
        Public Sub FillConstants()
            Dim i As Integer
            Monitor.Enter(frm)
            frm.lstItem.Items.Clear()
            For i = 0 To Constants.Count - 1
                Dim sKey As String
                sKey = Constants.GetKey(i)
                If sKey <> "" Then frm.lstItem.Items.Add(Constants.GetKey(i))
                @#Thread.Sleep(10)
            Next
            Monitor.Exit(frm)
        End Sub
        Public Sub FillDeclares()
            Dim i As Integer
            Monitor.Enter(frm)
            frm.lstItem.Items.Clear()
            For i = 0 To Declares.Count - 1
                Dim sKey As String
                sKey = Declares.GetKey(i)
                If sKey <> "" Then frm.lstItem.Items.Add(Declares.GetKey(i))
                @#Thread.Sleep(1)
            Next
            Monitor.Exit(frm)
        End Sub
        Public Sub FillTypes()
            Dim i As Integer
            Monitor.Enter(frm)
            frm.lstItem.Items.Clear()
            For i = 0 To Types.Count - 1
                Dim sKey As String
                sKey = Types.GetKey(i)
                If sKey <> "" Then frm.lstItem.Items.Add(Types.GetKey(i))
                @#Thread.Sleep(1)
            Next
            Monitor.Exit(frm)
        End Sub
    End Module
End Namespace
在代码中添加新项--类(IStore.vb)
代码如下
Namespace API
    Public Interface IStore
        Sub Add(ByVal Key As String, ByVal Data As String, Optional ByVal bCSharp As Boolean = False)
        ReadOnly Property Count() As Integer
        Overloads Function GetData(ByVal index As Integer) As String
        Overloads Function GetData(ByVal Key As String) As String
        ReadOnly Property GetKey(ByVal index As Integer) As String
        Overloads Function GetDataCSharp(ByVal Key As String) As String
        Overloads Function GetDataCSharp(ByVal index As Integer) As String
    End Interface
End Namespace

原文转自:http://www.ltesting.net