wininet: Fixed grouping security error flags.
[wine] / dlls / gdi32 / enhmfdrv / init.c
1 /*
2  * Enhanced MetaFile driver initialisation functions
3  *
4  * Copyright 1999 Huw D M Davies
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winnls.h"
29 #include "gdi_private.h"
30 #include "enhmfdrv/enhmetafiledrv.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
34
35 static BOOL EMFDRV_DeleteDC( PHYSDEV dev );
36
37 static const struct gdi_dc_funcs EMFDRV_Funcs =
38 {
39     NULL,                            /* pAbortDoc */
40     EMFDRV_AbortPath,                /* pAbortPath */
41     NULL,                            /* pAlphaBlend */
42     NULL,                            /* pAngleArc */
43     EMFDRV_Arc,                      /* pArc */
44     NULL,                            /* pArcTo */
45     EMFDRV_BeginPath,                /* pBeginPath */
46     NULL,                            /* pBlendImage */
47     NULL,                            /* pChoosePixelFormat */
48     EMFDRV_Chord,                    /* pChord */
49     EMFDRV_CloseFigure,              /* pCloseFigure */
50     NULL,                            /* pCreateBitmap */
51     NULL,                            /* pCreateCompatibleDC */
52     NULL,                            /* pCreateDC */
53     NULL,                            /* pDeleteBitmap */
54     EMFDRV_DeleteDC,                 /* pDeleteDC */
55     EMFDRV_DeleteObject,             /* pDeleteObject */
56     NULL,                            /* pDescribePixelFormat */
57     NULL,                            /* pDeviceCapabilities */
58     EMFDRV_Ellipse,                  /* pEllipse */
59     NULL,                            /* pEndDoc */
60     NULL,                            /* pEndPage */
61     EMFDRV_EndPath,                  /* pEndPath */
62     NULL,                            /* pEnumFonts */
63     NULL,                            /* pEnumICMProfiles */
64     EMFDRV_ExcludeClipRect,          /* pExcludeClipRect */
65     NULL,                            /* pExtDeviceMode */
66     NULL,                            /* pExtEscape */
67     EMFDRV_ExtFloodFill,             /* pExtFloodFill */
68     EMFDRV_ExtSelectClipRgn,         /* pExtSelectClipRgn */
69     EMFDRV_ExtTextOut,               /* pExtTextOut */
70     EMFDRV_FillPath,                 /* pFillPath */
71     EMFDRV_FillRgn,                  /* pFillRgn */
72     EMFDRV_FlattenPath,              /* pFlattenPath */
73     NULL,                            /* pFontIsLinked */
74     EMFDRV_FrameRgn,                 /* pFrameRgn */
75     EMFDRV_GdiComment,               /* pGdiComment */
76     NULL,                            /* pGdiRealizationInfo */
77     NULL,                            /* pGetBoundsRect */
78     NULL,                            /* pGetCharABCWidths */
79     NULL,                            /* pGetCharABCWidthsI */
80     NULL,                            /* pGetCharWidth */
81     EMFDRV_GetDeviceCaps,            /* pGetDeviceCaps */
82     NULL,                            /* pGetDeviceGammaRamp */
83     NULL,                            /* pGetFontData */
84     NULL,                            /* pGetFontUnicodeRanges */
85     NULL,                            /* pGetGlyphIndices */
86     NULL,                            /* pGetGlyphOutline */
87     NULL,                            /* pGetICMProfile */
88     NULL,                            /* pGetImage */
89     NULL,                            /* pGetKerningPairs */
90     NULL,                            /* pGetNearestColor */
91     NULL,                            /* pGetOutlineTextMetrics */
92     NULL,                            /* pGetPixel */
93     NULL,                            /* pGetPixelFormat */
94     NULL,                            /* pGetSystemPaletteEntries */
95     NULL,                            /* pGetTextCharsetInfo */
96     NULL,                            /* pGetTextExtentExPoint */
97     NULL,                            /* pGetTextExtentExPointI */
98     NULL,                            /* pGetTextFace */
99     NULL,                            /* pGetTextMetrics */
100     NULL,                            /* pGradientFill */
101     EMFDRV_IntersectClipRect,        /* pIntersectClipRect */
102     EMFDRV_InvertRgn,                /* pInvertRgn */
103     EMFDRV_LineTo,                   /* pLineTo */
104     EMFDRV_ModifyWorldTransform,     /* pModifyWorldTransform */
105     EMFDRV_MoveTo,                   /* pMoveTo */
106     EMFDRV_OffsetClipRgn,            /* pOffsetClipRgn */
107     EMFDRV_OffsetViewportOrgEx,      /* pOffsetViewportOrgEx */
108     EMFDRV_OffsetWindowOrgEx,        /* pOffsetWindowOrgEx */
109     EMFDRV_PaintRgn,                 /* pPaintRgn */
110     EMFDRV_PatBlt,                   /* pPatBlt */
111     EMFDRV_Pie,                      /* pPie */
112     EMFDRV_PolyBezier,               /* pPolyBezier */
113     EMFDRV_PolyBezierTo,             /* pPolyBezierTo */
114     NULL,                            /* pPolyDraw */
115     EMFDRV_PolyPolygon,              /* pPolyPolygon */
116     EMFDRV_PolyPolyline,             /* pPolyPolyline */
117     EMFDRV_Polygon,                  /* pPolygon */
118     EMFDRV_Polyline,                 /* pPolyline */
119     NULL,                            /* pPolylineTo */
120     NULL,                            /* pPutImage */
121     NULL,                            /* pRealizeDefaultPalette */
122     NULL,                            /* pRealizePalette */
123     EMFDRV_Rectangle,                /* pRectangle */
124     NULL,                            /* pResetDC */
125     EMFDRV_RestoreDC,                /* pRestoreDC */
126     EMFDRV_RoundRect,                /* pRoundRect */
127     EMFDRV_SaveDC,                   /* pSaveDC */
128     EMFDRV_ScaleViewportExtEx,       /* pScaleViewportExtEx */
129     EMFDRV_ScaleWindowExtEx,         /* pScaleWindowExtEx */
130     EMFDRV_SelectBitmap,             /* pSelectBitmap */
131     EMFDRV_SelectBrush,              /* pSelectBrush */
132     EMFDRV_SelectClipPath,           /* pSelectClipPath */
133     EMFDRV_SelectFont,               /* pSelectFont */
134     EMFDRV_SelectPalette,            /* pSelectPalette */
135     EMFDRV_SelectPen,                /* pSelectPen */
136     EMFDRV_SetArcDirection,          /* pSetArcDirection */
137     EMFDRV_SetBkColor,               /* pSetBkColor */
138     EMFDRV_SetBkMode,                /* pSetBkMode */
139     NULL,                            /* pSetBoundsRect */
140     EMFDRV_SetDCBrushColor,          /* pSetDCBrushColor*/
141     EMFDRV_SetDCPenColor,            /* pSetDCPenColor*/
142     EMFDRV_SetDIBitsToDevice,        /* pSetDIBitsToDevice */
143     NULL,                            /* pSetDeviceClipping */
144     NULL,                            /* pSetDeviceGammaRamp */
145     EMFDRV_SetLayout,                /* pSetLayout */
146     EMFDRV_SetMapMode,               /* pSetMapMode */
147     EMFDRV_SetMapperFlags,           /* pSetMapperFlags */
148     EMFDRV_SetPixel,                 /* pSetPixel */
149     NULL,                            /* pSetPixelFormat */
150     EMFDRV_SetPolyFillMode,          /* pSetPolyFillMode */
151     EMFDRV_SetROP2,                  /* pSetROP2 */
152     NULL,                            /* pSetRelAbs */
153     EMFDRV_SetStretchBltMode,        /* pSetStretchBltMode */
154     EMFDRV_SetTextAlign,             /* pSetTextAlign */
155     NULL,                            /* pSetTextCharacterExtra */
156     EMFDRV_SetTextColor,             /* pSetTextColor */
157     EMFDRV_SetTextJustification,     /* pSetTextJustification */ 
158     EMFDRV_SetViewportExtEx,         /* pSetViewportExtEx */
159     EMFDRV_SetViewportOrgEx,         /* pSetViewportOrgEx */
160     EMFDRV_SetWindowExtEx,           /* pSetWindowExtEx */
161     EMFDRV_SetWindowOrgEx,           /* pSetWindowOrgEx */
162     EMFDRV_SetWorldTransform,        /* pSetWorldTransform */
163     NULL,                            /* pStartDoc */
164     NULL,                            /* pStartPage */
165     EMFDRV_StretchBlt,               /* pStretchBlt */
166     EMFDRV_StretchDIBits,            /* pStretchDIBits */
167     EMFDRV_StrokeAndFillPath,        /* pStrokeAndFillPath */
168     EMFDRV_StrokePath,               /* pStrokePath */
169     NULL,                            /* pSwapBuffers */
170     NULL,                            /* pUnrealizePalette */
171     EMFDRV_WidenPath,                /* pWidenPath */
172     NULL,                            /* pwglCopyContext */
173     NULL,                            /* pwglCreateContext */
174     NULL,                            /* pwglCreateContextAttribsARB */
175     NULL,                            /* pwglDeleteContext */
176     NULL,                            /* pwglGetProcAddress */
177     NULL,                            /* pwglMakeContextCurrentARB */
178     NULL,                            /* pwglMakeCurrent */
179     NULL,                            /* pwglSetPixelFormatWINE */
180     NULL,                            /* pwglShareLists */
181     NULL,                            /* pwglUseFontBitmapsA */
182     NULL,                            /* pwglUseFontBitmapsW */
183     GDI_PRIORITY_GRAPHICS_DRV        /* priority */
184 };
185
186
187 /**********************************************************************
188  *           EMFDRV_DeleteDC
189  */
190 static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
191 {
192     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
193     UINT index;
194
195     if (physDev->emh) HeapFree( GetProcessHeap(), 0, physDev->emh );
196     for(index = 0; index < physDev->handles_size; index++)
197         if(physDev->handles[index])
198             GDI_hdc_not_using_object(physDev->handles[index], dev->hdc);
199     HeapFree( GetProcessHeap(), 0, physDev->handles );
200     HeapFree( GetProcessHeap(), 0, physDev );
201     return TRUE;
202 }
203
204
205 /******************************************************************
206  *         EMFDRV_WriteRecord
207  *
208  * Warning: this function can change the pointer to the metafile header.
209  */
210 BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
211 {
212     DWORD len;
213     ENHMETAHEADER *emh;
214     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
215
216     TRACE("record %d, size %d %s\n",
217           emr->iType, emr->nSize, physDev->hFile ? "(to disk)" : "");
218
219     assert( !(emr->nSize & 3) );
220
221     physDev->emh->nBytes += emr->nSize;
222     physDev->emh->nRecords++;
223
224     if(physDev->hFile) {
225         if (!WriteFile(physDev->hFile, emr, emr->nSize, NULL, NULL))
226             return FALSE;
227     } else {
228         DWORD nEmfSize = HeapSize(GetProcessHeap(), 0, physDev->emh);
229         len = physDev->emh->nBytes;
230         if (len > nEmfSize) {
231             nEmfSize += (nEmfSize / 2) + emr->nSize;
232             emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, nEmfSize);
233             if (!emh) return FALSE;
234             physDev->emh = emh;
235         }
236         memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
237                emr->nSize);
238     }
239     return TRUE;
240 }
241
242
243 /******************************************************************
244  *         EMFDRV_UpdateBBox
245  */
246 void EMFDRV_UpdateBBox( PHYSDEV dev, RECTL *rect )
247 {
248     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
249     RECTL *bounds = &physDev->emh->rclBounds;
250     RECTL vportRect = *rect;
251
252     LPtoDP( dev->hdc, (LPPOINT)&vportRect, 2 );
253
254     /* The coordinate systems may be mirrored
255        (LPtoDP handles points, not rectangles) */
256     if (vportRect.left > vportRect.right)
257     {
258         LONG temp = vportRect.right;
259         vportRect.right = vportRect.left;
260         vportRect.left = temp;
261     }
262     if (vportRect.top > vportRect.bottom)
263     {
264         LONG temp = vportRect.bottom;
265         vportRect.bottom = vportRect.top;
266         vportRect.top = temp;
267     }
268
269     if (bounds->left > bounds->right)
270     {
271         /* first bounding rectangle */
272         *bounds = vportRect;
273     }
274     else
275     {
276         bounds->left   = min(bounds->left,   vportRect.left);
277         bounds->top    = min(bounds->top,    vportRect.top);
278         bounds->right  = max(bounds->right,  vportRect.right);
279         bounds->bottom = max(bounds->bottom, vportRect.bottom);
280     }
281 }
282
283 /**********************************************************************
284  *          CreateEnhMetaFileA   (GDI32.@)
285  */
286 HDC WINAPI CreateEnhMetaFileA(
287     HDC hdc,           /* [in] optional reference DC */
288     LPCSTR filename,   /* [in] optional filename for disk metafiles */
289     const RECT *rect,  /* [in] optional bounding rectangle */
290     LPCSTR description /* [in] optional description */
291     )
292 {
293     LPWSTR filenameW = NULL;
294     LPWSTR descriptionW = NULL;
295     HDC hReturnDC;
296     DWORD len1, len2, total;
297
298     if(filename)
299     {
300         total = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
301         filenameW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
302         MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, total );
303     }
304     if(description) {
305         len1 = strlen(description);
306         len2 = strlen(description + len1 + 1);
307         total = MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, NULL, 0 );
308         descriptionW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
309         MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, descriptionW, total );
310     }
311
312     hReturnDC = CreateEnhMetaFileW(hdc, filenameW, rect, descriptionW);
313
314     HeapFree( GetProcessHeap(), 0, filenameW );
315     HeapFree( GetProcessHeap(), 0, descriptionW );
316
317     return hReturnDC;
318 }
319
320 /**********************************************************************
321  *          CreateEnhMetaFileW   (GDI32.@)
322  */
323 HDC WINAPI CreateEnhMetaFileW(
324     HDC           hdc,        /* [in] optional reference DC */
325     LPCWSTR       filename,   /* [in] optional filename for disk metafiles */
326     const RECT*   rect,       /* [in] optional bounding rectangle */
327     LPCWSTR       description /* [in] optional description */
328     )
329 {
330     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
331     HDC ret;
332     DC *dc;
333     EMFDRV_PDEVICE *physDev;
334     HANDLE hFile;
335     DWORD size = 0, length = 0;
336
337     TRACE("%s\n", debugstr_w(filename) );
338
339     if (!(dc = alloc_dc_ptr( OBJ_ENHMETADC ))) return 0;
340
341     physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
342     if (!physDev) {
343         free_dc_ptr( dc );
344         return 0;
345     }
346     if(description) { /* App name\0Title\0\0 */
347         length = lstrlenW(description);
348         length += lstrlenW(description + length + 1);
349         length += 3;
350         length *= 2;
351     }
352     size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4;
353
354     if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
355         HeapFree( GetProcessHeap(), 0, physDev );
356         free_dc_ptr( dc );
357         return 0;
358     }
359
360     push_dc_driver( &dc->physDev, &physDev->dev, &EMFDRV_Funcs );
361
362     physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
363     physDev->handles_size = HANDLE_LIST_INC;
364     physDev->cur_handles = 1;
365     physDev->hFile = 0;
366     physDev->dc_brush = 0;
367     physDev->dc_pen = 0;
368     physDev->screen_dc = 0;
369     physDev->restoring = 0;
370     if (hdc)  /* if no ref, use current display */
371         physDev->ref_dc = hdc;
372     else
373         physDev->ref_dc = physDev->screen_dc = CreateDCW( displayW, NULL, NULL, NULL );
374
375     SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0);
376
377     physDev->emh->iType = EMR_HEADER;
378     physDev->emh->nSize = size;
379
380     physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0;
381     physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1;
382
383     if(rect) {
384         physDev->emh->rclFrame.left   = rect->left;
385         physDev->emh->rclFrame.top    = rect->top;
386         physDev->emh->rclFrame.right  = rect->right;
387         physDev->emh->rclFrame.bottom = rect->bottom;
388     } else {  /* Set this to {0,0 - -1,-1} and update it at the end */
389         physDev->emh->rclFrame.left = physDev->emh->rclFrame.top = 0;
390         physDev->emh->rclFrame.right = physDev->emh->rclFrame.bottom = -1;
391     }
392
393     physDev->emh->dSignature = ENHMETA_SIGNATURE;
394     physDev->emh->nVersion = 0x10000;
395     physDev->emh->nBytes = physDev->emh->nSize;
396     physDev->emh->nRecords = 1;
397     physDev->emh->nHandles = 1;
398
399     physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */
400     physDev->emh->nDescription = length / 2;
401
402     physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0;
403
404     physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */
405
406     /* Size in pixels */
407     physDev->emh->szlDevice.cx = GetDeviceCaps( physDev->ref_dc, HORZRES );
408     physDev->emh->szlDevice.cy = GetDeviceCaps( physDev->ref_dc, VERTRES );
409
410     /* Size in millimeters */
411     physDev->emh->szlMillimeters.cx = GetDeviceCaps( physDev->ref_dc, HORZSIZE );
412     physDev->emh->szlMillimeters.cy = GetDeviceCaps( physDev->ref_dc, VERTSIZE );
413
414     /* Size in micrometers */
415     physDev->emh->szlMicrometers.cx = physDev->emh->szlMillimeters.cx * 1000;
416     physDev->emh->szlMicrometers.cy = physDev->emh->szlMillimeters.cy * 1000;
417
418     memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length);
419
420     if (filename)  /* disk based metafile */
421     {
422         if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0,
423                                  NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
424             free_dc_ptr( dc );
425             return 0;
426         }
427         if (!WriteFile( hFile, physDev->emh, size, NULL, NULL )) {
428             free_dc_ptr( dc );
429             return 0;
430         }
431         physDev->hFile = hFile;
432     }
433
434     TRACE("returning %p\n", physDev->dev.hdc);
435     ret = physDev->dev.hdc;
436     release_dc_ptr( dc );
437
438     return ret;
439 }
440
441 /******************************************************************
442  *             CloseEnhMetaFile (GDI32.@)
443  */
444 HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
445 {
446     HENHMETAFILE hmf;
447     EMFDRV_PDEVICE *physDev;
448     DC *dc;
449     EMREOF emr;
450     HANDLE hMapping = 0;
451
452     TRACE("(%p)\n", hdc );
453
454     if (!(dc = get_dc_ptr( hdc ))) return NULL;
455     if (dc->header.type != OBJ_ENHMETADC)
456     {
457         release_dc_ptr( dc );
458         return NULL;
459     }
460     if (dc->refcount != 1)
461     {
462         FIXME( "not deleting busy DC %p refcount %u\n", hdc, dc->refcount );
463         release_dc_ptr( dc );
464         return NULL;
465     }
466     physDev = (EMFDRV_PDEVICE *)dc->physDev;
467
468     if(dc->saveLevel)
469         RestoreDC(hdc, 1);
470
471     if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
472     if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
473     if (physDev->screen_dc) DeleteDC( physDev->screen_dc );
474
475     emr.emr.iType = EMR_EOF;
476     emr.emr.nSize = sizeof(emr);
477     emr.nPalEntries = 0;
478     emr.offPalEntries = FIELD_OFFSET(EMREOF, nSizeLast);
479     emr.nSizeLast = emr.emr.nSize;
480     EMFDRV_WriteRecord( dc->physDev, &emr.emr );
481
482     /* Update rclFrame if not initialized in CreateEnhMetaFile */
483     if(physDev->emh->rclFrame.left > physDev->emh->rclFrame.right) {
484         physDev->emh->rclFrame.left = physDev->emh->rclBounds.left *
485           physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx;
486         physDev->emh->rclFrame.top = physDev->emh->rclBounds.top *
487           physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy;
488         physDev->emh->rclFrame.right = physDev->emh->rclBounds.right *
489           physDev->emh->szlMillimeters.cx * 100 / physDev->emh->szlDevice.cx;
490         physDev->emh->rclFrame.bottom = physDev->emh->rclBounds.bottom *
491           physDev->emh->szlMillimeters.cy * 100 / physDev->emh->szlDevice.cy;
492     }
493
494     if (physDev->hFile)  /* disk based metafile */
495     {
496         if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0)
497         {
498             CloseHandle( physDev->hFile );
499             free_dc_ptr( dc );
500             return 0;
501         }
502
503         if (!WriteFile(physDev->hFile, physDev->emh, sizeof(*physDev->emh),
504                        NULL, NULL))
505         {
506             CloseHandle( physDev->hFile );
507             free_dc_ptr( dc );
508             return 0;
509         }
510         HeapFree( GetProcessHeap(), 0, physDev->emh );
511         hMapping = CreateFileMappingA(physDev->hFile, NULL, PAGE_READONLY, 0,
512                                       0, NULL);
513         TRACE("hMapping = %p\n", hMapping );
514         physDev->emh = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0);
515         TRACE("view = %p\n", physDev->emh );
516         CloseHandle( hMapping );
517         CloseHandle( physDev->hFile );
518     }
519
520     hmf = EMF_Create_HENHMETAFILE( physDev->emh, (physDev->hFile != 0) );
521     physDev->emh = NULL;  /* So it won't be deleted */
522     free_dc_ptr( dc );
523     return hmf;
524 }