[PATCH 2/3] dmusic: Pass creation parameters to DMUSIC_CreateDirectMusicBufferImpl then allocate data buffer and set format accordingly.

Alexandre Julliard julliard at winehq.org
Mon Apr 23 04:54:52 CDT 2012


Christian Costa <titan.costa at gmail.com> writes:

> +HRESULT WINAPI DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface)
> +{
> +    IDirectMusicBufferImpl* dmbuffer;
> +
> +    TRACE("(%p, %p)\n", desc, ret_iface);
> +
> +    dmbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
> +    if (!dmbuffer) {
> +        *ret_iface = NULL;
> +        return E_OUTOFMEMORY;
> +    }
> +
> +    dmbuffer->lpVtbl = &DirectMusicBuffer_Vtbl;
> +    dmbuffer->ref = 0; /* Will be inited by QueryInterface */
> +
> +    memcpy(&dmbuffer->format, &desc->guidBufferFormat, sizeof(GUID));
> +    dmbuffer->size = (desc->cbBuffer + 3) & ~3; /* Buffer size must be multiple of 4 bytes */
> +
> +    dmbuffer->data = HeapAlloc(GetProcessHeap(), 0, sizeof(dmbuffer->size));
> +    if (!dmbuffer->data) {
> +        HeapFree(GetProcessHeap(), 0, dmbuffer);
> +        *ret_iface = NULL;
> +        return E_OUTOFMEMORY;
> +    }
> +
> +    return IDirectMusicBufferImpl_QueryInterface((LPDIRECTMUSICBUFFER)dmbuffer, &IID_IDirectMusicBuffer, ret_iface);

While you are changing the function please also make it handle errors
properly.

-- 
Alexandre Julliard
julliard at winehq.org



More information about the wine-devel mailing list