I have the following structure in c# and c++ :
C#
[StructLayout(LayoutKind.Sequential)]
public struct WAVEFORMATEX
{
public short wFormatTag;
public short nChannels;
public int nSamplesPerSec;
public int nAvgBytesPerSec;
public short nBlockAlign;
public short wBitsPerSample;
public short cbSize;
}
wavFmt = new clsWinMMBase.WAVEFORMATEX();
wavFmt.cbSize = (short)(Marshal.SizeOf(wavFmt));// returns 20
C++
typedef struct tWAVEFORMATEX
{
WORD wFormatTag; /* format type */
WORD nChannels; /* number of channels (i.e. mono, stereo...) */
DWORD nSamplesPerSec; /* sample rate */
DWORD nAvgBytesPerSec; /* for buffer estimation */
WORD nBlockAlign; /* block size of data */
WORD wBitsPerSample; /* number of bits per sample of mono data */
WORD cbSize; /* the count in bytes of the size of */
/* extra information (after cbSize) */
} WAVEFORMATEX
WAVEFORMATEX m_stWFEX;
m_stWFEX.cbSize=sizeof(WAVEFORMATEX);// returns 18
Why
Mickey MarshallPosted Feb 11, 2016, 8:04 AM
Shweta LodhaPosted Feb 10, 2016, 10:16 PM
please read below link. It will give you your answer:
http://www.codeproject.com/Articles/97711/sizeof-vs-Marshal-SizeOf