Getting System.Exception: 'Incorrect function. (Exception from HRESULT: 0x80070001)' with MIDI in VB

0

I have run into an error (the latest of many) whilst trying (and failing) to program using the Windows.Devices.MIDI lib using VB (VS2019)

I started by taking the c# code from here .. https://blogs.windows.com/windowsdeveloper/2016/09/21/midi-enhancements-in-windows-10/ and now im trying to implement it in VB however i run into the following error which i cannot fathom -

System.Exception: 'Incorrect function. (Exception from HRESULT: 0x80070001)'

the error occurs when outPort.SendMessage(noteOnMessage) is executed in the MidiExample() sub

Any help on this issue would be greatly appreciated.

VB - visualstudio 2019, UWP desktop app

' Objects:
' Listview  - LstDev
' Textblock - txtData
' button    - btnSendMessage


  Imports Windows.Devices.Midi
  Imports Windows.Devices.Enumeration

Public NotInheritable Class MainPage
    Inherits Page

    Dim deviceList
    Dim deviceinfo


    Dim outportId As String = "0"
    Dim inPortId As String = "0"

    Dim watcher =DeviceInformation.CreateWatcher(MidiInPort.GetDeviceSelector())


Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
    '// load device list

    ListMidiDevices()

End Sub


Public Async Sub ListMidiDevices()
    '// list MIDI devices, add to ListView

    deviceList = Await DeviceInformation.FindAllAsync(MidiInPort.GetDeviceSelector())
    For Each deviceinfo In deviceList

        outportId = deviceinfo.id
        lstDev.Items.Add(deviceinfo.id.ToString)
        lstDev.Items.Add(deviceinfo.Name)
        lstDev.Items.Add("———-")
    Next

End Sub

Private Sub LstDev_SelectionChanged(sender As Object, e As SelectionChangedEventArgs) Handles lstDev.SelectionChanged
    '// Select hardware ID

    lblData.Text = lstDev.SelectedItem.ToString
    outportId = lblData.Text

End Sub

Private Async Sub MidiExample()
    '// send midi message 

    Dim noteOnMessage As New MidiNoteOnMessage(0, 110, 127)

    Dim outPort As MidiOutPort = Await MidiOutPort.FromIdAsync(outportId)

    ' outPort = Await MidiOutPort.FromIdAsync(outportId)

    outPort.SendMessage(noteOnMessage)


End Sub


Private Sub btnSendMessage_Click(sender As Object, e As RoutedEventArgs) Handles btnSendMessage.Click
    '// send message

    MidiExample()

End Sub

end class

vb.net
exception
uwp
iot
midi
asked on Stack Overflow Mar 20, 2021 by SLH2171

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0