WAVEFORMAT structure problem in WINMM.DLL

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

    WAVEFORMAT structure problem in WINMM.DLL

    Hi All,

    Yestrday I had problem regarding WAVEFORMAT structure in WaveInOpen API
    function call.
    Following structure works properly. But next to that didn't.
    Can anybody tell me why should I used Int16 and Int32 why not just Integer.
    Since in it's original definition they are Long, in .NET long is converted
    to Integer.
    But giving Integer it doesn't works.
    Even if I give all elements as int32 it doesn't works.

    Explain when to use Int16 or Short, Int32 or Integer?

    Hope explanation.

    Following is not working

    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


    This format works

    Structure WAVEFORMAT

    Dim wFormatTag As Int16

    Dim nChannels As Int16

    Dim nSamplesPerSec As Int32

    Dim nAvgBytesPerSec As Int32

    Dim nBlockAlign As Int16

    Dim wBitsPerSample As Int16

    Dim cbSize As Int16

    End Structure



    Thanks and Regards

    Sakharam Phapale


  • Herfried K. Wagner [MVP]

    #2
    Re: WAVEFORMAT structure problem in WINMM.DLL

    * "Sakharam Phapale" <sphapale@annet site.com> scripsit:[color=blue]
    > Yestrday I had problem regarding WAVEFORMAT structure in WaveInOpen API
    > function call.[/color]

    That's how it's defined in matters of C++:

    \\\
    typedef struct {
    WORD wFormatTag;
    WORD nChannels;
    DWORD nSamplesPerSec;
    DWORD nAvgBytesPerSec ;
    WORD nBlockAlign;
    } WAVEFORMAT;
    ///

    In VB.NET:

    \\\
    Imports System.Runtime. InteropServices
    ..
    ..
    ..
    <StructLayout(L ayoutKind.Seque ntial)> _
    Private Structure WAVEFORMAT
    Public wFormatTag As Int16
    Public nChannels As Int16
    Public nSamplesPerSec As Int32
    Public nAvgBytesPerSec As Int32
    Public nBlockAlign As Int16
    End Structure
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • Tom Shelton

      #3
      Re: WAVEFORMAT structure problem in WINMM.DLL

      On Sat, 4 Sep 2004 10:57:19 +0530, Sakharam Phapale wrote:
      [color=blue]
      > Hi All,
      >
      > Yestrday I had problem regarding WAVEFORMAT structure in WaveInOpen API
      > function call.
      > Following structure works properly. But next to that didn't.
      > Can anybody tell me why should I used Int16 and Int32 why not just Integer.
      > Since in it's original definition they are Long, in .NET long is converted
      > to Integer.
      > But giving Integer it doesn't works.
      > Even if I give all elements as int32 it doesn't works.
      >
      > Explain when to use Int16 or Short, Int32 or Integer?
      >
      > Hope explanation.
      >
      > Following is not working
      >
      > 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
      >
      >
      > This format works
      >
      > Structure WAVEFORMAT
      >
      > Dim wFormatTag As Int16
      >
      > Dim nChannels As Int16
      >
      > Dim nSamplesPerSec As Int32
      >
      > Dim nAvgBytesPerSec As Int32
      >
      > Dim nBlockAlign As Int16
      >
      > Dim wBitsPerSample As Int16
      >
      > Dim cbSize As Int16
      >
      > End Structure
      >
      >
      >
      > Thanks and Regards
      >
      > Sakharam Phapale[/color]

      First - Int16 = Short and Int32 = Integer. They are exactly the same, the
      compiler just mapps Integer declarations to System.Int32. So, when to use
      In32 over Integer? When ever you want to :) It is really more of a style
      issue, then a functional one.

      Now, when to use Short (Int16), Integer (Int32), etc... Well, since were
      talking about interop here - it depends on what the original datasize was.
      This is exactly the same as in VB6. You used the type that matched the
      original size. In C/C++ a int value is generally 32-bits, so in VB6 we
      used a long because it was 32-bits. When we saw short (16-bits), we used
      an Integer bacause it was the same size. Things are a different in .NET
      because the data sizes have changed. In .NET, Short is 16-bit, Integer is
      32-bit, and Long is 64-bit. Here is a quick partial rundown:

      C/C++ Type VB6 Type VB.NET Type
      BYTE (unsigned char) Byte Byte
      short (WORD) Integer Short or System.Int16
      int (DWORD) Long Integer or System.Int32
      long Long Integer or System.Int32
      long long Currency Long or System.Int64

      So, given your wave format structure:

      typedef struct {
      WORD wFormatTag;
      WORD nChannels;
      DWORD nSamplesPerSec;
      DWORD nAvgBytesPerSec ;
      WORD nBlockAlign;
      } WAVEFORMAT;

      This is the correct VB.NET declaration

      <StructLayout (LayoutKind.Seq uential)> _
      Structure WAVEFORMAT
      Public wFormatTag As Short
      Public nChannels As Short
      Public nSamplesPerSec As Integer
      Public nAvgBytesPerSec As Integer
      Public nBlockAlign As Short
      End Structure

      Make sense?
      --
      Tom Shelton [MVP]

      Comment

      Working...