WaveInOpen API function Problem

  • Thread starter Sakharam Phapale
  • Start date
S

Sakharam Phapale

Hi All,

I have written following code, but waveInOpen API call gives me error no 32.
Can anyone help me to solve this?


Public Delegate Function callback(ByVal hw As Integer, ByVal uMsg As
Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

Public Const CALLBACK_FUNCTION = &H30000

Structure WAVEFORMAT

Dim wFormatTag As Integer

Dim nChannels As Integer

Dim nSamplesPerSec As Integer

Dim nAvgBytesPerSec As Integer

Dim nBlockAlign As Integer

Dim wBitsPerSample As Integer

Dim cbSize As Integer

End Structure



Declare Function waveInOpen Lib "winmm.dll" (ByRef lphWaveIn As IntPtr, _

ByVal uDeviceID As Integer, ByRef lpFormat As WAVEFORMAT, _

ByVal dwCallback As callback, ByVal dwInstance As Integer, _

ByVal dwFlags As Integer) As Integer



Dim Wfmt As WAVEFORMAT

Dim WHdr As WAVEHDR

Dim intWaveIn As IntPtr

Dim intDevID As Integer = 0

Dim intRet As Integer

With Wfmt

..wFormatTag = 1

..nChannels = 1

..nBlockAlign = 1

..nSamplesPerSec = 8000

..nAvgBytesPerSec = 8000

..wBitsPerSample = 8

..cbSize = 0

End With

Dim Buffer(2048) As Byte

Dim Handle As GCHandle = GCHandle.Alloc(Buffer, GCHandleType.Pinned)

Dim ptrBuffer As IntPtr = Handle.AddrOfPinnedObject

intRet = waveInOpen(intWaveIn, intDevID, Wfmt, AddressOf WaveInProc, 0,
CALLBACK_FUNCTION)



intRet comes as 32.



Hopes kind help from you.

Thanks & Regards.

Sakharam Phapale
 
I

Imran Koradia

I'm not sure if you've tried looking up what that error means - but here's
where you can look up the error messages for the error codes:
http://msdn.microsoft.com/library/d...-us/debug/base/system_error_codes__0-499_.asp

error 32 is a sharing violation - so you might want to check whether the
file is opened already by some other process or something like that. I
haven't taken a look at your code but just wanted to make sure you had
looked into the error. If you've already done that then I'll probably go
through the code :)

hope that helps..
Imran.
 
S

Sakharam Phapale

Hi Imran,

Thanks for your reply, but I am not using any file.
I used this function for retrieving wave in device handle.
and this error is related to WAVEFORMAT, and here in code it is right one.

Thanks and Regards
Sakharam Phapale
 
I

Imran Koradia

my apologies - I was looking up the wrong error codes. This one is in
MMsytem.h and it translates to an unsupported waveform-audio format. I'll
look into it. In the meantime, maybe someone else here can come up with a
solution..

Imran.
 
I

Imran Koradia

looks like your structure needs to be modified a bit:

Structure WAVEFORMAT
Dim wFormatTag As Short
Dim nChannels As Short
Dim nSamplesPerSec As Integer
Dim nAvgBytesPerSec As Integer
Dim nBlockAlign As Short
Dim wBitsPerSample As Short
Dim cbSize As Short
End Structure

remember - DWORD converts to Integer (32-bit) and WORD converts to
Short(16-bit).

hope that helps..
Imran.
 

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