Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7496591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:41:09+00:00 2026-05-29T18:41:09+00:00

I’ve been trying to track this down for a while but I’m at a

  • 0

I’ve been trying to track this down for a while but I’m at a loss as to where to look next. Whenever I call waveOutPrepareHeader() I get INVALPARAMS indicating “The buffer’s base address is not aligned with the sample size.”

I am currently preparing my header from the data after the “data” tag (and length) from the file using the method found via MSDN.

    public Wave.SystemError Read(BinaryReader rdr, uint readLength)
    {
        dwBufferLength = readLength;
        byte[] data = new byte[readLength];
        rdr.Read(data, 0, data.Length);

        if (lpData == IntPtr.Zero)
            lpData = Memory.LocalAlloc(Memory.LMEM_FIXED,
               (uint)data.Length);

        if (lpData == IntPtr.Zero)
            return Wave.SystemError.NOMEM;

        Marshal.Copy(data, 0, lpData, data.Length);

        return Wave.SystemError.NOERROR;
    }

All the parameters of the class are zeroed out before use, after calling this function on a wave file I get

dwBufferLength = 32768
dwBytesRecorded = 0
dwFlags = 0
dwLoops = 0
dwUser = 0
lpData = 384656
lpNext = 0
reserved = 0

when passed into

return waveOutPrepareHeader(hWaveOut, 
                            ref headerBuffer[buffIndex],
                            (uint)Marshal.SizeOf(headerBuffer[buffIndex]));

where headerBuffer[buffIndex] is the abovementioned WAVEHDR I get 11 (MMSYSERR_INVALPARAM). I’ve checked and my hWaveOut and size seems to be sane so I’m forced to conclude the problem is with the header but I can’t figure out what is wrong or even what to check.

What do I need to do to fix this error, or failing that, what can I check to see what is causing it? Any assistance would be greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T18:41:15+00:00Added an answer on May 29, 2026 at 6:41 pm

    The problem ended up being not an issue with lpData (which was being allocated properly by LocalAlloc), but an issue with the way that the WAVEHDR structure itself was being passed to the PInvoked waveOutPrepareHeader.

    Most material on waveOut (even for C#) has you passing in an object of the header’s type. But in order to stop getting the error, I had to make a block of data using Marshal.AllocHGlobal and copy the header into it with Marshal.StructureToPtr. The IntPtr from the AllocHGlobal then is passed into waveOutPrepareHeader as such and that resolved the issue.

    Here’s some rough sample code for any who run up against a similar problem.

    WAVEHDR header = new WAVEHDR();
    //Read or setup header data here
    IntPtr headerPtr = Marshal.AllocHGlobal(Marshal.SizeOf(header));
    Marshal.StructureToPtr(header, headerPtr, true);
    waveOutPrepareHeader(hWaveOut, headerPtr, (uint)Marshal.SizeOf(header));
    

    This assumes that you set your PInvoke for everything that uses the header to an IntPtr type instead of a WAVEHDR one.

    From there, use the headerPtr for all the places where you need to pass in that header. You’ll have to handle the freeing of memory yourself at the appropriate location as you would expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.