diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c index 5146f5b3c4f..2e546713868 100644 --- a/dlls/gdi32/dc.c +++ b/dlls/gdi32/dc.c @@ -52,10 +52,11 @@ static const struct gdi_obj_funcs dc_funcs = static inline DC *get_dc_obj( HDC hdc ) { - DC *dc = GDI_GetObjPtr( hdc, 0 ); + WORD type; + DC *dc = get_any_obj_ptr( hdc, &type ); if (!dc) return NULL; - switch (GetObjectType( hdc )) + switch (type) { case OBJ_DC: case OBJ_MEMDC: diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h index 9c587470ac4..79a7a7435a5 100644 --- a/dlls/gdi32/gdi_private.h +++ b/dlls/gdi32/gdi_private.h @@ -299,6 +299,7 @@ extern HGDIOBJ alloc_gdi_handle( void *obj, WORD type, const struct gdi_obj_func extern void *free_gdi_handle( HGDIOBJ handle ) DECLSPEC_HIDDEN; extern HGDIOBJ get_full_gdi_handle( HGDIOBJ handle ) DECLSPEC_HIDDEN; extern void *GDI_GetObjPtr( HGDIOBJ, WORD ) DECLSPEC_HIDDEN; +extern void *get_any_obj_ptr( HGDIOBJ, WORD * ) DECLSPEC_HIDDEN; extern void GDI_ReleaseObj( HGDIOBJ ) DECLSPEC_HIDDEN; extern void GDI_CheckNotLock(void) DECLSPEC_HIDDEN; extern UINT GDI_get_ref_count( HGDIOBJ handle ) DECLSPEC_HIDDEN; diff --git a/dlls/gdi32/gdiobj.c b/dlls/gdi32/gdiobj.c index 237544dd8ab..46b22419450 100644 --- a/dlls/gdi32/gdiobj.c +++ b/dlls/gdi32/gdiobj.c @@ -829,13 +829,13 @@ HGDIOBJ get_full_gdi_handle( HGDIOBJ handle ) } /*********************************************************************** - * GDI_GetObjPtr + * get_any_obj_ptr * - * Return a pointer to the GDI object associated to the handle. - * Return NULL if the object has the wrong magic number. + * Return a pointer to, and the type of, the GDI object + * associated with the handle. * The object must be released with GDI_ReleaseObj. */ -void *GDI_GetObjPtr( HGDIOBJ handle, WORD type ) +void *get_any_obj_ptr( HGDIOBJ handle, WORD *type ) { void *ptr = NULL; struct gdi_handle_entry *entry; @@ -844,13 +844,32 @@ void *GDI_GetObjPtr( HGDIOBJ handle, WORD type ) if ((entry = handle_entry( handle ))) { - if (!type || entry->type == type) ptr = entry->obj; + ptr = entry->obj; + *type = entry->type; } if (!ptr) LeaveCriticalSection( &gdi_section ); return ptr; } +/*********************************************************************** + * GDI_GetObjPtr + * + * Return a pointer to the GDI object associated with the handle. + * Return NULL if the object has the wrong type. + * The object must be released with GDI_ReleaseObj. + */ +void *GDI_GetObjPtr( HGDIOBJ handle, WORD type ) +{ + WORD ret_type; + void *ptr = get_any_obj_ptr( handle, &ret_type ); + if (ptr && ret_type != type) + { + GDI_ReleaseObj( handle ); + ptr = NULL; + } + return ptr; +} /*********************************************************************** * GDI_ReleaseObj diff --git a/dlls/gdi32/pen.c b/dlls/gdi32/pen.c index cf4b080e1af..d6c1dc45762 100644 --- a/dlls/gdi32/pen.c +++ b/dlls/gdi32/pen.c @@ -223,6 +223,7 @@ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc ) PENOBJ *pen; HGDIOBJ ret = 0; DC *dc = get_dc_ptr( hdc ); + WORD type; if (!dc) { @@ -230,12 +231,12 @@ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc ) return 0; } - if ((pen = GDI_GetObjPtr( handle, 0 ))) + if ((pen = get_any_obj_ptr( handle, &type ))) { struct brush_pattern *pattern; PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectPen ); - switch (GetObjectType( handle )) + switch (type) { case OBJ_PEN: pattern = NULL; @@ -287,12 +288,13 @@ static BOOL PEN_DeleteObject( HGDIOBJ handle ) */ static INT PEN_GetObject( HGDIOBJ handle, INT count, LPVOID buffer ) { - PENOBJ *pen = GDI_GetObjPtr( handle, 0 ); + WORD type; + PENOBJ *pen = get_any_obj_ptr( handle, &type ); INT ret = 0; if (!pen) return 0; - switch (GetObjectType( handle )) + switch (type) { case OBJ_PEN: {