[PATCH 5/5] wined3d: Use the global memory allocation helpers.

Henri Verbeet hverbeet at codeweavers.com
Wed Feb 14 00:39:59 CST 2018


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/arb_program_shader.c  | 136 ++++++++++++++++++-----------------
 dlls/wined3d/ati_fragment_shader.c |  18 ++---
 dlls/wined3d/buffer.c              |  29 ++++----
 dlls/wined3d/context.c             |  68 +++++++++---------
 dlls/wined3d/cs.c                  |  32 ++++-----
 dlls/wined3d/device.c              |  42 +++++------
 dlls/wined3d/directx.c             |  37 +++++-----
 dlls/wined3d/glsl_shader.c         | 144 ++++++++++++++++++-------------------
 dlls/wined3d/palette.c             |   7 +-
 dlls/wined3d/query.c               |  32 ++++-----
 dlls/wined3d/resource.c            |   4 +-
 dlls/wined3d/sampler.c             |   4 +-
 dlls/wined3d/shader.c              | 138 ++++++++++++++++++-----------------
 dlls/wined3d/shader_sm1.c          |   6 +-
 dlls/wined3d/shader_sm4.c          |   8 +--
 dlls/wined3d/state.c               |  23 +++---
 dlls/wined3d/stateblock.c          |  11 ++-
 dlls/wined3d/surface.c             |  36 +++++-----
 dlls/wined3d/swapchain.c           |  22 +++---
 dlls/wined3d/texture.c             |  26 +++----
 dlls/wined3d/utils.c               |   8 +--
 dlls/wined3d/vertexdeclaration.c   |  19 +++--
 dlls/wined3d/view.c                |  18 ++---
 dlls/wined3d/wined3d_main.c        |  16 ++---
 dlls/wined3d/wined3d_private.h     |   8 +--
 25 files changed, 439 insertions(+), 453 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index a8c4abb..0d21f24 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -3880,7 +3880,7 @@ static void clone_sig(struct wined3d_shader_signature *new, const struct wined3d
     char *name;
 
     new->element_count = sig->element_count;
-    new->elements = wined3d_calloc(new->element_count, sizeof(*new->elements));
+    new->elements = heap_calloc(new->element_count, sizeof(*new->elements));
     for (i = 0; i < sig->element_count; ++i)
     {
         new->elements[i] = sig->elements[i];
@@ -3889,7 +3889,7 @@ static void clone_sig(struct wined3d_shader_signature *new, const struct wined3d
             continue;
 
         /* Clone the semantic string */
-        name = HeapAlloc(GetProcessHeap(), 0, strlen(sig->elements[i].semantic_name) + 1);
+        name = heap_alloc(strlen(sig->elements[i].semantic_name) + 1);
         strcpy(name, sig->elements[i].semantic_name);
         new->elements[i].semantic_name = name;
     }
@@ -3906,7 +3906,7 @@ static DWORD find_input_signature(struct shader_arb_priv *priv, const struct win
         TRACE("Found existing signature %u\n", found_sig->idx);
         return found_sig->idx;
     }
-    found_sig = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*found_sig));
+    found_sig = heap_alloc_zero(sizeof(*found_sig));
     clone_sig(&found_sig->sig, sig);
     found_sig->idx = priv->ps_sig_number++;
     TRACE("New signature stored and assigned number %u\n", found_sig->idx);
@@ -4258,7 +4258,7 @@ static struct arb_ps_compiled_shader *find_arb_pshader(struct wined3d_shader *sh
     {
         struct shader_arb_priv *priv = device->shader_priv;
 
-        shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+        shader->backend_data = heap_alloc_zero(sizeof(*shader_data));
         shader_data = shader->backend_data;
         shader_data->clamp_consts = shader->reg_maps.shader_version.major == 1;
 
@@ -4294,8 +4294,10 @@ static struct arb_ps_compiled_shader *find_arb_pshader(struct wined3d_shader *sh
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
             new_array = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, shader_data->gl_shaders,
                                     new_size * sizeof(*shader_data->gl_shaders));
-        } else {
-            new_array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data->gl_shaders));
+        }
+        else
+        {
+            new_array = heap_alloc_zero(sizeof(*shader_data->gl_shaders));
             new_size = 1;
         }
 
@@ -4353,7 +4355,7 @@ static struct arb_vs_compiled_shader *find_arb_vshader(struct wined3d_shader *sh
     {
         const struct wined3d_shader_reg_maps *reg_maps = &shader->reg_maps;
 
-        shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+        shader->backend_data = heap_alloc_zero(sizeof(*shader_data));
         shader_data = shader->backend_data;
 
         if ((gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT)
@@ -4393,8 +4395,10 @@ static struct arb_vs_compiled_shader *find_arb_vshader(struct wined3d_shader *sh
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
             new_array = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, shader_data->gl_shaders,
                                     new_size * sizeof(*shader_data->gl_shaders));
-        } else {
-            new_array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data->gl_shaders));
+        }
+        else
+        {
+            new_array = heap_alloc_zero(sizeof(*shader_data->gl_shaders));
             new_size = 1;
         }
 
@@ -4762,8 +4766,8 @@ static void shader_arb_destroy(struct wined3d_shader *shader)
             context_release(context);
         }
 
-        HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
-        HeapFree(GetProcessHeap(), 0, shader_data);
+        heap_free(shader_data->gl_shaders);
+        heap_free(shader_data);
         shader->backend_data = NULL;
     }
     else
@@ -4786,8 +4790,8 @@ static void shader_arb_destroy(struct wined3d_shader *shader)
             context_release(context);
         }
 
-        HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
-        HeapFree(GetProcessHeap(), 0, shader_data);
+        heap_free(shader_data->gl_shaders);
+        heap_free(shader_data);
         shader->backend_data = NULL;
     }
 }
@@ -4801,15 +4805,18 @@ static int sig_tree_compare(const void *key, const struct wine_rb_entry *entry)
 static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
         const struct fragment_pipeline *fragment_pipe)
 {
-    struct shader_arb_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv));
+    const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
     struct fragment_caps fragment_caps;
     void *vertex_priv, *fragment_priv;
-    const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
+    struct shader_arb_priv *priv;
+
+    if (!(priv = heap_alloc_zero(sizeof(*priv))))
+        return E_OUTOFMEMORY;
 
     if (!(vertex_priv = vertex_pipe->vp_alloc(&arb_program_shader_backend, priv)))
     {
         ERR("Failed to initialize vertex pipe.\n");
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -4817,7 +4824,7 @@ static HRESULT shader_arb_alloc(struct wined3d_device *device, const struct wine
     {
         ERR("Failed to initialize fragment pipe.\n");
         vertex_pipe->vp_free(device);
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -4847,10 +4854,10 @@ static void release_signature(struct wine_rb_entry *entry, void *context)
 
     for (i = 0; i < sig->sig.element_count; ++i)
     {
-        HeapFree(GetProcessHeap(), 0, (char *)sig->sig.elements[i].semantic_name);
+        heap_free((char *)sig->sig.elements[i].semantic_name);
     }
-    HeapFree(GetProcessHeap(), 0, sig->sig.elements);
-    HeapFree(GetProcessHeap(), 0, sig);
+    heap_free(sig->sig.elements);
+    heap_free(sig);
 }
 
 /* Context activation is done by the caller. */
@@ -4861,7 +4868,7 @@ static void shader_arb_free(struct wined3d_device *device)
     wine_rb_destroy(&priv->signature_tree, release_signature, NULL);
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
-    HeapFree(GetProcessHeap(), 0, device->shader_priv);
+    heap_free(device->shader_priv);
 }
 
 static BOOL shader_arb_allocate_context_data(struct wined3d_context *context)
@@ -5329,39 +5336,38 @@ static void get_loop_control_const(const struct wined3d_shader_instruction *ins,
 
 static void record_instruction(struct list *list, const struct wined3d_shader_instruction *ins)
 {
-    unsigned int i;
-    struct wined3d_shader_dst_param *dst_param;
     struct wined3d_shader_src_param *src_param = NULL, *rel_addr;
-    struct recorded_instruction *rec = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rec));
-    if(!rec)
+    struct wined3d_shader_dst_param *dst_param;
+    struct recorded_instruction *rec;
+    unsigned int i;
+
+    if (!(rec = heap_alloc_zero(sizeof(*rec))))
     {
         ERR("Out of memory\n");
         return;
     }
 
     rec->ins = *ins;
-    dst_param = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_param));
-    if(!dst_param) goto free;
+    if (!(dst_param = heap_alloc(sizeof(*dst_param))))
+        goto free;
     *dst_param = *ins->dst;
     if (ins->dst->reg.idx[0].rel_addr)
     {
-        rel_addr = HeapAlloc(GetProcessHeap(), 0, sizeof(*rel_addr));
-        if (!rel_addr)
+        if (!(rel_addr = heap_alloc(sizeof(*rel_addr))))
             goto free;
         *rel_addr = *ins->dst->reg.idx[0].rel_addr;
         dst_param->reg.idx[0].rel_addr = rel_addr;
     }
     rec->ins.dst = dst_param;
 
-    if (!(src_param = wined3d_calloc(ins->src_count, sizeof(*src_param))))
+    if (!(src_param = heap_calloc(ins->src_count, sizeof(*src_param))))
         goto free;
     for (i = 0; i < ins->src_count; ++i)
     {
         src_param[i] = ins->src[i];
         if (ins->src[i].reg.idx[0].rel_addr)
         {
-            rel_addr = HeapAlloc(GetProcessHeap(), 0, sizeof(*rel_addr));
-            if (!rel_addr)
+            if (!(rel_addr = heap_alloc(sizeof(*rel_addr))))
                 goto free;
             *rel_addr = *ins->src[i].reg.idx[0].rel_addr;
             src_param[i].reg.idx[0].rel_addr = rel_addr;
@@ -5373,20 +5379,20 @@ static void record_instruction(struct list *list, const struct wined3d_shader_in
 
 free:
     ERR("Out of memory\n");
-    if(dst_param)
+    if (dst_param)
     {
-        HeapFree(GetProcessHeap(), 0, (void *)dst_param->reg.idx[0].rel_addr);
-        HeapFree(GetProcessHeap(), 0, dst_param);
+        heap_free((void *)dst_param->reg.idx[0].rel_addr);
+        heap_free(dst_param);
     }
-    if(src_param)
+    if (src_param)
     {
-        for(i = 0; i < ins->src_count; i++)
+        for (i = 0; i < ins->src_count; ++i)
         {
-            HeapFree(GetProcessHeap(), 0, (void *)src_param[i].reg.idx[0].rel_addr);
+            heap_free((void *)src_param[i].reg.idx[0].rel_addr);
         }
-        HeapFree(GetProcessHeap(), 0, src_param);
+        heap_free(src_param);
     }
-    HeapFree(GetProcessHeap(), 0, rec);
+    heap_free(rec);
 }
 
 static void free_recorded_instruction(struct list *list)
@@ -5399,18 +5405,18 @@ static void free_recorded_instruction(struct list *list)
         list_remove(&rec_ins->entry);
         if (rec_ins->ins.dst)
         {
-            HeapFree(GetProcessHeap(), 0, (void *)rec_ins->ins.dst->reg.idx[0].rel_addr);
-            HeapFree(GetProcessHeap(), 0, (void *)rec_ins->ins.dst);
+            heap_free((void *)rec_ins->ins.dst->reg.idx[0].rel_addr);
+            heap_free((void *)rec_ins->ins.dst);
         }
         if (rec_ins->ins.src)
         {
             for (i = 0; i < rec_ins->ins.src_count; ++i)
             {
-                HeapFree(GetProcessHeap(), 0, (void *)rec_ins->ins.src[i].reg.idx[0].rel_addr);
+                heap_free((void *)rec_ins->ins.src[i].reg.idx[0].rel_addr);
             }
-            HeapFree(GetProcessHeap(), 0, (void *)rec_ins->ins.src);
+            heap_free((void *)rec_ins->ins.src);
         }
-        HeapFree(GetProcessHeap(), 0, rec_ins);
+        heap_free(rec_ins);
     }
 }
 
@@ -5424,7 +5430,7 @@ static void pop_control_frame(const struct wined3d_shader_instruction *ins)
         struct list *e = list_head(&priv->control_frames);
         control_frame = LIST_ENTRY(e, struct control_frame, entry);
         list_remove(&control_frame->entry);
-        HeapFree(GetProcessHeap(), 0, control_frame);
+        heap_free(control_frame);
         priv->loop_depth--;
     }
     else if (ins->handler_idx == WINED3DSIH_ENDIF)
@@ -5433,7 +5439,7 @@ static void pop_control_frame(const struct wined3d_shader_instruction *ins)
         struct list *e = list_head(&priv->control_frames);
         control_frame = LIST_ENTRY(e, struct control_frame, entry);
         list_remove(&control_frame->entry);
-        HeapFree(GetProcessHeap(), 0, control_frame);
+        heap_free(control_frame);
     }
 }
 
@@ -5447,7 +5453,7 @@ static void shader_arb_handle_instruction(const struct wined3d_shader_instructio
 
     if(ins->handler_idx == WINED3DSIH_LOOP || ins->handler_idx == WINED3DSIH_REP)
     {
-        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        control_frame = heap_alloc_zero(sizeof(*control_frame));
         list_add_head(&priv->control_frames, &control_frame->entry);
 
         if(ins->handler_idx == WINED3DSIH_LOOP) control_frame->type = LOOP;
@@ -5544,13 +5550,13 @@ static void shader_arb_handle_instruction(const struct wined3d_shader_instructio
                 shader_addline(buffer, "#end loop/rep\n");
 
                 free_recorded_instruction(&copy);
-                HeapFree(GetProcessHeap(), 0, control_frame);
+                heap_free(control_frame);
                 return; /* Instruction is handled */
             }
             else
             {
                 /* This is a nested loop. Proceed to the normal recording function */
-                HeapFree(GetProcessHeap(), 0, control_frame);
+                heap_free(control_frame);
             }
         }
     }
@@ -5564,7 +5570,7 @@ static void shader_arb_handle_instruction(const struct wined3d_shader_instructio
     /* boolean if */
     if(ins->handler_idx == WINED3DSIH_IF)
     {
-        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        control_frame = heap_alloc_zero(sizeof(*control_frame));
         list_add_head(&priv->control_frames, &control_frame->entry);
         control_frame->type = IF;
 
@@ -5584,7 +5590,7 @@ static void shader_arb_handle_instruction(const struct wined3d_shader_instructio
     else if(ins->handler_idx == WINED3DSIH_IFC)
     {
         /* IF(bool) and if_cond(a, b) use the same ELSE and ENDIF tokens */
-        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        control_frame = heap_alloc_zero(sizeof(*control_frame));
         control_frame->type = IFC;
         control_frame->no.ifc = priv->num_ifcs++;
         list_add_head(&priv->control_frames, &control_frame->entry);
@@ -5619,7 +5625,7 @@ static void shader_arb_handle_instruction(const struct wined3d_shader_instructio
             shader_addline(buffer, "#} endif\n");
             if(control_frame->muting) priv->muted = FALSE;
             list_remove(&control_frame->entry);
-            HeapFree(GetProcessHeap(), 0, control_frame);
+            heap_free(control_frame);
             return; /* Instruction is handled */
         }
         /* In case of an ifc, generate a HW shader instruction */
@@ -5719,7 +5725,7 @@ static void *arbfp_alloc(const struct wined3d_shader_backend_ops *shader_backend
      * or not. */
     if (shader_backend == &arb_program_shader_backend)
         priv = shader_priv;
-    else if (!(priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv))))
+    else if (!(priv = heap_alloc_zero(sizeof(*priv))))
         return NULL;
 
     wine_rb_init(&priv->fragment_shaders, wined3d_ffp_frag_program_key_compare);
@@ -5736,7 +5742,7 @@ static void arbfp_free_ffpshader(struct wine_rb_entry *entry, void *context)
 
     GL_EXTCALL(glDeleteProgramsARB(1, &entry_arb->shader));
     checkGLcall("glDeleteProgramsARB(1, &entry_arb->shader)");
-    HeapFree(GetProcessHeap(), 0, entry_arb);
+    heap_free(entry_arb);
 }
 
 /* Context activation is done by the caller. */
@@ -5748,9 +5754,7 @@ static void arbfp_free(struct wined3d_device *device)
     priv->use_arbfp_fixed_func = FALSE;
 
     if (device->shader_backend != &arb_program_shader_backend)
-    {
-        HeapFree(GetProcessHeap(), 0, device->fragment_priv);
-    }
+        heap_free(device->fragment_priv);
 }
 
 static void arbfp_get_caps(const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
@@ -6573,8 +6577,9 @@ static void fragment_prog_arbfp(struct wined3d_context *context, const struct wi
         desc = (const struct arbfp_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings);
         if (!desc)
         {
-            struct arbfp_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_desc));
-            if (!new_desc)
+            struct arbfp_ffp_desc *new_desc;
+
+            if (!(new_desc = heap_alloc(sizeof(*new_desc))))
             {
                 ERR("Out of memory\n");
                 return;
@@ -6899,7 +6904,7 @@ static void arbfp_free_blit_shader(struct wine_rb_entry *entry, void *ctx)
 
     GL_EXTCALL(glDeleteProgramsARB(1, &entry_arb->shader));
     checkGLcall("glDeleteProgramsARB(1, &entry_arb->shader)");
-    HeapFree(GetProcessHeap(), 0, entry_arb);
+    heap_free(entry_arb);
 }
 
 /* Context activation is done by the caller. */
@@ -6920,7 +6925,7 @@ static void arbfp_blitter_destroy(struct wined3d_blitter *blitter, struct wined3
     if (arbfp_blitter->palette_texture)
         gl_info->gl_ops.gl.p_glDeleteTextures(1, &arbfp_blitter->palette_texture);
 
-    HeapFree(GetProcessHeap(), 0, arbfp_blitter);
+    heap_free(arbfp_blitter);
 }
 
 static BOOL gen_planar_yuv_read(struct wined3d_string_buffer *buffer, const struct arbfp_blit_type *type,
@@ -7647,8 +7652,7 @@ static HRESULT arbfp_blit_set(struct wined3d_arbfp_blitter *blitter, struct wine
             return E_NOTIMPL;
         }
 
-        desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
-        if (!desc)
+        if (!(desc = heap_alloc(sizeof(*desc))))
             goto err_out;
 
         desc->type = type;
@@ -7661,7 +7665,7 @@ err_out:
             checkGLcall("GL_EXTCALL(glDeleteProgramsARB(1, &shader))");
             GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
             checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0)");
-            HeapFree(GetProcessHeap(), 0, desc);
+            heap_free(desc);
             return E_OUTOFMEMORY;
         }
     }
@@ -7918,7 +7922,7 @@ void wined3d_arbfp_blitter_create(struct wined3d_blitter **next, const struct wi
     if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
         return;
 
-    if (!(blitter = HeapAlloc(GetProcessHeap(), 0, sizeof(*blitter))))
+    if (!(blitter = heap_alloc(sizeof(*blitter))))
     {
         ERR("Failed to allocate blitter.\n");
         return;
diff --git a/dlls/wined3d/ati_fragment_shader.c b/dlls/wined3d/ati_fragment_shader.c
index 2fd94bc..9d6837a 100644
--- a/dlls/wined3d/ati_fragment_shader.c
+++ b/dlls/wined3d/ati_fragment_shader.c
@@ -1025,8 +1025,9 @@ static void set_tex_op_atifs(struct wined3d_context *context, const struct wined
     desc = (const struct atifs_ffp_desc *)find_ffp_frag_shader(&priv->fragment_shaders, &settings);
     if (!desc)
     {
-        struct atifs_ffp_desc *new_desc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*new_desc));
-        if (!new_desc)
+        struct atifs_ffp_desc *new_desc;
+
+        if (!(new_desc = heap_alloc_zero(sizeof(*new_desc))))
         {
             ERR("Out of memory\n");
             return;
@@ -1320,7 +1321,7 @@ static void *atifs_alloc(const struct wined3d_shader_backend_ops *shader_backend
 {
     struct atifs_private_data *priv;
 
-    if (!(priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv))))
+    if (!(priv = heap_alloc_zero(sizeof(*priv))))
         return NULL;
 
     wine_rb_init(&priv->fragment_shaders, wined3d_ffp_frag_program_key_compare);
@@ -1335,7 +1336,7 @@ static void atifs_free_ffpshader(struct wine_rb_entry *entry, void *cb_ctx)
 
     GL_EXTCALL(glDeleteFragmentShaderATI(entry_ati->shader));
     checkGLcall("glDeleteFragmentShaderATI(entry->shader)");
-    HeapFree(GetProcessHeap(), 0, entry_ati);
+    heap_free(entry_ati);
 }
 
 /* Context activation is done by the caller. */
@@ -1345,7 +1346,7 @@ static void atifs_free(struct wined3d_device *device)
 
     wine_rb_destroy(&priv->fragment_shaders, atifs_free_ffpshader, &device->adapter->gl_info);
 
-    HeapFree(GetProcessHeap(), 0, priv);
+    heap_free(priv);
     device->fragment_priv = NULL;
 }
 
@@ -1358,8 +1359,9 @@ static BOOL atifs_color_fixup_supported(struct color_fixup_desc fixup)
 
 static BOOL atifs_alloc_context_data(struct wined3d_context *context)
 {
-    struct atifs_context_private_data *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv));
-    if (!priv)
+    struct atifs_context_private_data *priv;
+
+    if (!(priv = heap_alloc_zero(sizeof(*priv))))
         return FALSE;
     context->fragment_pipe_data = priv;
     return TRUE;
@@ -1367,7 +1369,7 @@ static BOOL atifs_alloc_context_data(struct wined3d_context *context)
 
 static void atifs_free_context_data(struct wined3d_context *context)
 {
-    HeapFree(GetProcessHeap(), 0, context->fragment_pipe_data);
+    heap_free(context->fragment_pipe_data);
 }
 
 const struct fragment_pipeline atifs_fragment_pipeline = {
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index f907ece..c1dfc56 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -302,8 +302,8 @@ static BOOL buffer_process_converted_attribute(struct wined3d_buffer *buffer,
              */
             TRACE("Reconverting because converted attributes occur, and the stride changed.\n");
             buffer->stride = *stride_this_run;
-            HeapFree(GetProcessHeap(), HEAP_ZERO_MEMORY, buffer->conversion_map);
-            buffer->conversion_map = wined3d_calloc(buffer->stride, sizeof(*buffer->conversion_map));
+            heap_free(buffer->conversion_map);
+            buffer->conversion_map = heap_calloc(buffer->stride, sizeof(*buffer->conversion_map));
             ret = TRUE;
         }
     }
@@ -385,7 +385,7 @@ static BOOL buffer_find_decl(struct wined3d_buffer *This, const struct wined3d_s
         TRACE("No fixup required.\n");
         if(This->conversion_map)
         {
-            HeapFree(GetProcessHeap(), 0, This->conversion_map);
+            heap_free(This->conversion_map);
             This->conversion_map = NULL;
             This->stride = 0;
             return TRUE;
@@ -474,8 +474,9 @@ static BOOL buffer_find_decl(struct wined3d_buffer *This, const struct wined3d_s
     if (!stride_this_run && This->conversion_map)
     {
         /* Sanity test */
-        if (!ret) ERR("no converted attributes found, old conversion map exists, and no declaration change?\n");
-        HeapFree(GetProcessHeap(), 0, This->conversion_map);
+        if (!ret)
+            ERR("no converted attributes found, old conversion map exists, and no declaration change?\n");
+        heap_free(This->conversion_map);
         This->conversion_map = NULL;
         This->stride = 0;
     }
@@ -563,7 +564,7 @@ static void buffer_conversion_upload(struct wined3d_buffer *buffer, struct wined
     /* Now for each vertex in the buffer that needs conversion. */
     vertex_count = buffer->resource.size / buffer->stride;
 
-    if (!(data = HeapAlloc(GetProcessHeap(), 0, buffer->resource.size)))
+    if (!(data = heap_alloc(buffer->resource.size)))
     {
         ERR("Out of memory.\n");
         return;
@@ -601,7 +602,7 @@ static void buffer_conversion_upload(struct wined3d_buffer *buffer, struct wined
 
     wined3d_buffer_upload_ranges(buffer, context, data, 0, buffer->modified_areas, buffer->maps);
 
-    HeapFree(GetProcessHeap(), 0, data);
+    heap_free(data);
 }
 
 static BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer,
@@ -753,7 +754,7 @@ static void buffer_unload(struct wined3d_resource *resource)
 
         context_release(context);
 
-        HeapFree(GetProcessHeap(), 0, buffer->conversion_map);
+        heap_free(buffer->conversion_map);
         buffer->conversion_map = NULL;
         buffer->stride = 0;
         buffer->conversion_stride = 0;
@@ -780,11 +781,11 @@ static void wined3d_buffer_destroy_object(void *object)
         buffer_destroy_buffer_object(buffer, context);
         context_release(context);
 
-        HeapFree(GetProcessHeap(), 0, buffer->conversion_map);
+        heap_free(buffer->conversion_map);
     }
 
-    HeapFree(GetProcessHeap(), 0, buffer->maps);
-    HeapFree(GetProcessHeap(), 0, buffer);
+    heap_free(buffer->maps);
+    heap_free(buffer);
 }
 
 ULONG CDECL wined3d_buffer_decref(struct wined3d_buffer *buffer)
@@ -1396,7 +1397,7 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device
         buffer->flags |= WINED3D_BUFFER_USE_BO;
     }
 
-    if (!(buffer->maps = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer->maps))))
+    if (!(buffer->maps = heap_alloc(sizeof(*buffer->maps))))
     {
         ERR("Out of memory.\n");
         buffer_unload(&buffer->resource);
@@ -1423,14 +1424,14 @@ HRESULT CDECL wined3d_buffer_create(struct wined3d_device *device, const struct
     TRACE("device %p, desc %p, data %p, parent %p, parent_ops %p, buffer %p.\n",
             device, desc, data, parent, parent_ops, buffer);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = buffer_init(object, device, desc->byte_width, desc->usage, WINED3DFMT_UNKNOWN,
             desc->access, desc->bind_flags, data, parent, parent_ops)))
     {
         WARN("Failed to initialize buffer, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
     object->desc = *desc;
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index e3e4834..8c2ea86 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -523,8 +523,7 @@ static struct fbo_entry *context_create_fbo_entry(const struct wined3d_context *
     unsigned int object_count = gl_info->limits.buffers + 1;
     struct fbo_entry *entry;
 
-    entry = HeapAlloc(GetProcessHeap(), 0,
-            FIELD_OFFSET(struct fbo_entry, key.objects[object_count]));
+    entry = heap_alloc(FIELD_OFFSET(struct fbo_entry, key.objects[object_count]));
     memset(&entry->key, 0, FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[object_count]));
     context_generate_fbo_key(context, &entry->key, render_targets, depth_stencil, color_location, ds_location);
     entry->flags = 0;
@@ -574,7 +573,7 @@ static void context_destroy_fbo_entry(struct wined3d_context *context, struct fb
     }
     --context->fbo_entry_count;
     list_remove(&entry->entry);
-    HeapFree(GetProcessHeap(), 0, entry);
+    heap_free(entry);
 }
 
 /* Context activation is done by the caller. */
@@ -1435,11 +1434,11 @@ static void context_destroy_gl_resources(struct wined3d_context *context)
         checkGLcall("context cleanup");
     }
 
-    HeapFree(GetProcessHeap(), 0, context->free_so_statistics_queries);
-    HeapFree(GetProcessHeap(), 0, context->free_pipeline_statistics_queries);
-    HeapFree(GetProcessHeap(), 0, context->free_timestamp_queries);
-    HeapFree(GetProcessHeap(), 0, context->free_occlusion_queries);
-    HeapFree(GetProcessHeap(), 0, context->free_fences);
+    heap_free(context->free_so_statistics_queries);
+    heap_free(context->free_pipeline_statistics_queries);
+    heap_free(context->free_timestamp_queries);
+    heap_free(context->free_occlusion_queries);
+    heap_free(context->free_fences);
 
     context_restore_pixel_format(context);
     if (restore_ctx)
@@ -1491,8 +1490,8 @@ BOOL context_set_current(struct wined3d_context *ctx)
         {
             TRACE("Switching away from destroyed context %p.\n", old);
             context_destroy_gl_resources(old);
-            HeapFree(GetProcessHeap(), 0, (void *)old->gl_info);
-            HeapFree(GetProcessHeap(), 0, old);
+            heap_free((void *)old->gl_info);
+            heap_free(old);
         }
         else
         {
@@ -1863,35 +1862,33 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
 
     wined3d_from_cs(device->cs);
 
-    ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ret));
-    if (!ret)
+    if (!(ret = heap_alloc_zero(sizeof(*ret))))
         return NULL;
 
-    if (!(ret->blit_targets = wined3d_calloc(gl_info->limits.buffers, sizeof(*ret->blit_targets))))
+    if (!(ret->blit_targets = heap_calloc(gl_info->limits.buffers, sizeof(*ret->blit_targets))))
         goto out;
 
-    if (!(ret->draw_buffers = wined3d_calloc(gl_info->limits.buffers, sizeof(*ret->draw_buffers))))
+    if (!(ret->draw_buffers = heap_calloc(gl_info->limits.buffers, sizeof(*ret->draw_buffers))))
         goto out;
 
-    ret->fbo_key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            FIELD_OFFSET(struct wined3d_fbo_entry_key, objects[gl_info->limits.buffers + 1]));
-    if (!ret->fbo_key)
+    if (!(ret->fbo_key = heap_alloc_zero(FIELD_OFFSET(struct wined3d_fbo_entry_key,
+            objects[gl_info->limits.buffers + 1]))))
         goto out;
 
     ret->free_timestamp_query_size = 4;
-    if (!(ret->free_timestamp_queries = wined3d_calloc(ret->free_timestamp_query_size,
+    if (!(ret->free_timestamp_queries = heap_calloc(ret->free_timestamp_query_size,
             sizeof(*ret->free_timestamp_queries))))
         goto out;
     list_init(&ret->timestamp_queries);
 
     ret->free_occlusion_query_size = 4;
-    if (!(ret->free_occlusion_queries = wined3d_calloc(ret->free_occlusion_query_size,
+    if (!(ret->free_occlusion_queries = heap_calloc(ret->free_occlusion_query_size,
             sizeof(*ret->free_occlusion_queries))))
         goto out;
     list_init(&ret->occlusion_queries);
 
     ret->free_fence_size = 4;
-    if (!(ret->free_fences = wined3d_calloc(ret->free_fence_size, sizeof(*ret->free_fences))))
+    if (!(ret->free_fences = heap_calloc(ret->free_fence_size, sizeof(*ret->free_fences))))
         goto out;
     list_init(&ret->fences);
 
@@ -1947,7 +1944,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
         }
     }
 
-    if (!(ret->texture_type = wined3d_calloc(gl_info->limits.combined_samplers,
+    if (!(ret->texture_type = heap_calloc(gl_info->limits.combined_samplers,
             sizeof(*ret->texture_type))))
         goto out;
 
@@ -2248,14 +2245,14 @@ out:
         wined3d_release_dc(swapchain->win_handle, ret->hdc);
     device->shader_backend->shader_free_context_data(ret);
     device->adapter->fragment_pipe->free_context_data(ret);
-    HeapFree(GetProcessHeap(), 0, ret->texture_type);
-    HeapFree(GetProcessHeap(), 0, ret->free_fences);
-    HeapFree(GetProcessHeap(), 0, ret->free_occlusion_queries);
-    HeapFree(GetProcessHeap(), 0, ret->free_timestamp_queries);
-    HeapFree(GetProcessHeap(), 0, ret->fbo_key);
-    HeapFree(GetProcessHeap(), 0, ret->draw_buffers);
-    HeapFree(GetProcessHeap(), 0, ret->blit_targets);
-    HeapFree(GetProcessHeap(), 0, ret);
+    heap_free(ret->texture_type);
+    heap_free(ret->free_fences);
+    heap_free(ret->free_occlusion_queries);
+    heap_free(ret->free_timestamp_queries);
+    heap_free(ret->fbo_key);
+    heap_free(ret->draw_buffers);
+    heap_free(ret->blit_targets);
+    heap_free(ret);
     return NULL;
 }
 
@@ -2288,7 +2285,7 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont
     {
         /* Make a copy of gl_info for context_destroy_gl_resources use, the one
            in wined3d_adapter may go away in the meantime */
-        struct wined3d_gl_info *gl_info = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_info));
+        struct wined3d_gl_info *gl_info = heap_alloc(sizeof(*gl_info));
         *gl_info = *context->gl_info;
         context->gl_info = gl_info;
         context->destroyed = 1;
@@ -2297,12 +2294,13 @@ void context_destroy(struct wined3d_device *device, struct wined3d_context *cont
 
     device->shader_backend->shader_free_context_data(context);
     device->adapter->fragment_pipe->free_context_data(context);
-    HeapFree(GetProcessHeap(), 0, context->texture_type);
-    HeapFree(GetProcessHeap(), 0, context->fbo_key);
-    HeapFree(GetProcessHeap(), 0, context->draw_buffers);
-    HeapFree(GetProcessHeap(), 0, context->blit_targets);
+    heap_free(context->texture_type);
+    heap_free(context->fbo_key);
+    heap_free(context->draw_buffers);
+    heap_free(context->blit_targets);
     device_context_remove(device, context);
-    if (destroy) HeapFree(GetProcessHeap(), 0, context);
+    if (destroy)
+        heap_free(context);
 }
 
 const DWORD *context_get_tex_unit_mapping(const struct wined3d_context *context,
diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c
index ed249f4..2f77c7b 100644
--- a/dlls/wined3d/cs.c
+++ b/dlls/wined3d/cs.c
@@ -1697,7 +1697,7 @@ static void wined3d_cs_exec_set_light(struct wined3d_cs *cs, const void *data)
     if (!(light_info = wined3d_state_get_light(&cs->state, light_idx)))
     {
         TRACE("Adding new light.\n");
-        if (!(light_info = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*light_info))))
+        if (!(light_info = heap_alloc_zero(sizeof(*light_info))))
         {
             ERR("Failed to allocate light info.\n");
             return;
@@ -2459,9 +2459,9 @@ static void *wined3d_cs_st_require_space(struct wined3d_cs *cs, size_t size, enu
 
         new_size = max(size, cs->data_size * 2);
         if (!cs->end)
-            new_data = HeapReAlloc(GetProcessHeap(), 0, cs->data, new_size);
+            new_data = heap_realloc(cs->data, new_size);
         else
-            new_data = HeapAlloc(GetProcessHeap(), 0, new_size);
+            new_data = heap_alloc(new_size);
         if (!new_data)
             return NULL;
 
@@ -2494,7 +2494,7 @@ static void wined3d_cs_st_submit(struct wined3d_cs *cs, enum wined3d_cs_queue_id
     if (cs->data == data)
         cs->start = cs->end = start;
     else if (!start)
-        HeapFree(GetProcessHeap(), 0, data);
+        heap_free(data);
 }
 
 static void wined3d_cs_st_finish(struct wined3d_cs *cs, enum wined3d_cs_queue_id queue_id)
@@ -2728,15 +2728,15 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     struct wined3d_cs *cs;
 
-    if (!(cs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cs))))
+    if (!(cs = heap_alloc_zero(sizeof(*cs))))
         return NULL;
 
     cs->ops = &wined3d_cs_st_ops;
     cs->device = device;
 
-    if (!(cs->fb.render_targets = wined3d_calloc(gl_info->limits.buffers, sizeof(*cs->fb.render_targets))))
+    if (!(cs->fb.render_targets = heap_calloc(gl_info->limits.buffers, sizeof(*cs->fb.render_targets))))
     {
-        HeapFree(GetProcessHeap(), 0, cs);
+        heap_free(cs);
         return NULL;
     }
 
@@ -2744,7 +2744,7 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
             WINED3D_STATE_NO_REF | WINED3D_STATE_INIT_DEFAULT);
 
     cs->data_size = WINED3D_INITIAL_CS_SIZE;
-    if (!(cs->data = HeapAlloc(GetProcessHeap(), 0, cs->data_size)))
+    if (!(cs->data = heap_alloc(cs->data_size)))
         goto fail;
 
     if (wined3d_settings.cs_multithreaded
@@ -2755,7 +2755,7 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
         if (!(cs->event = CreateEventW(NULL, FALSE, FALSE, NULL)))
         {
             ERR("Failed to create command stream event.\n");
-            HeapFree(GetProcessHeap(), 0, cs->data);
+            heap_free(cs->data);
             goto fail;
         }
 
@@ -2764,7 +2764,7 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
         {
             ERR("Failed to get wined3d module handle.\n");
             CloseHandle(cs->event);
-            HeapFree(GetProcessHeap(), 0, cs->data);
+            heap_free(cs->data);
             goto fail;
         }
 
@@ -2773,7 +2773,7 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
             ERR("Failed to create wined3d command stream thread.\n");
             FreeLibrary(cs->wined3d_module);
             CloseHandle(cs->event);
-            HeapFree(GetProcessHeap(), 0, cs->data);
+            heap_free(cs->data);
             goto fail;
         }
     }
@@ -2782,8 +2782,8 @@ struct wined3d_cs *wined3d_cs_create(struct wined3d_device *device)
 
 fail:
     state_cleanup(&cs->state);
-    HeapFree(GetProcessHeap(), 0, cs->fb.render_targets);
-    HeapFree(GetProcessHeap(), 0, cs);
+    heap_free(cs->fb.render_targets);
+    heap_free(cs);
     return NULL;
 }
 
@@ -2798,7 +2798,7 @@ void wined3d_cs_destroy(struct wined3d_cs *cs)
     }
 
     state_cleanup(&cs->state);
-    HeapFree(GetProcessHeap(), 0, cs->fb.render_targets);
-    HeapFree(GetProcessHeap(), 0, cs->data);
-    HeapFree(GetProcessHeap(), 0, cs);
+    heap_free(cs->fb.render_targets);
+    heap_free(cs->data);
+    heap_free(cs);
 }
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 3961f55..e412272 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -149,11 +149,7 @@ BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *c
 
     TRACE("Adding context %p.\n", context);
 
-    if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
-    else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts,
-            sizeof(*new_array) * (device->context_count + 1));
-
-    if (!new_array)
+    if (!(new_array = heap_realloc(device->contexts, sizeof(*new_array) * (device->context_count + 1))))
     {
         ERR("Failed to grow the context array.\n");
         return FALSE;
@@ -189,14 +185,13 @@ void device_context_remove(struct wined3d_device *device, struct wined3d_context
 
     if (!--device->context_count)
     {
-        HeapFree(GetProcessHeap(), 0, device->contexts);
+        heap_free(device->contexts);
         device->contexts = NULL;
         return;
     }
 
     memmove(&device->contexts[i], &device->contexts[i + 1], (device->context_count - i) * sizeof(*device->contexts));
-    new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, device->context_count * sizeof(*device->contexts));
-    if (!new_array)
+    if (!(new_array = heap_realloc(device->contexts, device->context_count * sizeof(*device->contexts))))
     {
         ERR("Failed to shrink context array. Oh well.\n");
         return;
@@ -491,7 +486,7 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
 
         for (i = 0; i < ARRAY_SIZE(device->multistate_funcs); ++i)
         {
-            HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
+            heap_free(device->multistate_funcs[i]);
             device->multistate_funcs[i] = NULL;
         }
 
@@ -518,7 +513,7 @@ ULONG CDECL wined3d_device_decref(struct wined3d_device *device)
 
         wined3d_decref(device->wined3d);
         device->wined3d = NULL;
-        HeapFree(GetProcessHeap(), 0, device);
+        heap_free(device);
         TRACE("Freed device %p.\n", device);
     }
 
@@ -1066,7 +1061,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
     if (device->wined3d->flags & WINED3D_NO3D)
         return WINED3DERR_INVALIDCALL;
 
-    if (!(device->fb.render_targets = wined3d_calloc(gl_info->limits.buffers, sizeof(*device->fb.render_targets))))
+    if (!(device->fb.render_targets = heap_calloc(gl_info->limits.buffers, sizeof(*device->fb.render_targets))))
         return E_OUTOFMEMORY;
 
     /* Setup the implicit swapchain. This also initializes a context. */
@@ -1099,7 +1094,7 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
     }
 
     device->swapchain_count = 1;
-    if (!(device->swapchains = wined3d_calloc(device->swapchain_count, sizeof(*device->swapchains))))
+    if (!(device->swapchains = heap_calloc(device->swapchain_count, sizeof(*device->swapchains))))
     {
         ERR("Out of memory!\n");
         goto err_out;
@@ -1129,13 +1124,13 @@ HRESULT CDECL wined3d_device_init_3d(struct wined3d_device *device,
     return WINED3D_OK;
 
 err_out:
-    HeapFree(GetProcessHeap(), 0, device->swapchains);
+    heap_free(device->swapchains);
     device->swapchain_count = 0;
     if (device->back_buffer_view)
         wined3d_rendertarget_view_decref(device->back_buffer_view);
     if (swapchain)
         wined3d_swapchain_decref(swapchain);
-    HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
+    heap_free(device->fb.render_targets);
 
     return hr;
 }
@@ -1159,7 +1154,7 @@ HRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
     }
 
     device->swapchain_count = 1;
-    if (!(device->swapchains = wined3d_calloc(device->swapchain_count, sizeof(*device->swapchains))))
+    if (!(device->swapchains = heap_calloc(device->swapchain_count, sizeof(*device->swapchains))))
     {
         ERR("Out of memory!\n");
         goto err_out;
@@ -1169,7 +1164,7 @@ HRESULT CDECL wined3d_device_init_gdi(struct wined3d_device *device,
     if (!(device->blitter = wined3d_cpu_blitter_create()))
     {
         ERR("Failed to create CPU blitter.\n");
-        HeapFree(GetProcessHeap(), 0, device->swapchains);
+        heap_free(device->swapchains);
         device->swapchain_count = 0;
         goto err_out;
     }
@@ -1246,11 +1241,11 @@ HRESULT CDECL wined3d_device_uninit_3d(struct wined3d_device *device)
             FIXME("Something's still holding the implicit swapchain.\n");
     }
 
-    HeapFree(GetProcessHeap(), 0, device->swapchains);
+    heap_free(device->swapchains);
     device->swapchains = NULL;
     device->swapchain_count = 0;
 
-    HeapFree(GetProcessHeap(), 0, device->fb.render_targets);
+    heap_free(device->fb.render_targets);
     device->fb.render_targets = NULL;
 
     device->d3d_initialized = FALSE;
@@ -1271,7 +1266,7 @@ HRESULT CDECL wined3d_device_uninit_gdi(struct wined3d_device *device)
             FIXME("Something's still holding the implicit swapchain.\n");
     }
 
-    HeapFree(GetProcessHeap(), 0, device->swapchains);
+    heap_free(device->swapchains);
     device->swapchains = NULL;
     device->swapchain_count = 0;
     return WINED3D_OK;
@@ -1589,8 +1584,7 @@ HRESULT CDECL wined3d_device_set_light(struct wined3d_device *device,
     if (!(object = wined3d_state_get_light(device->update_state, light_idx)))
     {
         TRACE("Adding new light\n");
-        object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-        if (!object)
+        if (!(object = heap_alloc_zero(sizeof(*object))))
             return E_OUTOFMEMORY;
 
         list_add_head(&device->update_state->light_map[hash_idx], &object->entry);
@@ -4608,7 +4602,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device
         /* 32-bit user32 cursors ignore the alpha channel if it's all
          * zeroes, and use the mask instead. Fill the mask with all ones
          * to ensure we still get a fully transparent cursor. */
-        if (!(mask_bits = HeapAlloc(GetProcessHeap(), 0, mask_size)))
+        if (!(mask_bits = heap_alloc(mask_size)))
             return E_OUTOFMEMORY;
         memset(mask_bits, 0xff, mask_size);
 
@@ -4633,7 +4627,7 @@ HRESULT CDECL wined3d_device_set_cursor_properties(struct wined3d_device *device
         if (device->bCursorVisible)
             SetCursor(cursor);
 
-        HeapFree(GetProcessHeap(), 0, mask_bits);
+        heap_free(mask_bits);
     }
 
     TRACE("New cursor dimensions are %ux%u.\n", cursor_width, cursor_height);
@@ -5208,7 +5202,7 @@ HRESULT device_init(struct wined3d_device *device, struct wined3d *wined3d,
 err:
     for (i = 0; i < ARRAY_SIZE(device->multistate_funcs); ++i)
     {
-        HeapFree(GetProcessHeap(), 0, device->multistate_funcs[i]);
+        heap_free(device->multistate_funcs[i]);
     }
     wine_rb_destroy(&device->samplers, NULL, NULL);
     wined3d_decref(device->wined3d);
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 924cc72..a1e679b 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -448,8 +448,8 @@ UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
 
 static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
 {
-    HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
-    HeapFree(GetProcessHeap(), 0, adapter->cfgs);
+    heap_free(adapter->gl_info.formats);
+    heap_free(adapter->cfgs);
 }
 
 ULONG CDECL wined3d_incref(struct wined3d *wined3d)
@@ -475,7 +475,7 @@ ULONG CDECL wined3d_decref(struct wined3d *wined3d)
         {
             wined3d_adapter_cleanup(&wined3d->adapters[i]);
         }
-        HeapFree(GetProcessHeap(), 0, wined3d);
+        heap_free(wined3d);
     }
 
     return refcount;
@@ -4638,11 +4638,11 @@ HRESULT CDECL wined3d_find_closest_matching_adapter_mode(const struct wined3d *w
         return E_FAIL;
     }
 
-    if (!(modes = wined3d_calloc(mode_count, sizeof(*modes))))
+    if (!(modes = heap_calloc(mode_count, sizeof(*modes))))
         return E_OUTOFMEMORY;
-    if (!(matching_modes = wined3d_calloc(mode_count, sizeof(*matching_modes))))
+    if (!(matching_modes = heap_calloc(mode_count, sizeof(*matching_modes))))
     {
-        HeapFree(GetProcessHeap(), 0, modes);
+        heap_free(modes);
         return E_OUTOFMEMORY;
     }
 
@@ -4651,8 +4651,8 @@ HRESULT CDECL wined3d_find_closest_matching_adapter_mode(const struct wined3d *w
         if (FAILED(hr = wined3d_enum_adapter_modes(wined3d, adapter_idx,
                 mode->format_id, WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &modes[i])))
         {
-            HeapFree(GetProcessHeap(), 0, matching_modes);
-            HeapFree(GetProcessHeap(), 0, modes);
+            heap_free(matching_modes);
+            heap_free(modes);
             return hr;
         }
         matching_modes[i] = &modes[i];
@@ -4688,8 +4688,8 @@ HRESULT CDECL wined3d_find_closest_matching_adapter_mode(const struct wined3d *w
         if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx,
                 &current_mode, NULL)))
         {
-            HeapFree(GetProcessHeap(), 0, matching_modes);
-            HeapFree(GetProcessHeap(), 0, modes);
+            heap_free(matching_modes);
+            heap_free(modes);
             return hr;
         }
         mode->width = current_mode.width;
@@ -4711,8 +4711,8 @@ HRESULT CDECL wined3d_find_closest_matching_adapter_mode(const struct wined3d *w
 
     *mode = *matching_modes[j];
 
-    HeapFree(GetProcessHeap(), 0, matching_modes);
-    HeapFree(GetProcessHeap(), 0, modes);
+    heap_free(matching_modes);
+    heap_free(modes);
 
     TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
             mode->refresh_rate, debug_d3dformat(mode->format_id),
@@ -6191,8 +6191,7 @@ HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, e
     if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = device_init(object, wined3d, adapter_idx, device_type,
@@ -6200,7 +6199,7 @@ HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, e
     if (FAILED(hr))
     {
         WARN("Failed to initialize device, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -6440,7 +6439,7 @@ static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter *adapter, HDC dc
         attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
         GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, 0, 0, 1, &attribute, &cfg_count));
 
-        adapter->cfgs = wined3d_calloc(cfg_count, sizeof(*adapter->cfgs));
+        adapter->cfgs = heap_calloc(cfg_count, sizeof(*adapter->cfgs));
         attribs[attrib_count++] = WGL_RED_BITS_ARB;
         attribs[attrib_count++] = WGL_GREEN_BITS_ARB;
         attribs[attrib_count++] = WGL_BLUE_BITS_ARB;
@@ -6505,7 +6504,7 @@ static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter *adapter, HDC dc
         int cfg_count;
 
         cfg_count = DescribePixelFormat(dc, 0, 0, 0);
-        adapter->cfgs = wined3d_calloc(cfg_count, sizeof(*adapter->cfgs));
+        adapter->cfgs = heap_calloc(cfg_count, sizeof(*adapter->cfgs));
 
         for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
         {
@@ -6666,7 +6665,7 @@ static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal,
     {
         WARN("No suitable pixel formats found.\n");
         wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
-        HeapFree(GetProcessHeap(), 0, adapter->cfgs);
+        heap_free(adapter->cfgs);
         return FALSE;
     }
 
@@ -6674,7 +6673,7 @@ static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal,
     {
         ERR("Failed to initialize GL format info.\n");
         wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
-        HeapFree(GetProcessHeap(), 0, adapter->cfgs);
+        heap_free(adapter->cfgs);
         return FALSE;
     }
 
diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c
index 6f59cf1..6cc030a 100644
--- a/dlls/wined3d/glsl_shader.c
+++ b/dlls/wined3d/glsl_shader.c
@@ -474,7 +474,7 @@ void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLuint id, BOOL
     {
         const char *ptr, *line;
 
-        log = HeapAlloc(GetProcessHeap(), 0, length);
+        log = heap_alloc(length);
         /* The info log is supposed to be zero-terminated, but at least some
          * versions of fglrx don't terminate the string properly. The reported
          * length does include the terminator, so explicitly set it to zero
@@ -496,7 +496,7 @@ void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLuint id, BOOL
             FIXME("Info log received from GLSL shader #%u:\n", id);
             while ((line = get_info_log_line(&ptr))) FIXME("    %.*s", (int)(ptr - line), line);
         }
-        HeapFree(GetProcessHeap(), 0, log);
+        heap_free(log);
     }
 }
 
@@ -528,7 +528,7 @@ static void shader_glsl_dump_program_source(const struct wined3d_gl_info *gl_inf
     char *source = NULL;
 
     GL_EXTCALL(glGetProgramiv(program, GL_ATTACHED_SHADERS, &shader_count));
-    if (!(shaders = wined3d_calloc(shader_count, sizeof(*shaders))))
+    if (!(shaders = heap_calloc(shader_count, sizeof(*shaders))))
     {
         ERR("Failed to allocate shader array memory.\n");
         return;
@@ -544,13 +544,12 @@ static void shader_glsl_dump_program_source(const struct wined3d_gl_info *gl_inf
 
         if (source_size < tmp)
         {
-            HeapFree(GetProcessHeap(), 0, source);
+            heap_free(source);
 
-            source = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, tmp);
-            if (!source)
+            if (!(source = heap_alloc_zero(tmp)))
             {
                 ERR("Failed to allocate %d bytes for shader source.\n", tmp);
-                HeapFree(GetProcessHeap(), 0, shaders);
+                heap_free(shaders);
                 return;
             }
             source_size = tmp;
@@ -569,8 +568,8 @@ static void shader_glsl_dump_program_source(const struct wined3d_gl_info *gl_inf
         FIXME("\n");
     }
 
-    HeapFree(GetProcessHeap(), 0, source);
-    HeapFree(GetProcessHeap(), 0, shaders);
+    heap_free(source);
+    heap_free(shaders);
 }
 
 /* Context activation is done by the caller. */
@@ -944,16 +943,16 @@ static void shader_glsl_init_transform_feedback(const struct wined3d_context *co
 
     shader_glsl_generate_transform_feedback_varyings(so_desc, buffer, NULL, &count, NULL, &length, mode);
 
-    if (!(varyings = wined3d_calloc(count, sizeof(*varyings))))
+    if (!(varyings = heap_calloc(count, sizeof(*varyings))))
     {
         ERR("Out of memory.\n");
         string_buffer_release(&priv->string_buffers, buffer);
         return;
     }
-    if (!(strings = wined3d_calloc(length, sizeof(*strings))))
+    if (!(strings = heap_calloc(length, sizeof(*strings))))
     {
         ERR("Out of memory.\n");
-        HeapFree(GetProcessHeap(), 0, varyings);
+        heap_free(varyings);
         string_buffer_release(&priv->string_buffers, buffer);
         return;
     }
@@ -962,8 +961,8 @@ static void shader_glsl_init_transform_feedback(const struct wined3d_context *co
     GL_EXTCALL(glTransformFeedbackVaryings(program_id, count, varyings, mode));
     checkGLcall("glTransformFeedbackVaryings");
 
-    HeapFree(GetProcessHeap(), 0, varyings);
-    HeapFree(GetProcessHeap(), 0, strings);
+    heap_free(varyings);
+    heap_free(strings);
     string_buffer_release(&priv->string_buffers, buffer);
 }
 
@@ -6849,7 +6848,7 @@ static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const struc
         list_remove(&entry->ps.shader_entry);
     if (entry->cs.id)
         list_remove(&entry->cs.shader_entry);
-    HeapFree(GetProcessHeap(), 0, entry);
+    heap_free(entry);
 }
 
 static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
@@ -6868,7 +6867,7 @@ static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
     unsigned int i, j;
     char reg_mask[6];
 
-    set = wined3d_calloc(max_varyings, sizeof(*set));
+    set = heap_calloc(max_varyings, sizeof(*set));
 
     for (i = 0; i < input_signature->element_count; ++i)
     {
@@ -6952,7 +6951,7 @@ static void shader_glsl_setup_vs3_output(struct shader_glsl_priv *priv,
             shader_addline(buffer, "%s.%s = vec%u(0.0);\n", destination->buffer, reg_mask, size);
     }
 
-    HeapFree(GetProcessHeap(), 0, set);
+    heap_free(set);
     string_buffer_release(&priv->string_buffers, destination);
 }
 
@@ -8293,8 +8292,7 @@ static GLuint find_glsl_pshader(const struct wined3d_context *context,
 
     if (!shader->backend_data)
     {
-        shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-        if (!shader->backend_data)
+        if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
         {
             ERR("Failed to allocate backend data.\n");
             return 0;
@@ -8318,16 +8316,16 @@ static GLuint find_glsl_pshader(const struct wined3d_context *context,
     }
 
     TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
-    if(shader_data->shader_array_size == shader_data->num_gl_shaders) {
+    if (shader_data->shader_array_size == shader_data->num_gl_shaders)
+    {
         if (shader_data->num_gl_shaders)
         {
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
-            new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders.ps,
-                    new_size * sizeof(*gl_shaders));
+            new_array = heap_realloc(shader_data->gl_shaders.ps, new_size * sizeof(*gl_shaders));
         }
         else
         {
-            new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_shaders));
+            new_array = heap_alloc(sizeof(*gl_shaders));
             new_size = 1;
         }
 
@@ -8385,8 +8383,7 @@ static GLuint find_glsl_vshader(const struct wined3d_context *context, struct sh
 
     if (!shader->backend_data)
     {
-        shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-        if (!shader->backend_data)
+        if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
         {
             ERR("Failed to allocate backend data.\n");
             return 0;
@@ -8407,16 +8404,16 @@ static GLuint find_glsl_vshader(const struct wined3d_context *context, struct sh
 
     TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
 
-    if(shader_data->shader_array_size == shader_data->num_gl_shaders) {
+    if (shader_data->shader_array_size == shader_data->num_gl_shaders)
+    {
         if (shader_data->num_gl_shaders)
         {
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
-            new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders.vs,
-                    new_size * sizeof(*gl_shaders));
+            new_array = heap_realloc(shader_data->gl_shaders.vs, new_size * sizeof(*gl_shaders));
         }
         else
         {
-            new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_shaders));
+            new_array = heap_alloc(sizeof(*gl_shaders));
             new_size = 1;
         }
 
@@ -8448,7 +8445,7 @@ static GLuint find_glsl_hull_shader(const struct wined3d_context *context,
 
     if (!shader->backend_data)
     {
-        if (!(shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data))))
+        if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
         {
             ERR("Failed to allocate backend data.\n");
             return 0;
@@ -8466,9 +8463,8 @@ static GLuint find_glsl_hull_shader(const struct wined3d_context *context,
     TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
 
     assert(!shader_data->gl_shaders.hs);
-    new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
     new_size = 1;
-    if (!new_array)
+    if (!(new_array = heap_alloc(sizeof(*new_array))))
     {
         ERR("Failed to allocate GL shaders array.\n");
         return 0;
@@ -8494,7 +8490,7 @@ static GLuint find_glsl_domain_shader(const struct wined3d_context *context,
 
     if (!shader->backend_data)
     {
-        if (!(shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data))))
+        if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
         {
             ERR("Failed to allocate backend data.\n");
             return 0;
@@ -8514,12 +8510,11 @@ static GLuint find_glsl_domain_shader(const struct wined3d_context *context,
     if (shader_data->num_gl_shaders)
     {
         new_size = shader_data->shader_array_size + 1;
-        new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders.ds,
-                new_size * sizeof(*new_array));
+        new_array = heap_realloc(shader_data->gl_shaders.ds, new_size * sizeof(*new_array));
     }
     else
     {
-        new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
+        new_array = heap_alloc(sizeof(*new_array));
         new_size = 1;
     }
 
@@ -8550,7 +8545,7 @@ static GLuint find_glsl_geometry_shader(const struct wined3d_context *context,
 
     if (!shader->backend_data)
     {
-        if (!(shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data))))
+        if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
         {
             ERR("Failed to allocate backend data.\n");
             return 0;
@@ -8570,12 +8565,11 @@ static GLuint find_glsl_geometry_shader(const struct wined3d_context *context,
     if (shader_data->num_gl_shaders)
     {
         new_size = shader_data->shader_array_size + 1;
-        new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders.gs,
-                new_size * sizeof(*new_array));
+        new_array = heap_realloc(shader_data->gl_shaders.gs, new_size * sizeof(*new_array));
     }
     else
     {
-        new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
+        new_array = heap_alloc(sizeof(*new_array));
         new_size = 1;
     }
 
@@ -9721,7 +9715,7 @@ static struct glsl_ffp_vertex_shader *shader_glsl_find_ffp_vertex_shader(struct
     if ((entry = wine_rb_get(&priv->ffp_vertex_shaders, settings)))
         return WINE_RB_ENTRY_VALUE(entry, struct glsl_ffp_vertex_shader, desc.entry);
 
-    if (!(shader = HeapAlloc(GetProcessHeap(), 0, sizeof(*shader))))
+    if (!(shader = heap_alloc(sizeof(*shader))))
         return NULL;
 
     shader->desc.settings = *settings;
@@ -9742,7 +9736,7 @@ static struct glsl_ffp_fragment_shader *shader_glsl_find_ffp_fragment_shader(str
     if ((desc = find_ffp_frag_shader(&priv->ffp_fragment_shaders, args)))
         return CONTAINING_RECORD(desc, struct glsl_ffp_fragment_shader, entry);
 
-    if (!(glsl_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*glsl_desc))))
+    if (!(glsl_desc = heap_alloc(sizeof(*glsl_desc))))
         return NULL;
 
     glsl_desc->entry.settings = *args;
@@ -9914,26 +9908,26 @@ static HRESULT shader_glsl_compile_compute_shader(struct shader_glsl_priv *priv,
     struct glsl_shader_prog_link *entry;
     GLuint shader_id, program_id;
 
-    if (!(entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry))))
+    if (!(entry = heap_alloc(sizeof(*entry))))
     {
         ERR("Out of memory.\n");
         return E_OUTOFMEMORY;
     }
 
-    if (!(shader->backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data))))
+    if (!(shader->backend_data = heap_alloc_zero(sizeof(*shader_data))))
     {
         ERR("Failed to allocate backend data.\n");
-        HeapFree(GetProcessHeap(), 0, entry);
+        heap_free(entry);
         return E_OUTOFMEMORY;
     }
     shader_data = shader->backend_data;
     gl_shaders = shader_data->gl_shaders.cs;
 
-    if (!(shader_data->gl_shaders.cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*gl_shaders))))
+    if (!(shader_data->gl_shaders.cs = heap_alloc(sizeof(*gl_shaders))))
     {
         ERR("Failed to allocate GL shader array.\n");
-        HeapFree(GetProcessHeap(), 0, entry);
-        HeapFree(GetProcessHeap(), 0, shader->backend_data);
+        heap_free(entry);
+        heap_free(shader->backend_data);
         shader->backend_data = NULL;
         return E_OUTOFMEMORY;
     }
@@ -10166,7 +10160,7 @@ static void set_glsl_shader_program(const struct wined3d_context *context, const
     TRACE("Created new GLSL shader program %u.\n", program_id);
 
     /* Create the entry */
-    entry = HeapAlloc(GetProcessHeap(), 0, sizeof(struct glsl_shader_prog_link));
+    entry = heap_alloc(sizeof(*entry));
     entry->id = program_id;
     entry->vs.id = vs_id;
     entry->hs.id = hs_id;
@@ -10610,7 +10604,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
 
     if (!shader_data || !shader_data->num_gl_shaders)
     {
-        HeapFree(GetProcessHeap(), 0, shader_data);
+        heap_free(shader_data);
         shader->backend_data = NULL;
         return;
     }
@@ -10637,7 +10631,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.ps);
+                heap_free(shader_data->gl_shaders.ps);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, ps.shader_entry)
@@ -10659,7 +10653,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.vs);
+                heap_free(shader_data->gl_shaders.vs);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, vs.shader_entry)
@@ -10681,7 +10675,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.hs);
+                heap_free(shader_data->gl_shaders.hs);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, hs.shader_entry)
@@ -10703,7 +10697,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.ds);
+                heap_free(shader_data->gl_shaders.ds);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, ds.shader_entry)
@@ -10725,7 +10719,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.gs);
+                heap_free(shader_data->gl_shaders.gs);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, gs.shader_entry)
@@ -10747,7 +10741,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
                     GL_EXTCALL(glDeleteShader(gl_shaders[i].id));
                     checkGLcall("glDeleteShader");
                 }
-                HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders.cs);
+                heap_free(shader_data->gl_shaders.cs);
 
                 LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, linked_programs,
                         struct glsl_shader_prog_link, cs.shader_entry)
@@ -10765,7 +10759,7 @@ static void shader_glsl_destroy(struct wined3d_shader *shader)
         }
     }
 
-    HeapFree(GetProcessHeap(), 0, shader->backend_data);
+    heap_free(shader->backend_data);
     shader->backend_data = NULL;
 
     context_release(context);
@@ -10803,9 +10797,9 @@ static BOOL constant_heap_init(struct constant_heap *heap, unsigned int constant
     SIZE_T size = (constant_count + 1) * sizeof(*heap->entries)
             + constant_count * sizeof(*heap->contained)
             + constant_count * sizeof(*heap->positions);
-    void *mem = HeapAlloc(GetProcessHeap(), 0, size);
+    void *mem;
 
-    if (!mem)
+    if (!(mem = heap_alloc(size)))
     {
         ERR("Failed to allocate memory\n");
         return FALSE;
@@ -10823,24 +10817,27 @@ static BOOL constant_heap_init(struct constant_heap *heap, unsigned int constant
 
 static void constant_heap_free(struct constant_heap *heap)
 {
-    HeapFree(GetProcessHeap(), 0, heap->entries);
+    heap_free(heap->entries);
 }
 
 static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct wined3d_vertex_pipe_ops *vertex_pipe,
         const struct fragment_pipeline *fragment_pipe)
 {
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
     SIZE_T stack_size = wined3d_log2i(max(WINED3D_MAX_VS_CONSTS_F, WINED3D_MAX_PS_CONSTS_F)) + 1;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     struct fragment_caps fragment_caps;
     void *vertex_priv, *fragment_priv;
+    struct shader_glsl_priv *priv;
+
+    if (!(priv = heap_alloc_zero(sizeof(*priv))))
+        return E_OUTOFMEMORY;
 
     string_buffer_list_init(&priv->string_buffers);
 
     if (!(vertex_priv = vertex_pipe->vp_alloc(&glsl_shader_backend, priv)))
     {
         ERR("Failed to initialize vertex pipe.\n");
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -10848,7 +10845,7 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
     {
         ERR("Failed to initialize fragment pipe.\n");
         vertex_pipe->vp_free(device);
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -10858,7 +10855,7 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
         goto fail;
     }
 
-    if (!(priv->stack = wined3d_calloc(stack_size, sizeof(*priv->stack))))
+    if (!(priv->stack = heap_calloc(stack_size, sizeof(*priv->stack))))
     {
         ERR("Failed to allocate memory.\n");
         goto fail;
@@ -10894,11 +10891,11 @@ static HRESULT shader_glsl_alloc(struct wined3d_device *device, const struct win
 fail:
     constant_heap_free(&priv->pconst_heap);
     constant_heap_free(&priv->vconst_heap);
-    HeapFree(GetProcessHeap(), 0, priv->stack);
+    heap_free(priv->stack);
     string_buffer_free(&priv->shader_buffer);
     fragment_pipe->free_private(device);
     vertex_pipe->vp_free(device);
-    HeapFree(GetProcessHeap(), 0, priv);
+    heap_free(priv);
     return E_OUTOFMEMORY;
 }
 
@@ -10910,20 +10907,21 @@ static void shader_glsl_free(struct wined3d_device *device)
     wine_rb_destroy(&priv->program_lookup, NULL, NULL);
     constant_heap_free(&priv->pconst_heap);
     constant_heap_free(&priv->vconst_heap);
-    HeapFree(GetProcessHeap(), 0, priv->stack);
+    heap_free(priv->stack);
     string_buffer_list_cleanup(&priv->string_buffers);
     string_buffer_free(&priv->shader_buffer);
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
 
-    HeapFree(GetProcessHeap(), 0, device->shader_priv);
+    heap_free(device->shader_priv);
     device->shader_priv = NULL;
 }
 
 static BOOL shader_glsl_allocate_context_data(struct wined3d_context *context)
 {
     struct glsl_context_data *ctx_data;
-    if (!(ctx_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ctx_data))))
+
+    if (!(ctx_data = heap_alloc_zero(sizeof(*ctx_data))))
         return FALSE;
     ctx_data->vertex_color_clamp = GL_FIXED_ONLY_ARB;
     context->shader_backend_data = ctx_data;
@@ -10932,7 +10930,7 @@ static BOOL shader_glsl_allocate_context_data(struct wined3d_context *context)
 
 static void shader_glsl_free_context_data(struct wined3d_context *context)
 {
-    HeapFree(GetProcessHeap(), 0, context->shader_backend_data);
+    heap_free(context->shader_backend_data);
 }
 
 static void shader_glsl_init_context_state(struct wined3d_context *context)
@@ -11372,7 +11370,7 @@ static void shader_glsl_free_ffp_vertex_shader(struct wine_rb_entry *entry, void
         delete_glsl_program_entry(ctx->priv, ctx->gl_info, program);
     }
     ctx->gl_info->gl_ops.ext.p_glDeleteShader(shader->id);
-    HeapFree(GetProcessHeap(), 0, shader);
+    heap_free(shader);
 }
 
 /* Context activation is done by the caller. */
@@ -11869,7 +11867,7 @@ static void shader_glsl_free_ffp_fragment_shader(struct wine_rb_entry *entry, vo
         delete_glsl_program_entry(ctx->priv, ctx->gl_info, program);
     }
     ctx->gl_info->gl_ops.ext.p_glDeleteShader(shader->id);
-    HeapFree(GetProcessHeap(), 0, shader);
+    heap_free(shader);
 }
 
 /* Context activation is done by the caller. */
diff --git a/dlls/wined3d/palette.c b/dlls/wined3d/palette.c
index ed77604..2436100 100644
--- a/dlls/wined3d/palette.c
+++ b/dlls/wined3d/palette.c
@@ -35,7 +35,7 @@ ULONG CDECL wined3d_palette_incref(struct wined3d_palette *palette)
 
 static void wined3d_palette_destroy_object(void *object)
 {
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_palette_decref(struct wined3d_palette *palette)
@@ -160,14 +160,13 @@ HRESULT CDECL wined3d_palette_create(struct wined3d_device *device, DWORD flags,
     TRACE("device %p, flags %#x, entry_count %u, entries %p, palette %p.\n",
             device, flags, entry_count, entries, palette);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_palette_init(object, device, flags, entry_count, entries)))
     {
         WARN("Failed to initialize palette, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c
index 1bdaaf0..9828fc2 100644
--- a/dlls/wined3d/query.c
+++ b/dlls/wined3d/query.c
@@ -286,7 +286,7 @@ static void wined3d_fence_free(struct wined3d_fence *fence)
 void wined3d_fence_destroy(struct wined3d_fence *fence)
 {
     wined3d_fence_free(fence);
-    HeapFree(GetProcessHeap(), 0, fence);
+    heap_free(fence);
 }
 
 static HRESULT wined3d_fence_init(struct wined3d_fence *fence, const struct wined3d_gl_info *gl_info)
@@ -308,12 +308,12 @@ HRESULT wined3d_fence_create(struct wined3d_device *device, struct wined3d_fence
 
     TRACE("device %p, fence %p.\n", device, fence);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_fence_init(object, gl_info)))
     {
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -918,7 +918,7 @@ static void wined3d_event_query_ops_destroy(struct wined3d_query *query)
     struct wined3d_event_query *event_query = wined3d_event_query_from_query(query);
 
     wined3d_fence_free(&event_query->fence);
-    HeapFree(GetProcessHeap(), 0, event_query);
+    heap_free(event_query);
 }
 
 static const struct wined3d_query_ops event_query_ops =
@@ -939,13 +939,13 @@ static HRESULT wined3d_event_query_create(struct wined3d_device *device,
     TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
             device, type, parent, parent_ops, query);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_fence_init(&object->fence, gl_info)))
     {
         WARN("Event queries not supported.\n");
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -964,7 +964,7 @@ static void wined3d_occlusion_query_ops_destroy(struct wined3d_query *query)
 
     if (oq->context)
         context_free_occlusion_query(oq);
-    HeapFree(GetProcessHeap(), 0, oq);
+    heap_free(oq);
 }
 
 static const struct wined3d_query_ops occlusion_query_ops =
@@ -990,7 +990,7 @@ static HRESULT wined3d_occlusion_query_create(struct wined3d_device *device,
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     wined3d_query_init(&object->query, device, type, &object->samples,
@@ -1008,7 +1008,7 @@ static void wined3d_timestamp_query_ops_destroy(struct wined3d_query *query)
 
     if (tq->context)
         context_free_timestamp_query(tq);
-    HeapFree(GetProcessHeap(), 0, tq);
+    heap_free(tq);
 }
 
 static const struct wined3d_query_ops timestamp_query_ops =
@@ -1034,7 +1034,7 @@ static HRESULT wined3d_timestamp_query_create(struct wined3d_device *device,
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     wined3d_query_init(&object->query, device, type, &object->timestamp,
@@ -1048,7 +1048,7 @@ static HRESULT wined3d_timestamp_query_create(struct wined3d_device *device,
 
 static void wined3d_timestamp_disjoint_query_ops_destroy(struct wined3d_query *query)
 {
-    HeapFree(GetProcessHeap(), 0, query);
+    heap_free(query);
 }
 
 static const struct wined3d_query_ops timestamp_disjoint_query_ops =
@@ -1074,7 +1074,7 @@ static HRESULT wined3d_timestamp_disjoint_query_create(struct wined3d_device *de
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
@@ -1104,7 +1104,7 @@ static void wined3d_so_statistics_query_ops_destroy(struct wined3d_query *query)
 
     if (pq->context)
         context_free_so_statistics_query(pq);
-    HeapFree(GetProcessHeap(), 0, pq);
+    heap_free(pq);
 }
 
 static const struct wined3d_query_ops so_statistics_query_ops =
@@ -1141,7 +1141,7 @@ static HRESULT wined3d_so_statistics_query_create(struct wined3d_device *device,
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     wined3d_query_init(&object->query, device, type, &object->statistics,
@@ -1159,7 +1159,7 @@ static void wined3d_pipeline_query_ops_destroy(struct wined3d_query *query)
     struct wined3d_pipeline_statistics_query *pq = wined3d_pipeline_statistics_query_from_query(query);
     if (pq->context)
         context_free_pipeline_statistics_query(pq);
-    HeapFree(GetProcessHeap(), 0, pq);
+    heap_free(pq);
 }
 
 static const struct wined3d_query_ops pipeline_query_ops =
@@ -1185,7 +1185,7 @@ static HRESULT wined3d_pipeline_query_create(struct wined3d_device *device,
         return WINED3DERR_NOTAVAILABLE;
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     wined3d_query_init(&object->query, device, type, &object->statistics,
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 76f877cb..22c2f48 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -374,7 +374,7 @@ BOOL wined3d_resource_allocate_sysmem(struct wined3d_resource *resource)
     SIZE_T align = RESOURCE_ALIGNMENT - 1 + sizeof(*p);
     void *mem;
 
-    if (!(mem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, resource->size + align)))
+    if (!(mem = heap_alloc_zero(resource->size + align)))
         return FALSE;
 
     p = (void **)(((ULONG_PTR)mem + align) & ~(RESOURCE_ALIGNMENT - 1)) - 1;
@@ -392,7 +392,7 @@ void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
     if (!p)
         return;
 
-    HeapFree(GetProcessHeap(), 0, *(--p));
+    heap_free(*(--p));
     resource->heap_memory = NULL;
 }
 
diff --git a/dlls/wined3d/sampler.c b/dlls/wined3d/sampler.c
index 8c8d24c..82fbe2c 100644
--- a/dlls/wined3d/sampler.c
+++ b/dlls/wined3d/sampler.c
@@ -47,7 +47,7 @@ static void wined3d_sampler_destroy_object(void *object)
         context_release(context);
     }
 
-    HeapFree(GetProcessHeap(), 0, sampler);
+    heap_free(sampler);
 }
 
 ULONG CDECL wined3d_sampler_decref(struct wined3d_sampler *sampler)
@@ -144,7 +144,7 @@ HRESULT CDECL wined3d_sampler_create(struct wined3d_device *device, const struct
             || desc->mip_filter > WINED3D_TEXF_LINEAR)
         return WINED3DERR_INVALIDCALL;
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     wined3d_sampler_init(object, device, desc, parent, parent_ops);
diff --git a/dlls/wined3d/shader.c b/dlls/wined3d/shader.c
index 424025c..66e1bbf 100644
--- a/dlls/wined3d/shader.c
+++ b/dlls/wined3d/shader.c
@@ -428,7 +428,7 @@ void string_buffer_clear(struct wined3d_string_buffer *buffer)
 BOOL string_buffer_init(struct wined3d_string_buffer *buffer)
 {
     buffer->buffer_size = 32;
-    if (!(buffer->buffer = HeapAlloc(GetProcessHeap(), 0, buffer->buffer_size)))
+    if (!(buffer->buffer = heap_alloc(buffer->buffer_size)))
     {
         ERR("Failed to allocate shader buffer memory.\n");
         return FALSE;
@@ -440,7 +440,7 @@ BOOL string_buffer_init(struct wined3d_string_buffer *buffer)
 
 void string_buffer_free(struct wined3d_string_buffer *buffer)
 {
-    HeapFree(GetProcessHeap(), 0, buffer->buffer);
+    heap_free(buffer->buffer);
 }
 
 BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc)
@@ -450,7 +450,7 @@ BOOL string_buffer_resize(struct wined3d_string_buffer *buffer, int rc)
 
     while (rc > 0 && (unsigned int)rc >= new_buffer_size - buffer->content_size)
         new_buffer_size *= 2;
-    if (!(new_buffer = HeapReAlloc(GetProcessHeap(), 0, buffer->buffer, new_buffer_size)))
+    if (!(new_buffer = heap_realloc(buffer->buffer, new_buffer_size)))
     {
         ERR("Failed to grow buffer.\n");
         buffer->buffer[buffer->content_size] = '\0';
@@ -498,11 +498,11 @@ struct wined3d_string_buffer *string_buffer_get(struct wined3d_string_buffer_lis
 
     if (list_empty(&list->list))
     {
-        buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer));
+        buffer = heap_alloc(sizeof(*buffer));
         if (!buffer || !string_buffer_init(buffer))
         {
             ERR("Couldn't allocate buffer for temporary string.\n");
-            HeapFree(GetProcessHeap(), 0, buffer);
+            heap_free(buffer);
             return NULL;
         }
     }
@@ -559,7 +559,7 @@ void string_buffer_list_cleanup(struct wined3d_string_buffer_list *list)
     LIST_FOR_EACH_ENTRY_SAFE(buffer, buffer_next, &list->list, struct wined3d_string_buffer, entry)
     {
         string_buffer_free(buffer);
-        HeapFree(GetProcessHeap(), 0, buffer);
+        heap_free(buffer);
     }
     list_init(&list->list);
 }
@@ -585,7 +585,7 @@ static void shader_delete_constant_list(struct list *clist)
     struct wined3d_shader_lconst *constant, *constant_next;
 
     LIST_FOR_EACH_ENTRY_SAFE(constant, constant_next, clist, struct wined3d_shader_lconst, entry)
-        HeapFree(GetProcessHeap(), 0, constant);
+        heap_free(constant);
     list_init(clist);
 }
 
@@ -826,7 +826,7 @@ static void shader_record_sample(struct wined3d_shader_reg_maps *reg_maps,
 
     if (!map->size)
     {
-        if (!(entries = wined3d_calloc(4, sizeof(*entries))))
+        if (!(entries = heap_calloc(4, sizeof(*entries))))
         {
             ERR("Failed to allocate sampler map entries.\n");
             return;
@@ -839,7 +839,7 @@ static void shader_record_sample(struct wined3d_shader_reg_maps *reg_maps,
         size_t new_size = map->size * 2;
 
         if (sizeof(*entries) * new_size <= sizeof(*entries) * map->size
-                || !(entries = HeapReAlloc(GetProcessHeap(), 0, entries, sizeof(*entries) * new_size)))
+                || !(entries = heap_realloc(entries, sizeof(*entries) * new_size)))
         {
             ERR("Failed to resize sampler map entries.\n");
             return;
@@ -925,10 +925,9 @@ static HRESULT shader_record_shader_phase(struct wined3d_shader *shader,
             if (shader->u.hs.phases.control_point)
             {
                 FIXME("Multiple control point phases.\n");
-                HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.control_point);
+                heap_free(shader->u.hs.phases.control_point);
             }
-            if (!(shader->u.hs.phases.control_point = HeapAlloc(GetProcessHeap(),
-                    HEAP_ZERO_MEMORY, sizeof(*shader->u.hs.phases.control_point))))
+            if (!(shader->u.hs.phases.control_point = heap_alloc_zero(sizeof(*shader->u.hs.phases.control_point))))
                 return E_OUTOFMEMORY;
             phase = shader->u.hs.phases.control_point;
             break;
@@ -1011,7 +1010,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
 
     shader_set_limits(shader);
 
-    if (!(reg_maps->constf = wined3d_calloc(((min(shader->limits->constant_float, constf_size) + 31) / 32),
+    if (!(reg_maps->constf = heap_calloc(((min(shader->limits->constant_float, constf_size) + 31) / 32),
             sizeof(*reg_maps->constf))))
     {
         ERR("Failed to allocate constant map memory.\n");
@@ -1156,7 +1155,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
             {
                 struct wined3d_shader_indexable_temp *reg;
 
-                if (!(reg = HeapAlloc(GetProcessHeap(), 0, sizeof(*reg))))
+                if (!(reg = heap_alloc(sizeof(*reg))))
                     return E_OUTOFMEMORY;
 
                 *reg = ins.declaration.indexable_temp;
@@ -1336,9 +1335,11 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEF)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
+            struct wined3d_shader_lconst *lconst;
             float *value;
-            if (!lconst) return E_OUTOFMEMORY;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, 4 * sizeof(DWORD));
@@ -1367,8 +1368,10 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEFI)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
-            if (!lconst) return E_OUTOFMEMORY;
+            struct wined3d_shader_lconst *lconst;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, 4 * sizeof(DWORD));
@@ -1378,8 +1381,10 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         }
         else if (ins.handler_idx == WINED3DSIH_DEFB)
         {
-            struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
-            if (!lconst) return E_OUTOFMEMORY;
+            struct wined3d_shader_lconst *lconst;
+
+            if (!(lconst = heap_alloc(sizeof(*lconst))))
+                return E_OUTOFMEMORY;
 
             lconst->idx = ins.dst[0].reg.idx[0].offset;
             memcpy(lconst->value, ins.src[0].reg.u.immconst_data, sizeof(DWORD));
@@ -1759,7 +1764,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         struct wined3d_shader_signature_element *e;
         unsigned int i;
 
-        if (!(input_signature->elements = wined3d_calloc(count, sizeof(*input_signature->elements))))
+        if (!(input_signature->elements = heap_calloc(count, sizeof(*input_signature->elements))))
             return E_OUTOFMEMORY;
         input_signature->element_count = count;
 
@@ -1800,7 +1805,7 @@ static HRESULT shader_get_registers_used(struct wined3d_shader *shader, const st
         unsigned int count = wined3d_popcount(reg_maps->output_registers);
         struct wined3d_shader_signature_element *e;
 
-        if (!(output_signature->elements = wined3d_calloc(count, sizeof(*output_signature->elements))))
+        if (!(output_signature->elements = heap_calloc(count, sizeof(*output_signature->elements))))
             return E_OUTOFMEMORY;
         output_signature->element_count = count;
 
@@ -1820,14 +1825,14 @@ static void shader_cleanup_reg_maps(struct wined3d_shader_reg_maps *reg_maps)
 {
     struct wined3d_shader_indexable_temp *reg, *reg_next;
 
-    HeapFree(GetProcessHeap(), 0, reg_maps->constf);
-    HeapFree(GetProcessHeap(), 0, reg_maps->sampler_map.entries);
+    heap_free(reg_maps->constf);
+    heap_free(reg_maps->sampler_map.entries);
 
     LIST_FOR_EACH_ENTRY_SAFE(reg, reg_next, &reg_maps->indexable_temps, struct wined3d_shader_indexable_temp, entry)
-        HeapFree(GetProcessHeap(), 0, reg);
+        heap_free(reg);
     list_init(&reg_maps->indexable_temps);
 
-    HeapFree(GetProcessHeap(), 0, reg_maps->tgsm);
+    heap_free(reg_maps->tgsm);
 }
 
 unsigned int shader_find_free_input_register(const struct wined3d_shader_reg_maps *reg_maps, unsigned int max)
@@ -3084,22 +3089,22 @@ static void shader_cleanup(struct wined3d_shader *shader)
 {
     if (shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_HULL)
     {
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.control_point);
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.fork);
-        HeapFree(GetProcessHeap(), 0, shader->u.hs.phases.join);
+        heap_free(shader->u.hs.phases.control_point);
+        heap_free(shader->u.hs.phases.fork);
+        heap_free(shader->u.hs.phases.join);
     }
     else if (shader->reg_maps.shader_version.type == WINED3D_SHADER_TYPE_GEOMETRY)
     {
-        HeapFree(GetProcessHeap(), 0, shader->u.gs.so_desc.elements);
+        heap_free(shader->u.gs.so_desc.elements);
     }
 
-    HeapFree(GetProcessHeap(), 0, shader->patch_constant_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->output_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-    HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+    heap_free(shader->patch_constant_signature.elements);
+    heap_free(shader->output_signature.elements);
+    heap_free(shader->input_signature.elements);
+    heap_free(shader->signature_strings);
     shader->device->shader_backend->shader_destroy(shader);
     shader_cleanup_reg_maps(&shader->reg_maps);
-    HeapFree(GetProcessHeap(), 0, shader->function);
+    heap_free(shader->function);
     shader_delete_constant_list(&shader->constantsF);
     shader_delete_constant_list(&shader->constantsB);
     shader_delete_constant_list(&shader->constantsI);
@@ -3163,13 +3168,13 @@ static HRESULT shader_none_alloc(struct wined3d_device *device, const struct win
     void *vertex_priv, *fragment_priv;
     struct shader_none_priv *priv;
 
-    if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
+    if (!(priv = heap_alloc(sizeof(*priv))))
         return E_OUTOFMEMORY;
 
     if (!(vertex_priv = vertex_pipe->vp_alloc(&none_shader_backend, priv)))
     {
         ERR("Failed to initialize vertex pipe.\n");
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -3177,7 +3182,7 @@ static HRESULT shader_none_alloc(struct wined3d_device *device, const struct win
     {
         ERR("Failed to initialize fragment pipe.\n");
         vertex_pipe->vp_free(device);
-        HeapFree(GetProcessHeap(), 0, priv);
+        heap_free(priv);
         return E_FAIL;
     }
 
@@ -3199,7 +3204,7 @@ static void shader_none_free(struct wined3d_device *device)
 
     priv->fragment_pipe->free_private(device);
     priv->vertex_pipe->vp_free(device);
-    HeapFree(GetProcessHeap(), 0, priv);
+    heap_free(priv);
 }
 
 static BOOL shader_none_allocate_context_data(struct wined3d_context *context)
@@ -3353,7 +3358,7 @@ static void wined3d_shader_init_object(void *object)
 static void wined3d_shader_destroy_object(void *object)
 {
     shader_cleanup(object);
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_shader_decref(struct wined3d_shader *shader)
@@ -3420,9 +3425,10 @@ HRESULT CDECL wined3d_shader_set_local_constants_float(struct wined3d_shader *sh
 
     for (i = start_idx; i < end_idx; ++i)
     {
-        struct wined3d_shader_lconst *lconst = HeapAlloc(GetProcessHeap(), 0, sizeof(*lconst));
+        struct wined3d_shader_lconst *lconst;
         float *value;
-        if (!lconst)
+
+        if (!(lconst = heap_alloc(sizeof(*lconst))))
             return E_OUTOFMEMORY;
 
         lconst->idx = i;
@@ -3554,7 +3560,7 @@ static HRESULT shader_signature_copy(struct wined3d_shader_signature *dst,
     ptr = *signature_strings;
 
     dst->element_count = src->element_count;
-    if (!(dst->elements = wined3d_calloc(dst->element_count, sizeof(*dst->elements))))
+    if (!(dst->elements = heap_calloc(dst->element_count, sizeof(*dst->elements))))
         return E_OUTOFMEMORY;
 
     for (i = 0; i < src->element_count; ++i)
@@ -3606,26 +3612,26 @@ static HRESULT shader_init(struct wined3d_shader *shader, struct wined3d_device
         return hr;
     if (FAILED(hr = shader_signature_calculate_strings_length(&desc->patch_constant_signature, &total)))
         return hr;
-    if (total && !(shader->signature_strings = HeapAlloc(GetProcessHeap(), 0, total)))
+    if (total && !(shader->signature_strings = heap_alloc(total)))
         return E_OUTOFMEMORY;
     ptr = shader->signature_strings;
 
     if (FAILED(hr = shader_signature_copy(&shader->input_signature, &desc->input_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->signature_strings);
         return hr;
     }
     if (FAILED(hr = shader_signature_copy(&shader->output_signature, &desc->output_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->input_signature.elements);
+        heap_free(shader->signature_strings);
         return hr;
     }
     if (FAILED(hr = shader_signature_copy(&shader->patch_constant_signature, &desc->patch_constant_signature, &ptr)))
     {
-        HeapFree(GetProcessHeap(), 0, shader->output_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->input_signature.elements);
-        HeapFree(GetProcessHeap(), 0, shader->signature_strings);
+        heap_free(shader->output_signature.elements);
+        heap_free(shader->input_signature.elements);
+        heap_free(shader->signature_strings);
         return hr;
     }
 
@@ -3662,7 +3668,7 @@ static HRESULT shader_init(struct wined3d_shader *shader, struct wined3d_device
         byte_code_size = (ptr - desc->byte_code) * sizeof(*ptr);
     }
 
-    if (!(shader->function = HeapAlloc(GetProcessHeap(), 0, byte_code_size)))
+    if (!(shader->function = heap_alloc(byte_code_size)))
     {
         shader_cleanup(shader);
         return E_OUTOFMEMORY;
@@ -3720,12 +3726,12 @@ static HRESULT geometry_shader_init(struct wined3d_shader *shader, struct wined3
     struct wined3d_stream_output_element *elements = NULL;
     HRESULT hr;
 
-    if (so_desc && !(elements = wined3d_calloc(so_desc->element_count, sizeof(*elements))))
+    if (so_desc && !(elements = heap_calloc(so_desc->element_count, sizeof(*elements))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(shader, device, desc, 0, WINED3D_SHADER_TYPE_GEOMETRY, parent, parent_ops)))
     {
-        HeapFree(GetProcessHeap(), 0, elements);
+        heap_free(elements);
         return hr;
     }
 
@@ -4102,13 +4108,13 @@ HRESULT CDECL wined3d_shader_create_cs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_COMPUTE, parent, parent_ops)))
     {
         WARN("Failed to initialize compute shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4127,13 +4133,13 @@ HRESULT CDECL wined3d_shader_create_ds(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_DOMAIN, parent, parent_ops)))
     {
         WARN("Failed to initialize domain shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4153,13 +4159,13 @@ HRESULT CDECL wined3d_shader_create_gs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, so_desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, so_desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = geometry_shader_init(object, device, desc, so_desc, parent, parent_ops)))
     {
         WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4178,13 +4184,13 @@ HRESULT CDECL wined3d_shader_create_hs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = shader_init(object, device, desc, 0, WINED3D_SHADER_TYPE_HULL, parent, parent_ops)))
     {
         WARN("Failed to initialize hull shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4203,14 +4209,13 @@ HRESULT CDECL wined3d_shader_create_ps(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = pixel_shader_init(object, device, desc, parent, parent_ops)))
     {
         WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -4229,14 +4234,13 @@ HRESULT CDECL wined3d_shader_create_vs(struct wined3d_device *device, const stru
     TRACE("device %p, desc %p, parent %p, parent_ops %p, shader %p.\n",
             device, desc, parent, parent_ops, shader);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = vertex_shader_init(object, device, desc, parent, parent_ops)))
     {
         WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
diff --git a/dlls/wined3d/shader_sm1.c b/dlls/wined3d/shader_sm1.c
index 40c9e79..0c6bb93 100644
--- a/dlls/wined3d/shader_sm1.c
+++ b/dlls/wined3d/shader_sm1.c
@@ -549,7 +549,7 @@ static void *shader_sm1_init(const DWORD *byte_code, size_t byte_code_size,
         return NULL;
     }
 
-    if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
+    if (!(priv = heap_alloc(sizeof(*priv))))
         return NULL;
 
     if (output_signature->element_count)
@@ -569,7 +569,7 @@ static void *shader_sm1_init(const DWORD *byte_code, size_t byte_code_size,
 
         default:
             FIXME("Unrecognized shader type %#x.\n", *byte_code >> 16);
-            HeapFree(GetProcessHeap(), 0, priv);
+            heap_free(priv);
             return NULL;
     }
     priv->shader_version.major = WINED3D_SM1_VERSION_MAJOR(*byte_code);
@@ -582,7 +582,7 @@ static void *shader_sm1_init(const DWORD *byte_code, size_t byte_code_size,
 
 static void shader_sm1_free(void *data)
 {
-    HeapFree(GetProcessHeap(), 0, data);
+    heap_free(data);
 }
 
 static void shader_sm1_read_header(void *data, const DWORD **ptr, struct wined3d_shader_version *shader_version)
diff --git a/dlls/wined3d/shader_sm4.c b/dlls/wined3d/shader_sm4.c
index 3963cbc..8eac746 100644
--- a/dlls/wined3d/shader_sm4.c
+++ b/dlls/wined3d/shader_sm4.c
@@ -1242,7 +1242,7 @@ static void *shader_sm4_init(const DWORD *byte_code, size_t byte_code_size,
         return NULL;
     }
 
-    if (!(priv = HeapAlloc(GetProcessHeap(), 0, sizeof(*priv))))
+    if (!(priv = heap_alloc(sizeof(*priv))))
     {
         ERR("Failed to allocate private data\n");
         return NULL;
@@ -1311,9 +1311,9 @@ static void shader_sm4_free(void *data)
     list_move_head(&priv->src_free, &priv->src);
     LIST_FOR_EACH_ENTRY_SAFE(e1, e2, &priv->src_free, struct wined3d_shader_src_param_entry, entry)
     {
-        HeapFree(GetProcessHeap(), 0, e1);
+        heap_free(e1);
     }
-    HeapFree(GetProcessHeap(), 0, priv);
+    heap_free(priv);
 }
 
 static struct wined3d_shader_src_param *get_src_param(struct wined3d_sm4_data *priv)
@@ -1328,7 +1328,7 @@ static struct wined3d_shader_src_param *get_src_param(struct wined3d_sm4_data *p
     }
     else
     {
-        if (!(e = HeapAlloc(GetProcessHeap(), 0, sizeof(*e))))
+        if (!(e = heap_alloc(sizeof(*e))))
             return NULL;
         elem = &e->entry;
     }
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index aa1a2ae..407ad62 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -49,7 +49,7 @@ ULONG CDECL wined3d_blend_state_incref(struct wined3d_blend_state *state)
 
 static void wined3d_blend_state_destroy_object(void *object)
 {
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_blend_state_decref(struct wined3d_blend_state *state)
@@ -84,7 +84,7 @@ HRESULT CDECL wined3d_blend_state_create(struct wined3d_device *device,
     TRACE("device %p, desc %p, parent %p, parent_ops %p, state %p.\n",
             device, desc, parent, parent_ops, state);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->refcount = 1;
@@ -110,7 +110,7 @@ ULONG CDECL wined3d_rasterizer_state_incref(struct wined3d_rasterizer_state *sta
 
 static void wined3d_rasterizer_state_destroy_object(void *object)
 {
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_rasterizer_state_decref(struct wined3d_rasterizer_state *state)
@@ -145,7 +145,7 @@ HRESULT CDECL wined3d_rasterizer_state_create(struct wined3d_device *device,
     TRACE("device %p, desc %p, parent %p, parent_ops %p, state %p.\n",
             device, desc, parent, parent_ops, state);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     object->refcount = 1;
@@ -6170,7 +6170,7 @@ HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_
                     break;
                 case 1:
                     StateTable[cur[i].state].apply = multistate_apply_2;
-                    if (!(dev_multistate_funcs[cur[i].state] = wined3d_calloc(2, sizeof(**dev_multistate_funcs))))
+                    if (!(dev_multistate_funcs[cur[i].state] = heap_calloc(2, sizeof(**dev_multistate_funcs))))
                         goto out_of_mem;
 
                     dev_multistate_funcs[cur[i].state][0] = multistate_funcs[cur[i].state][0];
@@ -6178,13 +6178,9 @@ HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_
                     break;
                 case 2:
                     StateTable[cur[i].state].apply = multistate_apply_3;
-                    funcs_array = HeapReAlloc(GetProcessHeap(),
-                                              0,
-                                              dev_multistate_funcs[cur[i].state],
-                                              sizeof(**dev_multistate_funcs) * 3);
-                    if (!funcs_array) {
+                    if (!(funcs_array = heap_realloc(dev_multistate_funcs[cur[i].state],
+                            sizeof(**dev_multistate_funcs) * 3)))
                         goto out_of_mem;
-                    }
 
                     dev_multistate_funcs[cur[i].state] = funcs_array;
                     dev_multistate_funcs[cur[i].state][2] = multistate_funcs[cur[i].state][2];
@@ -6210,8 +6206,9 @@ HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_
     return WINED3D_OK;
 
 out_of_mem:
-    for (i = 0; i <= STATE_HIGHEST; ++i) {
-        HeapFree(GetProcessHeap(), 0, dev_multistate_funcs[i]);
+    for (i = 0; i <= STATE_HIGHEST; ++i)
+    {
+        heap_free(dev_multistate_funcs[i]);
     }
 
     memset(dev_multistate_funcs, 0, (STATE_HIGHEST + 1)*sizeof(*dev_multistate_funcs));
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 9d61360..4c28eb5 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -404,7 +404,7 @@ static void stateblock_init_lights(struct wined3d_stateblock *stateblock, struct
 
         LIST_FOR_EACH_ENTRY(src_light, &light_map[i], struct wined3d_light_info, entry)
         {
-            struct wined3d_light_info *dst_light = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_light));
+            struct wined3d_light_info *dst_light = heap_alloc(sizeof(*dst_light));
 
             *dst_light = *src_light;
             list_add_tail(&stateblock->state.light_map[i], &dst_light->entry);
@@ -539,7 +539,7 @@ void state_cleanup(struct wined3d_state *state)
         {
             struct wined3d_light_info *light = LIST_ENTRY(e1, struct wined3d_light_info, entry);
             list_remove(&light->entry);
-            HeapFree(GetProcessHeap(), 0, light);
+            heap_free(light);
         }
     }
 }
@@ -553,7 +553,7 @@ ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
     if (!refcount)
     {
         state_cleanup(&stateblock->state);
-        HeapFree(GetProcessHeap(), 0, stateblock);
+        heap_free(stateblock);
     }
 
     return refcount;
@@ -1372,15 +1372,14 @@ HRESULT CDECL wined3d_stateblock_create(struct wined3d_device *device,
     TRACE("device %p, type %#x, stateblock %p.\n",
             device, type, stateblock);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = stateblock_init(object, device, type);
     if (FAILED(hr))
     {
         WARN("Failed to initialize stateblock, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 00bc4e4..1f5a98a 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -571,7 +571,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
 
         WARN_(d3d_perf)("Downloading all miplevel layers to get the surface data for a single sub-resource.\n");
 
-        if (!(temporary_mem = wined3d_calloc(texture->layer_count, sub_resource->size)))
+        if (!(temporary_mem = heap_calloc(texture->layer_count, sub_resource->size)))
         {
             ERR("Out of memory.\n");
             return;
@@ -593,7 +593,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
                 wined3d_texture_get_level_pow2_width(texture, surface->texture_level),
                 wined3d_texture_get_level_pow2_height(texture, surface->texture_level),
                 &src_row_pitch, &src_slice_pitch);
-        if (!(temporary_mem = HeapAlloc(GetProcessHeap(), 0, src_slice_pitch)))
+        if (!(temporary_mem = heap_alloc(src_slice_pitch)))
         {
             ERR("Out of memory.\n");
             return;
@@ -622,7 +622,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
                 wined3d_texture_get_level_height(texture, surface->texture_level),
                 &src_row_pitch, &src_slice_pitch);
 
-        if (!(temporary_mem = HeapAlloc(GetProcessHeap(), 0, src_slice_pitch)))
+        if (!(temporary_mem = heap_alloc(src_slice_pitch)))
         {
             ERR("Failed to allocate memory.\n");
             return;
@@ -751,7 +751,7 @@ static void surface_download_data(struct wined3d_surface *surface, const struct
         checkGLcall("glBindBuffer");
     }
 
-    HeapFree(GetProcessHeap(), 0, temporary_mem);
+    heap_free(temporary_mem);
 }
 
 /* This call just uploads data, the caller is responsible for binding the
@@ -1016,7 +1016,7 @@ void surface_set_compatible_renderbuffer(struct wined3d_surface *surface, const
         gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER,
                 surface->container->resource.format->glInternal, width, height);
 
-        entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
+        entry = heap_alloc(sizeof(*entry));
         entry->width = width;
         entry->height = height;
         entry->id = renderbuffer;
@@ -1470,7 +1470,7 @@ static void read_from_framebuffer(struct wined3d_surface *surface,
         /* glReadPixels returns the image upside down, and there is no way to
          * prevent this. Flip the lines in software. */
 
-        if (!(row = HeapAlloc(GetProcessHeap(), 0, row_pitch)))
+        if (!(row = heap_alloc(row_pitch)))
             goto error;
 
         if (data.buffer_object)
@@ -1491,7 +1491,7 @@ static void read_from_framebuffer(struct wined3d_surface *surface,
             top += row_pitch;
             bottom -= row_pitch;
         }
-        HeapFree(GetProcessHeap(), 0, row);
+        heap_free(row);
 
         if (data.buffer_object)
             GL_EXTCALL(glUnmapBuffer(GL_PIXEL_PACK_BUFFER));
@@ -2317,7 +2317,7 @@ static BOOL surface_load_texture(struct wined3d_surface *surface,
 
         src_mem = context_map_bo_address(context, &data, src_slice_pitch,
                 GL_PIXEL_UNPACK_BUFFER, WINED3D_MAP_READONLY);
-        if (!(dst_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
+        if (!(dst_mem = heap_alloc(dst_slice_pitch)))
         {
             ERR("Out of memory (%u).\n", dst_slice_pitch);
             context_release(context);
@@ -2341,7 +2341,7 @@ static BOOL surface_load_texture(struct wined3d_surface *surface,
 
         src_mem = context_map_bo_address(context, &data, src_slice_pitch,
                 GL_PIXEL_UNPACK_BUFFER, WINED3D_MAP_READONLY);
-        if (!(dst_mem = HeapAlloc(GetProcessHeap(), 0, dst_slice_pitch)))
+        if (!(dst_mem = heap_alloc(dst_slice_pitch)))
         {
             ERR("Out of memory (%u).\n", dst_slice_pitch);
             context_release(context);
@@ -2361,7 +2361,7 @@ static BOOL surface_load_texture(struct wined3d_surface *surface,
     wined3d_surface_upload_data(surface, gl_info, &format, &src_rect,
             src_row_pitch, &dst_point, srgb, wined3d_const_bo_address(&data));
 
-    HeapFree(GetProcessHeap(), 0, dst_mem);
+    heap_free(dst_mem);
 
     return TRUE;
 }
@@ -2437,7 +2437,7 @@ static void fbo_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_
     if ((next = blitter->next))
         next->ops->blitter_destroy(next, context);
 
-    HeapFree(GetProcessHeap(), 0, blitter);
+    heap_free(blitter);
 }
 
 static void fbo_blitter_clear(struct wined3d_blitter *blitter, struct wined3d_device *device,
@@ -2511,7 +2511,7 @@ void wined3d_fbo_blitter_create(struct wined3d_blitter **next, const struct wine
     if ((wined3d_settings.offscreen_rendering_mode != ORM_FBO) || !gl_info->fbo_ops.glBlitFramebuffer)
         return;
 
-    if (!(blitter = HeapAlloc(GetProcessHeap(), 0, sizeof(*blitter))))
+    if (!(blitter = heap_alloc(sizeof(*blitter))))
         return;
 
     TRACE("Created blitter %p.\n", blitter);
@@ -2529,7 +2529,7 @@ static void raw_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_
     if ((next = blitter->next))
         next->ops->blitter_destroy(next, context);
 
-    HeapFree(GetProcessHeap(), 0, blitter);
+    heap_free(blitter);
 }
 
 /* Context activation is done by the caller. */
@@ -2643,7 +2643,7 @@ void wined3d_raw_blitter_create(struct wined3d_blitter **next, const struct wine
     if (!gl_info->supported[ARB_COPY_IMAGE])
         return;
 
-    if (!(blitter = HeapAlloc(GetProcessHeap(), 0, sizeof(*blitter))))
+    if (!(blitter = heap_alloc(sizeof(*blitter))))
         return;
 
     TRACE("Created blitter %p.\n", blitter);
@@ -2661,7 +2661,7 @@ static void ffp_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_
     if ((next = blitter->next))
         next->ops->blitter_destroy(next, context);
 
-    HeapFree(GetProcessHeap(), 0, blitter);
+    heap_free(blitter);
 }
 
 static BOOL ffp_blit_supported(enum wined3d_blit_op blit_op, const struct wined3d_context *context,
@@ -2938,7 +2938,7 @@ void wined3d_ffp_blitter_create(struct wined3d_blitter **next, const struct wine
 {
     struct wined3d_blitter *blitter;
 
-    if (!(blitter = HeapAlloc(GetProcessHeap(), 0, sizeof(*blitter))))
+    if (!(blitter = heap_alloc(sizeof(*blitter))))
         return;
 
     TRACE("Created blitter %p.\n", blitter);
@@ -2956,7 +2956,7 @@ static void cpu_blitter_destroy(struct wined3d_blitter *blitter, struct wined3d_
     if ((next = blitter->next))
         next->ops->blitter_destroy(next, context);
 
-    HeapFree(GetProcessHeap(), 0, blitter);
+    heap_free(blitter);
 }
 
 static HRESULT surface_cpu_blt_compressed(const BYTE *src_data, BYTE *dst_data,
@@ -3749,7 +3749,7 @@ struct wined3d_blitter *wined3d_cpu_blitter_create(void)
 {
     struct wined3d_blitter *blitter;
 
-    if (!(blitter = HeapAlloc(GetProcessHeap(), 0, sizeof(*blitter))))
+    if (!(blitter = heap_alloc(sizeof(*blitter))))
         return NULL;
 
     TRACE("Created blitter %p.\n", blitter);
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index fb89099..c20a692 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -61,7 +61,7 @@ static void swapchain_cleanup(struct wined3d_swapchain *swapchain)
             if (wined3d_texture_decref(swapchain->back_buffers[i]))
                 WARN("Something's still holding back buffer %u (%p).\n", i, swapchain->back_buffers[i]);
         }
-        HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
+        heap_free(swapchain->back_buffers);
         swapchain->back_buffers = NULL;
     }
 
@@ -120,7 +120,7 @@ ULONG CDECL wined3d_swapchain_decref(struct wined3d_swapchain *swapchain)
 
         swapchain_cleanup(swapchain);
         swapchain->parent_ops->wined3d_object_destroyed(swapchain->parent);
-        HeapFree(GetProcessHeap(), 0, swapchain);
+        heap_free(swapchain);
     }
 
     return refcount;
@@ -885,8 +885,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
 
     if (!(device->wined3d->flags & WINED3D_NO3D))
     {
-        swapchain->context = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain->context));
-        if (!swapchain->context)
+        if (!(swapchain->context = heap_alloc(sizeof(*swapchain->context))))
         {
             ERR("Failed to create the context array.\n");
             hr = E_OUTOFMEMORY;
@@ -905,7 +904,7 @@ static HRESULT swapchain_init(struct wined3d_swapchain *swapchain, struct wined3
 
     if (swapchain->desc.backbuffer_count > 0)
     {
-        if (!(swapchain->back_buffers = wined3d_calloc(swapchain->desc.backbuffer_count,
+        if (!(swapchain->back_buffers = heap_calloc(swapchain->desc.backbuffer_count,
                 sizeof(*swapchain->back_buffers))))
         {
             ERR("Failed to allocate backbuffer array memory.\n");
@@ -987,7 +986,7 @@ err:
                 wined3d_texture_decref(swapchain->back_buffers[i]);
             }
         }
-        HeapFree(GetProcessHeap(), 0, swapchain->back_buffers);
+        heap_free(swapchain->back_buffers);
     }
 
     wined3d_cs_destroy_object(swapchain->device->cs, wined3d_swapchain_destroy_object, swapchain);
@@ -1011,15 +1010,14 @@ HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, struct win
     TRACE("device %p, desc %p, parent %p, parent_ops %p, swapchain %p.\n",
             device, desc, parent, parent_ops, swapchain);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = swapchain_init(object, device, desc, parent, parent_ops);
     if (FAILED(hr))
     {
         WARN("Failed to initialize swapchain, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -1043,14 +1041,14 @@ static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain
     }
     context_release(ctx);
 
-    if (!(ctx_array = wined3d_calloc(swapchain->num_contexts + 1, sizeof(*ctx_array))))
+    if (!(ctx_array = heap_calloc(swapchain->num_contexts + 1, sizeof(*ctx_array))))
     {
         ERR("Out of memory when trying to allocate a new context array\n");
         context_destroy(swapchain->device, ctx);
         return NULL;
     }
     memcpy(ctx_array, swapchain->context, sizeof(*ctx_array) * swapchain->num_contexts);
-    HeapFree(GetProcessHeap(), 0, swapchain->context);
+    heap_free(swapchain->context);
     ctx_array[swapchain->num_contexts] = ctx;
     swapchain->context = ctx_array;
     swapchain->num_contexts++;
@@ -1067,7 +1065,7 @@ void swapchain_destroy_contexts(struct wined3d_swapchain *swapchain)
     {
         context_destroy(swapchain->device, swapchain->context[i]);
     }
-    HeapFree(GetProcessHeap(), 0, swapchain->context);
+    heap_free(swapchain->context);
     swapchain->num_contexts = 0;
     swapchain->context = NULL;
 }
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index dd6a2dd..029b042 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -962,7 +962,7 @@ static void wined3d_texture_cleanup_sync(struct wined3d_texture *texture)
 static void wined3d_texture_destroy_object(void *object)
 {
     wined3d_texture_cleanup(object);
-    HeapFree(GetProcessHeap(), 0, object);
+    heap_free(object);
 }
 
 ULONG CDECL wined3d_texture_decref(struct wined3d_texture *texture)
@@ -1752,7 +1752,7 @@ static void texture2d_cleanup_sub_resources(struct wined3d_texture *texture)
             TRACE("Deleting renderbuffer %u.\n", entry->id);
             context_gl_resource_released(device, entry->id, TRUE);
             gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
-            HeapFree(GetProcessHeap(), 0, entry);
+            heap_free(entry);
         }
 
         if (surface->dc)
@@ -1769,7 +1769,7 @@ static void texture2d_cleanup_sub_resources(struct wined3d_texture *texture)
     }
     if (context)
         context_release(context);
-    HeapFree(GetProcessHeap(), 0, texture->sub_resources[0].u.surface);
+    heap_free(texture->sub_resources[0].u.surface);
 }
 
 static const struct wined3d_texture_ops texture2d_ops =
@@ -1854,7 +1854,7 @@ static void wined3d_texture_unload(struct wined3d_resource *resource)
                 context_gl_resource_released(device, entry->id, TRUE);
                 gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
                 list_remove(&entry->entry);
-                HeapFree(GetProcessHeap(), 0, entry);
+                heap_free(entry);
             }
             list_init(&surface->renderbuffers);
             surface->current_renderbuffer = NULL;
@@ -2223,7 +2223,7 @@ static HRESULT texture_init(struct wined3d_texture *texture, const struct wined3
         texture->resource.map_binding = WINED3D_LOCATION_BUFFER;
 
     if (level_count > ~(SIZE_T)0 / layer_count
-            || !(surfaces = wined3d_calloc(level_count * layer_count, sizeof(*surfaces))))
+            || !(surfaces = heap_calloc(level_count * layer_count, sizeof(*surfaces))))
     {
         wined3d_texture_cleanup_sync(texture);
         return E_OUTOFMEMORY;
@@ -2344,7 +2344,7 @@ static void texture3d_upload_data(struct wined3d_texture *texture, unsigned int
         dst_row_pitch = update_w * format->conv_byte_count;
         dst_slice_pitch = dst_row_pitch * update_h;
 
-        converted_mem = wined3d_calloc(update_d, dst_slice_pitch);
+        converted_mem = heap_calloc(update_d, dst_slice_pitch);
         format->upload(data->addr, converted_mem, row_pitch, slice_pitch,
                 dst_row_pitch, dst_slice_pitch, update_w, update_h, update_d);
         mem = converted_mem;
@@ -2372,7 +2372,7 @@ static void texture3d_upload_data(struct wined3d_texture *texture, unsigned int
         checkGLcall("glBindBuffer");
     }
 
-    HeapFree(GetProcessHeap(), 0, converted_mem);
+    heap_free(converted_mem);
 }
 
 /* Context activation is done by the caller. */
@@ -2423,7 +2423,7 @@ static void texture3d_srgb_transfer(struct wined3d_texture *texture, unsigned in
      * for DEFAULT pool surfaces. */
     WARN_(d3d_perf)("Performing slow rgb/srgb volume transfer.\n");
     data.buffer_object = 0;
-    if (!(data.addr = HeapAlloc(GetProcessHeap(), 0, sub_resource->size)))
+    if (!(data.addr = heap_alloc(sub_resource->size)))
         return;
 
     wined3d_texture_get_pitch(texture, sub_resource_idx, &row_pitch, &slice_pitch);
@@ -2433,7 +2433,7 @@ static void texture3d_srgb_transfer(struct wined3d_texture *texture, unsigned in
     texture3d_upload_data(texture, sub_resource_idx, context,
             NULL, wined3d_const_bo_address(&data), row_pitch, slice_pitch);
 
-    HeapFree(GetProcessHeap(), 0, data.addr);
+    heap_free(data.addr);
 }
 
 /* Context activation is done by the caller. */
@@ -2988,8 +2988,8 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
         }
     }
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
-            FIELD_OFFSET(struct wined3d_texture, sub_resources[level_count * layer_count]))))
+    if (!(object = heap_alloc_zero(FIELD_OFFSET(struct wined3d_texture,
+            sub_resources[level_count * layer_count]))))
         return E_OUTOFMEMORY;
 
     switch (desc->resource_type)
@@ -3011,7 +3011,7 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
     if (FAILED(hr))
     {
         WARN("Failed to initialize texture, returning %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -3028,7 +3028,7 @@ HRESULT CDECL wined3d_texture_create(struct wined3d_device *device, const struct
             {
                 WARN("Invalid sub-resource data specified for sub-resource %u.\n", i);
                 wined3d_texture_cleanup_sync(object);
-                HeapFree(GetProcessHeap(), 0, object);
+                heap_free(object);
                 return E_INVALIDARG;
             }
         }
diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c
index 960909f..5d97bc8 100644
--- a/dlls/wined3d/utils.c
+++ b/dlls/wined3d/utils.c
@@ -1828,7 +1828,7 @@ static BOOL init_format_base_info(struct wined3d_gl_info *gl_info)
     unsigned int i, j;
 
     gl_info->format_count = WINED3D_FORMAT_COUNT;
-    if (!(gl_info->formats = wined3d_calloc(gl_info->format_count
+    if (!(gl_info->formats = heap_calloc(gl_info->format_count
             + ARRAY_SIZE(typeless_depth_stencil_formats), sizeof(*gl_info->formats))))
     {
         ERR("Failed to allocate memory.\n");
@@ -1922,7 +1922,7 @@ static BOOL init_format_base_info(struct wined3d_gl_info *gl_info)
     return TRUE;
 
 fail:
-    HeapFree(GetProcessHeap(), 0, gl_info->formats);
+    heap_free(gl_info->formats);
     return FALSE;
 }
 
@@ -3806,7 +3806,7 @@ BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wi
     return TRUE;
 
 fail:
-    HeapFree(GetProcessHeap(), 0, gl_info->formats);
+    heap_free(gl_info->formats);
     gl_info->formats = NULL;
     return FALSE;
 }
@@ -6159,7 +6159,7 @@ BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE
         new_capacity = count;
 
     if (!*elements)
-        new_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, new_capacity * size);
+        new_elements = heap_alloc_zero(new_capacity * size);
     else
         new_elements = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *elements, new_capacity * size);
     if (!new_elements)
diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
index 4fa6d54..3d1518d 100644
--- a/dlls/wined3d/vertexdeclaration.c
+++ b/dlls/wined3d/vertexdeclaration.c
@@ -54,8 +54,8 @@ static void wined3d_vertex_declaration_destroy_object(void *object)
 {
     struct wined3d_vertex_declaration *declaration = object;
 
-    HeapFree(GetProcessHeap(), 0, declaration->elements);
-    HeapFree(GetProcessHeap(), 0, declaration);
+    heap_free(declaration->elements);
+    heap_free(declaration);
 }
 
 ULONG CDECL wined3d_vertex_declaration_decref(struct wined3d_vertex_declaration *declaration)
@@ -188,7 +188,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
     declaration->parent = parent;
     declaration->parent_ops = parent_ops;
     declaration->device = device;
-    if (!(declaration->elements = wined3d_calloc(element_count, sizeof(*declaration->elements))))
+    if (!(declaration->elements = heap_calloc(element_count, sizeof(*declaration->elements))))
     {
         ERR("Failed to allocate elements memory.\n");
         return E_OUTOFMEMORY;
@@ -223,7 +223,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
         {
             FIXME("The application tries to use an unsupported format (%s), returning E_FAIL.\n",
                     debug_d3dformat(elements[i].format));
-            HeapFree(GetProcessHeap(), 0, declaration->elements);
+            heap_free(declaration->elements);
             return E_FAIL;
         }
 
@@ -247,7 +247,7 @@ static HRESULT vertexdeclaration_init(struct wined3d_vertex_declaration *declara
         if (e->offset & 0x3)
         {
             WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
-            HeapFree(GetProcessHeap(), 0, declaration->elements);
+            heap_free(declaration->elements);
             return E_FAIL;
         }
 
@@ -270,15 +270,14 @@ HRESULT CDECL wined3d_vertex_declaration_create(struct wined3d_device *device,
     TRACE("device %p, elements %p, element_count %u, parent %p, parent_ops %p, declaration %p.\n",
             device, elements, element_count, parent, parent_ops, declaration);
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if(!object)
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     hr = vertexdeclaration_init(object, device, elements, element_count, parent, parent_ops);
     if (FAILED(hr))
     {
         WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return hr;
     }
 
@@ -346,7 +345,7 @@ static unsigned int convert_fvf_to_declaration(const struct wined3d_gl_info *gl_
            has_psize + has_diffuse + has_specular + num_textures;
 
     state.gl_info = gl_info;
-    if (!(state.elements = wined3d_calloc(size, sizeof(*state.elements))))
+    if (!(state.elements = heap_calloc(size, sizeof(*state.elements))))
         return ~0u;
     state.offset = 0;
     state.idx = 0;
@@ -445,6 +444,6 @@ HRESULT CDECL wined3d_vertex_declaration_create_from_fvf(struct wined3d_device *
     if (size == ~0U) return E_OUTOFMEMORY;
 
     hr = wined3d_vertex_declaration_create(device, elements, size, parent, parent_ops, declaration);
-    HeapFree(GetProcessHeap(), 0, elements);
+    heap_free(elements);
     return hr;
 }
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index b06dacc..05167f4 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -337,7 +337,7 @@ static void wined3d_rendertarget_view_destroy_object(void *object)
         context_release(context);
     }
 
-    HeapFree(GetProcessHeap(), 0, view);
+    heap_free(view);
 }
 
 ULONG CDECL wined3d_rendertarget_view_decref(struct wined3d_rendertarget_view *view)
@@ -600,12 +600,12 @@ HRESULT CDECL wined3d_rendertarget_view_create(const struct wined3d_view_desc *d
     TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
             desc, resource, parent, parent_ops, view);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_rendertarget_view_init(object, desc, resource, parent, parent_ops)))
     {
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         WARN("Failed to initialise view, hr %#x.\n", hr);
         return hr;
     }
@@ -660,7 +660,7 @@ static void wined3d_shader_resource_view_destroy_object(void *object)
         context_release(context);
     }
 
-    HeapFree(GetProcessHeap(), 0, view);
+    heap_free(view);
 }
 
 ULONG CDECL wined3d_shader_resource_view_decref(struct wined3d_shader_resource_view *view)
@@ -776,12 +776,12 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
     TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
             desc, resource, parent, parent_ops, view);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_shader_resource_view_init(object, desc, resource, parent, parent_ops)))
     {
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         WARN("Failed to initialise view, hr %#x.\n", hr);
         return hr;
     }
@@ -952,7 +952,7 @@ static void wined3d_unordered_access_view_destroy_object(void *object)
         context_release(context);
     }
 
-    HeapFree(GetProcessHeap(), 0, view);
+    heap_free(view);
 }
 
 ULONG CDECL wined3d_unordered_access_view_decref(struct wined3d_unordered_access_view *view)
@@ -1144,12 +1144,12 @@ HRESULT CDECL wined3d_unordered_access_view_create(const struct wined3d_view_des
     TRACE("desc %p, resource %p, parent %p, parent_ops %p, view %p.\n",
             desc, resource, parent, parent_ops, view);
 
-    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+    if (!(object = heap_alloc_zero(sizeof(*object))))
         return E_OUTOFMEMORY;
 
     if (FAILED(hr = wined3d_unordered_access_view_init(object, desc, resource, parent, parent_ops)))
     {
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         WARN("Failed to initialise view, hr %#x.\n", hr);
         return hr;
     }
diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c
index d3d3f2d..814a78a 100644
--- a/dlls/wined3d/wined3d_main.c
+++ b/dlls/wined3d/wined3d_main.c
@@ -99,8 +99,7 @@ struct wined3d * CDECL wined3d_create(DWORD flags)
     struct wined3d *object;
     HRESULT hr;
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, FIELD_OFFSET(struct wined3d, adapters[1]));
-    if (!object)
+    if (!(object = heap_alloc_zero(FIELD_OFFSET(struct wined3d, adapters[1]))))
     {
         ERR("Failed to allocate wined3d object memory.\n");
         return NULL;
@@ -113,7 +112,7 @@ struct wined3d * CDECL wined3d_create(DWORD flags)
     if (FAILED(hr))
     {
         WARN("Failed to initialize wined3d object, hr %#x.\n", hr);
-        HeapFree(GetProcessHeap(), 0, object);
+        heap_free(object);
         return NULL;
     }
 
@@ -281,9 +280,10 @@ static BOOL wined3d_dll_init(HINSTANCE hInstDLL)
         {
             size_t len = strlen(buffer) + 1;
 
-            wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, len);
-            if (!wined3d_settings.logo) ERR("Failed to allocate logo path memory.\n");
-            else memcpy(wined3d_settings.logo, buffer, len);
+            if (!(wined3d_settings.logo = heap_alloc(len)))
+                ERR("Failed to allocate logo path memory.\n");
+            else
+                memcpy(wined3d_settings.logo, buffer, len);
         }
         if (!get_config_key_dword(hkey, appkey, "MultisampleTextures", &wined3d_settings.multisample_textures))
             ERR_(winediag)("Setting multisample textures to %#x.\n", wined3d_settings.multisample_textures);
@@ -350,9 +350,9 @@ static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL)
          * these entries. */
         WARN("Leftover wndproc table entry %p.\n", &wndproc_table.entries[i]);
     }
-    HeapFree(GetProcessHeap(), 0, wndproc_table.entries);
+    heap_free(wndproc_table.entries);
 
-    HeapFree(GetProcessHeap(), 0, wined3d_settings.logo);
+    heap_free(wined3d_settings.logo);
     UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL);
 
     DeleteCriticalSection(&wined3d_wndproc_cs);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 8201536..5065731 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -48,6 +48,7 @@
 #include "winternl.h"
 #include "ddk/d3dkmthk.h"
 #include "wine/debug.h"
+#include "wine/heap.h"
 #include "wine/unicode.h"
 
 #include "objbase.h"
@@ -4294,13 +4295,6 @@ static inline BOOL wined3d_format_is_typeless(const struct wined3d_format *forma
     return format->id == format->typeless_id && format->id != WINED3DFMT_UNKNOWN;
 }
 
-static inline void *wined3d_calloc(SIZE_T count, SIZE_T size)
-{
-    if (count > ~(SIZE_T)0 / size)
-        return NULL;
-    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * size);
-}
-
 static inline BOOL use_vs(const struct wined3d_state *state)
 {
     /* Check state->vertex_declaration to allow this to be used before the
-- 
2.1.4




More information about the wine-devel mailing list