Re: callback function immediatly called with an empty buffer

Tech-Archive recommends: Fix windows errors by optimizing your registry



> And when I debug the callback function, I see that all the fields of that
> parameter are set to 0, except dwflags, set to 3. It is like the parameter
> points to an incorrect memory area.
> I realy do not know what to do with that

{ flags for dwFlags field of WAVEHDR }
const
WHDR_DONE = $00000001; { done bit }
WHDR_PREPARED = $00000002; { set if this header has been prepared
}
WHDR_BEGINLOOP = $00000004; { loop start block }
WHDR_ENDLOOP = $00000008; { loop end block }
WHDR_INQUEUE = $00000010; { reserved for driver }

.... so your header has been prepared and is done. When you return the
header to the queue you should
set dwFlags to ...

dwFlags and not WHDR_DONE

... or whatever VB requires to do that setting.

Have you tried doing nothing in the MM_WIM_DONE handler if
dwBytesRecorded is zero. It certainly sounds strange activity to
immediately return an empty buffer as done (and my usage shows the
correct buffer length on return), but such a test would prevent
recording errors arising.

Does GlobalAlloc set the allocated memory to 0 ?

You seem to be doing everything you should. All I do (in Delph) is ...

InBuffers[i] := AllocMem(BufferSize);
InHeaders[i] := AllocMem(SizeOf(TWaveHdr));
with InHeaders[i]^ do begin
lpData := InBuffers[i];
dwBufferLength := BufferSize;
dwUser := integer(RecStrm); // for use in MMWIMData to copy
buffer
end;
{... and prepare headers}
WaveInPrepareHeader(hndWaveIn, InHeaders[i], SizeOf(TWaveHdr));

... and Delphi AllocMem zeroes the memory for me.

Alan Lloyd

.



Relevant Pages

  • Re: Learning to stream audio from a file
    ... Shouldn't you be polling the m_WaveHeaders for WHDR_DONE in dwFlags, ... and refill _that_ header's buffer, rather than assuming the next header ...
    (microsoft.public.win32.programmer.mmedia)
  • Re: Detecting freed memory
    ... can easily see the parent article, or even the subject header. ... The parent article asked about how to detect, after a call to free, ... > buffer that can be checked. ... It would also have to initialize newly malloced memory with some ...
    (comp.lang.c)
  • Re: Fw: Buffer overflow in CIFS VFS.
    ... What I meant is that two fixed size memory pools rather variable size ... type of buffer or whatever needed info. ... access the header would move the pointer back by sizeof. ...
    (Linux-Kernel)
  • Re: memory related concerns
    ... i have a situation where i receive data in a buffer and i ... utiltimate aim is to return the header of the linked list to the caller ... run out of memory simultaneously. ...
    (comp.lang.c)
  • Re: memory related concerns
    ... i have a situation where i receive data in a buffer and i ... utiltimate aim is to return the header of the linked list to the caller ... run out of memory simultaneously. ...
    (comp.lang.c)