Imports System
Imports COMTLI = System.Runtime.InteropServices.ComTypes
Imports System.Runtime.InteropServices

' This class implements the TLBINF32 methods used
'  by the ScanTool sample.  It was created by adding content
'  onto the stub class authored by gmStudio for 
'  ScanToolLib.
Namespace TLI
	''' <summary>
	''' PInvoke methods.
	''' </summary>
	Friend Class NativeMethods
		<DllImport("oleaut32.dll", CharSet := CharSet.Unicode, PreserveSig := False)> _
		Friend Shared Function LoadTypeLibEx(szFile As String, regkind As REGKIND) As COMTLI.ITypeLib
		End Function
	End Class

	' REGKIND enumeration used by LoadTypeLibEx
	Friend Enum REGKIND
		REGKIND_DEFAULT = 0
		REGKIND_REGISTER = 1
		REGKIND_NONE = 2
	End Enum

	Public Class TypeLibInfo

		Private typLib As COMTLI.ITypeLib = Nothing

		Public Sub New(newTypeLibInfo As COMTLI.ITypeLib)
			typLib = newTypeLibInfo
		End Sub

		Public ReadOnly Property Name() As String
			Get
				Return Marshal.GetTypeLibName(typLib)
			End Get
		End Property
		Public ReadOnly Property GUID() As String
			Get
				Dim fmtGUID As String = "{" & Marshal.GetTypeLibGuid(typLib).ToString().ToUpper() & "}"
				Return fmtGUID
			End Get
		End Property
	End Class
	Public Class TLIApplication

    Public Function TypeLibInfoFromFile(FileName As String) As TLI.TypeLibInfo
        Return New TLI.TypeLibInfo(NativeMethods.LoadTypeLibEx(FileName, REGKIND.REGKIND_NONE))
    End Function

	End Class
	Public Enum TliErrors
		tliErrNoCurrentTypelib = -2147220991
		tliErrCantLoadLibrary = -2147312566 ' COM was -2147220990, Win32 API returns a different exception number
		tliErrTypeLibNotRegistered = -2147220989
		tliErrSearchResultsChanged = -2147220988
		tliErrNotApplicable = -2147220987
		tliErrIncompatibleData = -2147220986
		tliErrIncompatibleSearchType = -2147220985
		tliErrIncompatibleTypeKind = -2147220984
		tliErrInaccessibleImportLib = -2147220983
		tliErrNoDefaultValue = -2147220982
		tliErrDataNotAvailable = -2147220981
		tliErrNotAnEntryPoint = -2147220980
		tliErrStopFiltering = -2147220979
		tliErrArrayBoundsNotAvailable = -2147220978
		tliErrSearchResultsNotSorted = -2147220977
		tliErrTypeNotArray = -2147220976
	End Enum
End Namespace
