WaveInOpen API function Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sakharam Phapale

    WaveInOpen API function Problem

    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_FUNCTI ON = &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

    ..nSamplesPerSe c = 8000

    ..nAvgBytesPerS ec = 8000

    ..wBitsPerSampl e = 8

    ..cbSize = 0

    End With

    Dim Buffer(2048) As Byte

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

    Dim ptrBuffer As IntPtr = Handle.AddrOfPi nnedObject

    intRet = waveInOpen(intW aveIn, intDevID, Wfmt, AddressOf WaveInProc, 0,
    CALLBACK_FUNCTI ON)



    intRet comes as 32.



    Hopes kind help from you.

    Thanks & Regards.

    Sakharam Phapale


  • Imran Koradia

    #2
    Re: WaveInOpen API function Problem

    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:


    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.

    "Sakharam Phapale" <sphapale@annet site.com> wrote in message
    news:%23CQmifbk EHA.1028@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Hi All,
    >
    > I have written following code, but waveInOpen API call gives me error no[/color]
    32.[color=blue]
    > 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_FUNCTI ON = &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
    >
    > .nAvgBytesPerSe c = 8000
    >
    > .wBitsPerSample = 8
    >
    > .cbSize = 0
    >
    > End With
    >
    > Dim Buffer(2048) As Byte
    >
    > Dim Handle As GCHandle = GCHandle.Alloc( Buffer, GCHandleType.Pi nned)
    >
    > Dim ptrBuffer As IntPtr = Handle.AddrOfPi nnedObject
    >
    > intRet = waveInOpen(intW aveIn, intDevID, Wfmt, AddressOf WaveInProc, 0,
    > CALLBACK_FUNCTI ON)
    >
    >
    >
    > intRet comes as 32.
    >
    >
    >
    > Hopes kind help from you.
    >
    > Thanks & Regards.
    >
    > Sakharam Phapale
    >
    >[/color]


    Comment

    • Sakharam Phapale

      #3
      Re: WaveInOpen API function Problem

      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


      "Imran Koradia" <nospam@microso ft.com> wrote in message
      news:uXwfVobkEH A.3392@TK2MSFTN GP15.phx.gbl...[color=blue]
      > 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:
      >[/color]
      http://msdn.microsoft.com/library/de...es__0-499_.asp[color=blue]
      >
      > 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.
      >
      > "Sakharam Phapale" <sphapale@annet site.com> wrote in message
      > news:%23CQmifbk EHA.1028@TK2MSF TNGP12.phx.gbl. ..[color=green]
      > > Hi All,
      > >
      > > I have written following code, but waveInOpen API call gives me error no[/color]
      > 32.[color=green]
      > > 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_FUNCTI ON = &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,[/color][/color]
      _[color=blue][color=green]
      > >
      > > 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
      > >
      > > .nAvgBytesPerSe c = 8000
      > >
      > > .wBitsPerSample = 8
      > >
      > > .cbSize = 0
      > >
      > > End With
      > >
      > > Dim Buffer(2048) As Byte
      > >
      > > Dim Handle As GCHandle = GCHandle.Alloc( Buffer, GCHandleType.Pi nned)
      > >
      > > Dim ptrBuffer As IntPtr = Handle.AddrOfPi nnedObject
      > >
      > > intRet = waveInOpen(intW aveIn, intDevID, Wfmt, AddressOf WaveInProc, 0,
      > > CALLBACK_FUNCTI ON)
      > >
      > >
      > >
      > > intRet comes as 32.
      > >
      > >
      > >
      > > Hopes kind help from you.
      > >
      > > Thanks & Regards.
      > >
      > > Sakharam Phapale
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Imran Koradia

        #4
        Re: WaveInOpen API function Problem

        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.

        "Sakharam Phapale" <sphapale@annet site.com> wrote in message
        news:eoJccwbkEH A.3112@TK2MSFTN GP14.phx.gbl...[color=blue]
        > 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
        >
        >
        > "Imran Koradia" <nospam@microso ft.com> wrote in message
        > news:uXwfVobkEH A.3392@TK2MSFTN GP15.phx.gbl...[color=green]
        > > I'm not sure if you've tried looking up what that error means - but[/color][/color]
        here's[color=blue][color=green]
        > > where you can look up the error messages for the error codes:
        > >[/color]
        >[/color]
        http://msdn.microsoft.com/library/de...es__0-499_.asp[color=blue][color=green]
        > >
        > > 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.
        > >
        > > "Sakharam Phapale" <sphapale@annet site.com> wrote in message
        > > news:%23CQmifbk EHA.1028@TK2MSF TNGP12.phx.gbl. ..[color=darkred]
        > > > Hi All,
        > > >
        > > > I have written following code, but waveInOpen API call gives me error[/color][/color][/color]
        no[color=blue][color=green]
        > > 32.[color=darkred]
        > > > 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_FUNCTI ON = &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[/color][/color][/color]
        IntPtr,[color=blue]
        > _[color=green][color=darkred]
        > > >
        > > > 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
        > > >
        > > > .nAvgBytesPerSe c = 8000
        > > >
        > > > .wBitsPerSample = 8
        > > >
        > > > .cbSize = 0
        > > >
        > > > End With
        > > >
        > > > Dim Buffer(2048) As Byte
        > > >
        > > > Dim Handle As GCHandle = GCHandle.Alloc( Buffer, GCHandleType.Pi nned)
        > > >
        > > > Dim ptrBuffer As IntPtr = Handle.AddrOfPi nnedObject
        > > >
        > > > intRet = waveInOpen(intW aveIn, intDevID, Wfmt, AddressOf WaveInProc,[/color][/color][/color]
        0,[color=blue][color=green][color=darkred]
        > > > CALLBACK_FUNCTI ON)
        > > >
        > > >
        > > >
        > > > intRet comes as 32.
        > > >
        > > >
        > > >
        > > > Hopes kind help from you.
        > > >
        > > > Thanks & Regards.
        > > >
        > > > Sakharam Phapale
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Imran Koradia

          #5
          Re: WaveInOpen API function Problem

          looks like your structure needs to be modified a bit:
          [color=blue][color=green][color=darkred]
          > > > 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
          > > >[/color][/color][/color]

          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.


          Comment

          Working...