-1

There's struct:

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct WAVEFORMATEX
{
    public ushort wFormatTag;
    public ushort nChannels;
    public uint nSamplesPerSec;
    public uint nAvgBytesPerSec;
    public ushort nBlockAlign;
    public ushort wBitsPerSample;
    public ushort cbSize;
};

Marshal.SizeOf(WAVEFORMATEX) says it's = 18

The Win32 SendMessage func returns size = 16 444

Actual size is 13, and I can assume it's aligned at the size of 4, so the 16 looks correct.

Why Marshal.SizeOf(WAVEFORMATEX) says 18?

222

Or, if 18 is correct, then why SendMessage returns 16?

  • 4
    ushorts are 2 bytes, and uints are 4 bytes. 5 ushorts plus 2 uints equals 18 bytes. – SirCxyrtyx Mar 12 at 1:02
  • 3
    A ushort is 2 bytes and a uint is 4 bytes, so that struct is 2+2+4+4+2+2+2=18. That would be the correct size it's been defined. Where are you getting the other numbers? – shf301 Mar 12 at 1:02
  • 1
    The Win32 SendMessage func returns size = 16 what does this mean? – Jonathan Potter Mar 12 at 3:14
  • 2
    I don't understand why you packed the structure. But as it happens that won't affect the size here. I guess your mistake is that you think ushort is a single byte. It's actually two bytes. – David Heffernan Mar 12 at 7:11
  • 1
    Which message are you talking about? – Anders Mar 12 at 13:01
1

As the comments point out, The size value 18 is correct because the size of ushort is 2 but not 1.

"Win32 SendMessage func returns size = 16"

The return value of SendMessage specifies the result of message processing, depending on the message sent, but not the size of it has sent.

  • this is the sendmessage i use. waveformatex is the return struct. so if it's 18 then why it says 16? – Natali Mar 14 at 0:08
  • yeah, it was my fault of course .. i stupidly assumed that ushot is 1 byte with 1 bit for sign. if I wrote WORD i would never missed it. but the return value 16 makes me confused anyway. – Natali Mar 14 at 0:11
  • i have added comments to my question, pls, clarify the return value 16 then.. i'll set your feedback as the answer.. really 18 is not 16, right? – Natali Mar 14 at 0:28
  • Depends on the return value of the function response the message. 16 can only represent that the window camHwnd return the size of 16 to SendMessage. – Drake Wu - MSFT Mar 14 at 2:29

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.