WAVEFORMAT structure problem in WINMM.DLL

  • Thread starter Sakharam Phapale
  • Start date
S

Sakharam Phapale

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
 
H

Herfried K. Wagner [MVP]

* "Sakharam Phapale said:
Yestrday I had problem regarding WAVEFORMAT structure in WaveInOpen API
function call.

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(LayoutKind.Sequential)> _
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
///
 
T

Tom Shelton

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

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.Sequential)> _
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?
 

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

Similar Threads


Top