waveOutGetDevCaps in .net (Upgrade from VB6)

L

LongShotBuddy

Howdy,

I've tried everything (but the right thing obviously) to get the
following to work, I'm sure it has something to do with the changes
from VB6 to .net, but sure has me stumped, any suggestions? It's not
populating the WAVEOUTCAPS structure, and GetLastError returns "Error
#126"

Thanks!

Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Integer
Declare Function waveOutGetDevCaps Lib "winmm.dll"_
Alias "waveOutGetDevCapsA" (ByVal uDeviceID As_
Integer, ByVal lpCaps As WAVEOUTCAPS, ByVal_
uSize As Integer) As Integer

(snip)

Private Const MAXPNAMELEN = 32

Structure WAVEOUTCAPS
Public wMid As Int16 ' integer
Public wPid As Int16 ' integer
Public vDriverVersion As Int32 ' long
<VBFixedString(MAXPNAMELEN)> Public szPname As String
Public dwFormats As Int32 ' long
Public wChannels As Int16 ' integer
Public dwSupport As Int32 ' long
End Structure

(snip)

Public Shared Sub GetWaveOutDevices()

Dim NumDevs As Integer
Dim WaveFormat As WAVEOUTCAPS
Dim i As Integer
Dim result As Integer

NumDevs = waveOutGetNumDevs()

For i = 0 To NumDevs - 1

result = (waveOutGetDevCaps(i, WaveFormat,
Len(WaveFormat)))
'(result = 0)
Next

End sub
 
J

James Lang

Hi
This is a long shot but try taking the alias out of the api declare
statement ( I cant remember where I read this, and haven't tried it myself )

Regards
James
 
T

Tom Shelton

Howdy,

I've tried everything (but the right thing obviously) to get the
following to work, I'm sure it has something to do with the changes
from VB6 to .net, but sure has me stumped, any suggestions? It's not
populating the WAVEOUTCAPS structure, and GetLastError returns "Error
#126"

Thanks!

Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Integer
Declare Function waveOutGetDevCaps Lib "winmm.dll"_
Alias "waveOutGetDevCapsA" (ByVal uDeviceID As_
Integer, ByVal lpCaps As WAVEOUTCAPS, ByVal_
uSize As Integer) As Integer

Your declate for waveOutGetDevCaps is wrong... Should be:

Declare Auto Function waveOutGetDevCaps Lib "winmm.dll" _
(ByVal uDeviceID As Integer, _
ByRef lpCaps As WAVEOUTCAPS, _
ByVal uSize As Integer) AS Integer
(snip)

Private Const MAXPNAMELEN = 32

Structure WAVEOUTCAPS
Public wMid As Int16 ' integer
Public wPid As Int16 ' integer
Public vDriverVersion As Int32 ' long
<VBFixedString(MAXPNAMELEN)> Public szPname As String
Public dwFormats As Int32 ' long
Public wChannels As Int16 ' integer
Public dwSupport As Int32 ' long
End Structure

Your Structure is wrong as well.. VBFixedString is not for interop.. And
you'll need to set the CharSet attribute on the structure as well.
Also, it looks like you forgot a field.

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _
Structure WAVEOUTCAPS
Public wMid As Short
Public wPid As Short
Public vDriverVersion As Integer

<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAXPNAMELEN)> _
Public szPname As String

Public dwFormats As Integer
Public wChannels As Short
public wReserved1 As Short
public dwSupport As Integer
End Structure
(snip)

Public Shared Sub GetWaveOutDevices()

Dim NumDevs As Integer
Dim WaveFormat As WAVEOUTCAPS
Dim i As Integer
Dim result As Integer

NumDevs = waveOutGetNumDevs()

For i = 0 To NumDevs - 1
result = (waveOutGetDevCaps(i, WaveFormat, Marshal.SizeOf(WaveFormat)))
'(result = 0)
Next

End sub


HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top