Imports System.Runtime.InteropServices

Public Class VFW
    Public Shared Sub ShowEncoderForm(ByVal fccCode As String, ByVal owner As IntPtr)
        Dim hic As Integer = GetEncoderHandle(fccCode, ICMODE.QUERY)
        ICSendMessage(hic, ICM.CONFIGURE, owner, 0)
        ICClose(hic)
    End Sub

    Public Shared Function GetEncoderHandle(ByVal fccCode As String, ByVal mode As ICMODE) As Integer
        Dim fccType, fccHandler As Integer
        fccType = mmioStringToFOURCC("vidc", MMIO.TOUPPER)
        fccHandler = mmioStringToFOURCC(fccCode, MMIO.TOUPPER)
        Return ICOpen(fccType, fccHandler, mode)
    End Function

    Public Shared Sub ShowAboutDialog(ByVal fourCC As String, ByVal handle As IntPtr)
        Dim h As Integer = GetEncoderHandle(fourCC, ICMODE.QUERY)
        ICSendMessage(h, ICM.ABOUT, handle, 0)
        ICClose(h)
    End Sub

    Public Enum ICMODE
        QUERY = 4
    End Enum

    Public Enum ICM
        GETSTATE = 20480
        SETSTATE = 20481
        CONFIGURE = 20490
        ABOUT = &H4000 + &H1000 + 11
    End Enum

    Public Enum MMIO
        TOUPPER = 16
    End Enum

    <DllImport("msvfw32.dll")> _
    Public Shared Function ICClose(ByVal hic As Integer) As Integer
    End Function

    <DllImport("msvfw32.dll")> _
    Private Shared Function ICOpen(ByVal fccType As Integer, ByVal fccHandler As Integer, ByVal wMode As Integer) As Integer
    End Function

    <DllImport("msvfw32.dll")> _
    Private Shared Function ICSendMessage(ByVal hic As Integer, ByVal msg As ICM, ByVal dw1 As IntPtr, ByVal dw2 As Integer) As Integer
    End Function

    <DllImport("winmm.dll")> _
    Private Shared Function mmioStringToFOURCC(ByVal sz As String, ByVal uFlags As Integer) As Integer
    End Function
End Class