none
winmm waveOutGetDevCaps channels count RRS feed

  • Question

  • Hey guys.

        I am working on splitting my devices into single or mono channels.  Trouble is I can't get an accurate result from the channels variable in the structure.  I was using a preset size of 64 to get the name,  but it must not be big enough to get the last components of the structure.  However,  when I use code (Marshal.Sizeof(my structure)) I get a number that can't be correct. Here is the code snips.

       <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)>
        Public Structure WAVEDEVINFO
            ''' <summary>Manufacturer identifier for the device driver for the device. Manufacturer identifiers are defined in Manufacturer and Product Identifiers.</summary>
            Public wMid As Short
            ''' <summary>Product identifier for the device. Product identifiers are defined in Manufacturer and Product Identifiers.</summary>
            Public wPid As Short
            ''' <summary>Version number of the device driver for the device. The high-order byte is the major version number, and the low-order byte is the minor version number.</summary>
            Public vDriverVersion As Integer
            ''' <summary>Product name in a null-terminated string.</summary>
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Public szPname As String
            ''' <summary>Standard formats that are supported. Can be a combination of the WaveFormats enumeration.</summary>
            Public dwFormats As WaveFormats
            ''' <summary>Number specifying whether the device supports mono (1) or stereo (2) output.</summary>
            Public wChannels As Short
            ''' <summary>Reserved for packing.</summary>
            Public wReserved1 As UShort
            ''' <summary>Optional functionality supported by the device. The following values are defined</summary>
            Public dwSupport As WaveCapSupportFlags
        End Structure
    
    
    
    
      <DllImport("winmm.dll", EntryPoint:="waveInGetDevCaps")>
        Public Shared Function waveInGetDevCaps(ByVal uDeviceID As Integer, ByRef lpWaveInCaps As WAVEDEVINFO, ByVal cbWaveInCaps As Integer) As Integer
        End Function
    
    
    
    
    Public Shared wInInfo As WAVEDEVINFO
    
    Public Sub Button_click()
    
    Dim f as integer = 0
    
    retVal = waveInGetDevCaps(f, wInInfo, 64)
    
    
    '  tried '
    ' retVal = waveInGetDevCaps(f, wInInfo, Marshal.SizeOf(wInInfo)) '
    
    Dim N as String = wInInfo.szPname
    
    '  this is not getting the value right '
    Dim NumOfCh as Integer = wInInfo.wChannels
    
    End Sub
    
    

    Any ideas??

     

    Saturday, March 23, 2019 11:22 PM

Answers

  • It works for me with :

        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
        Public Structure WAVEINCAPS
            Public wMid As Short
            Public wPid As Short
            Public vDriverVersion As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)>
            Public szPname As String
            Public dwFormats As Integer
            Public wChannels As Short
            Public wReserved As Short
        End Structure

    (size of structure = 80)

    (szPname is truncated by also in C++)


    • Edited by Castorix31 Sunday, March 24, 2019 1:01 AM
    • Marked as answer by -tE Sunday, March 24, 2019 1:45 AM
    Sunday, March 24, 2019 12:59 AM

All replies

  • It works for me with :

        <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)>
        Public Structure WAVEINCAPS
            Public wMid As Short
            Public wPid As Short
            Public vDriverVersion As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=32)>
            Public szPname As String
            Public dwFormats As Integer
            Public wChannels As Short
            Public wReserved As Short
        End Structure

    (size of structure = 80)

    (szPname is truncated by also in C++)


    • Edited by Castorix31 Sunday, March 24, 2019 1:01 AM
    • Marked as answer by -tE Sunday, March 24, 2019 1:45 AM
    Sunday, March 24, 2019 12:59 AM
  • Awesome.  Works!
    Sunday, March 24, 2019 1:45 AM