Desktop Functions:

   Smart Device Functions:

Show Recent Changes
Subscribe (RSS)
Misc. Pages
Helpful Tools
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
UnRegisterTypeLib (oleaut32)
The UnRegisterTypeLib function removes type library information from the system registry. Use this API to allow applications to properly uninstall themselves. In-process objects typically call this API from "DllUnregisterServer".

C# Signature:

[DllImport("oleaut32.dll", EntryPoint = "UnRegisterTypeLib", CharSet = CharSet.Auto, SetLastError = true)]
    private static extern int UnRegisterTypeLib(
        ref Guid libID,
        short wVerMajor,
        short wVerMinor,
        int lCID,
        SYSKIND tSysKind);

VB.Net Signatures:

Declare Unicode Function UnRegisterTypeLib Lib "oleaut32.dll" (ByRef LibID As System.Guid, ByVal nVerMajor As Short, ByVal nVerMinor As Short, ByVal lCID As Integer, ByVal tSysKind As System.Runtime.InteropServices.ComTypes.SYSKIND) As Integer

VB 6 Signature:

Declare Function UnRegisterTypeLib Lib "oleaut32.dll" (LibID As tGUID, ByVal nVerMajor As Integer, ByVal nVerMinor As Integer, ByVal lCID As Long, ByVal tSysKind As eSYSKIND) As Long

User-Defined Types:

Type tGUID
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(0 To 7) As Byte
End Type

    SYS_WIN16 = 0&
    SYS_WIN32 = 1&
    SYS_MAC = 2&
    SYS_WIN64 = 3&
End Enum

Alternative Managed API:

Do you know one? Please contribute it!


In VB.Net you can substitute System.Runtime.InteropServices.SYSKIND for System.Runtime.InteropServices.ComTypes.SYSKIND, defined in mscorlib.dll.

Note that in v2.0 (Whidbey) of the .NET Framework, the System.Runtime.InteropServices.SYSKIND interface has been deprecated in favor of System.Runtime.InteropServices.ComTypes.SYSKIND.

Tips & Tricks:

Please add some!

Sample Code:

'VB.Net  Register or Unregister a Type Library file
    Private Declare Unicode Function LoadTypeLib Lib "oleaut32.dll" (ByVal TLpszModule As String, ByRef TPpTypeLib As ComTypes.ITypeLib2) As Integer
    Private Declare Unicode Function RegisterTypeLib Lib "oleaut32.dll" (ByVal ptlib As ComTypes.ITypeLib2, ByVal szFullPath As String, ByVal szHelpDir As String) As Integer
    Private Declare Unicode Function UnRegisterTypeLib Lib "oleaut32.dll" (ByRef LibID As System.Guid, ByVal nVerMajor As Short, ByVal nVerMinor As Short, ByVal lCID As Integer, ByVal tSysKind As ComTypes.SYSKIND) As Integer

    Private Const ERROR_SUCCESS As Short = 0

    Public Function RegisterTLib(ByVal strFile As String, ByVal bRegister As Boolean) As Boolean
        Dim nResult As Integer
        Dim TLB As ComTypes.ITypeLib2 = Nothing
        Dim tlbAttrPtr As IntPtr
        Dim tlbAttr As ComTypes.TYPELIBATTR

        On Error Resume Next

        If My.Computer.FileSystem.FileExists(strFile) = False Then
            RegisterTLib = False
            nResult = LoadTypeLib(strFile, TLB)

            If nResult = ERROR_SUCCESS Then
                If bRegister Then
                    nResult = RegisterTypeLib(TLB, strFile, Nothing)

                    If nResult = ERROR_SUCCESS Then 'success
                        RegisterTLib = true
                    Else 'failure
                        RegisterTLib = False
                    End If
                    tlbAttr = CType(Marshal.PtrToStructure(tlbAttrPtr, GetType(ComTypes.TYPELIBATTR)), ComTypes.TYPELIBATTR)

                    nResult = UnRegisterTypeLib(tlbAttr.guid, tlbAttr.wMajorVerNum, tlbAttr.wMinorVerNum, tlbAttr.lcid, tlbAttr.syskind)
                    tlbAttr = Nothing

                    If nResult = ERROR_SUCCESS Then 'success
                        RegisterTLib = True
                    Else 'failure
                        RegisterTLib = False
                    End If
                End If
            Else ' error loading the TypeLibrary file
                RegisterTLib = False
            End If
        End If
    End Function


Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

Access directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version