dinput: Stub IDirectInputJoyConfig8 interface.
[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,                            /* pCopyBitmap */
51     NULL,                            /* pCreateBitmap */
52     NULL,                            /* pCreateCompatibleDC */
53     NULL,                            /* pCreateDC */
54     NULL,                            /* pCreateDIBSection */
55     NULL,                            /* pDeleteBitmap */
56     EMFDRV_DeleteDC,                 /* pDeleteDC */
57     EMFDRV_DeleteObject,             /* pDeleteObject */
58     NULL,                            /* pDescribePixelFormat */
59     NULL,                            /* pDeviceCapabilities */
60     EMFDRV_Ellipse,                  /* pEllipse */
61     NULL,                            /* pEndDoc */
62     NULL,                            /* pEndPage */
63     EMFDRV_EndPath,                  /* pEndPath */
64     NULL,                            /* pEnumFonts */
65     NULL,                            /* pEnumICMProfiles */
66     EMFDRV_ExcludeClipRect,          /* pExcludeClipRect */
67     NULL,                            /* pExtDeviceMode */
68     NULL,                            /* pExtEscape */
69     EMFDRV_ExtFloodFill,             /* pExtFloodFill */
70     EMFDRV_ExtSelectClipRgn,         /* pExtSelectClipRgn */
71     EMFDRV_ExtTextOut,               /* pExtTextOut */
72     EMFDRV_FillPath,                 /* pFillPath */
73     EMFDRV_FillRgn,                  /* pFillRgn */
74     EMFDRV_FlattenPath,              /* pFlattenPath */
75     NULL,                            /* pFontIsLinked */
76     EMFDRV_FrameRgn,                 /* pFrameRgn */
77     EMFDRV_GdiComment,               /* pGdiComment */
78     NULL,                            /* pGdiRealizationInfo */
79     NULL,                            /* pGetCharABCWidths */
80     NULL,                            /* pGetCharABCWidthsI */
81     NULL,                            /* pGetCharWidth */
82     EMFDRV_GetDeviceCaps,            /* pGetDeviceCaps */
83     NULL,                            /* pGetDeviceGammaRamp */
84     NULL,                            /* pGetFontData */
85     NULL,                            /* pGetFontUnicodeRanges */
86     NULL,                            /* pGetGlyphIndices */
87     NULL,                            /* pGetGlyphOutline */
88     NULL,                            /* pGetICMProfile */
89     NULL,                            /* pGetImage */
90     NULL,                            /* pGetKerningPairs */
91     NULL,                            /* pGetNearestColor */
92     NULL,                            /* pGetOutlineTextMetrics */
93     NULL,                            /* pGetPixel */
94     NULL,                            /* pGetPixelFormat */
95     NULL,                            /* pGetSystemPaletteEntries */
96     NULL,                            /* pGetTextCharsetInfo */
97     NULL,                            /* pGetTextExtentExPoint */
98     NULL,                            /* pGetTextExtentExPointI */
99     NULL,                            /* pGetTextFace */
100     NULL,                            /* pGetTextMetrics */
101     NULL,                            /* pGradientFill */
102     EMFDRV_IntersectClipRect,        /* pIntersectClipRect */
103     EMFDRV_InvertRgn,                /* pInvertRgn */
104     EMFDRV_LineTo,                   /* pLineTo */
105     EMFDRV_ModifyWorldTransform,     /* pModifyWorldTransform */
106     EMFDRV_MoveTo,                   /* pMoveTo */
107     EMFDRV_OffsetClipRgn,            /* pOffsetClipRgn */
108     EMFDRV_OffsetViewportOrgEx,      /* pOffsetViewportOrgEx */
109     EMFDRV_OffsetWindowOrgEx,        /* pOffsetWindowOrgEx */
110     EMFDRV_PaintRgn,                 /* pPaintRgn */
111     EMFDRV_PatBlt,                   /* pPatBlt */
112     EMFDRV_Pie,                      /* pPie */
113     NULL,                            /* pPolyBezier */
114     NULL,                            /* pPolyBezierTo */
115     NULL,                            /* pPolyDraw */
116     EMFDRV_PolyPolygon,              /* pPolyPolygon */
117     EMFDRV_PolyPolyline,             /* pPolyPolyline */
118     EMFDRV_Polygon,                  /* pPolygon */
119     EMFDRV_Polyline,                 /* pPolyline */
120     NULL,                            /* pPolylineTo */
121     NULL,                            /* pPutImage */
122     NULL,                            /* pRealizeDefaultPalette */
123     NULL,                            /* pRealizePalette */
124     EMFDRV_Rectangle,                /* pRectangle */
125     NULL,                            /* pResetDC */
126     EMFDRV_RestoreDC,                /* pRestoreDC */
127     EMFDRV_RoundRect,                /* pRoundRect */
128     EMFDRV_SaveDC,                   /* pSaveDC */
129     EMFDRV_ScaleViewportExtEx,       /* pScaleViewportExtEx */
130     EMFDRV_ScaleWindowExtEx,         /* pScaleWindowExtEx */
131     EMFDRV_SelectBitmap,             /* pSelectBitmap */
132     EMFDRV_SelectBrush,              /* pSelectBrush */
133     EMFDRV_SelectClipPath,           /* pSelectClipPath */
134     EMFDRV_SelectFont,               /* pSelectFont */
135     EMFDRV_SelectPalette,            /* pSelectPalette */
136     EMFDRV_SelectPen,                /* pSelectPen */
137     EMFDRV_SetArcDirection,          /* pSetArcDirection */
138     EMFDRV_SetBkColor,               /* pSetBkColor */
139     EMFDRV_SetBkMode,                /* pSetBkMode */
140     EMFDRV_SetDCBrushColor,          /* pSetDCBrushColor*/
141     EMFDRV_SetDCPenColor,            /* pSetDCPenColor*/
142     NULL,                            /* pSetDIBColorTable */
143     EMFDRV_SetDIBitsToDevice,        /* pSetDIBitsToDevice */
144     NULL,                            /* pSetDeviceClipping */
145     NULL,                            /* pSetDeviceGammaRamp */
146     EMFDRV_SetLayout,                /* pSetLayout */
147     EMFDRV_SetMapMode,               /* pSetMapMode */
148     EMFDRV_SetMapperFlags,           /* pSetMapperFlags */
149     EMFDRV_SetPixel,                 /* pSetPixel */
150     NULL,                            /* pSetPixelFormat */
151     EMFDRV_SetPolyFillMode,          /* pSetPolyFillMode */
152     EMFDRV_SetROP2,                  /* pSetROP2 */
153     NULL,                            /* pSetRelAbs */
154     EMFDRV_SetStretchBltMode,        /* pSetStretchBltMode */
155     EMFDRV_SetTextAlign,             /* pSetTextAlign */
156     NULL,                            /* pSetTextCharacterExtra */
157     EMFDRV_SetTextColor,             /* pSetTextColor */
158     EMFDRV_SetTextJustification,     /* pSetTextJustification */ 
159     EMFDRV_SetViewportExtEx,         /* pSetViewportExtEx */
160     EMFDRV_SetViewportOrgEx,         /* pSetViewportOrgEx */
161     EMFDRV_SetWindowExtEx,           /* pSetWindowExtEx */
162     EMFDRV_SetWindowOrgEx,           /* pSetWindowOrgEx */
163     EMFDRV_SetWorldTransform,        /* pSetWorldTransform */
164     NULL,                            /* pStartDoc */
165     NULL,                            /* pStartPage */
166     EMFDRV_StretchBlt,               /* pStretchBlt */
167     EMFDRV_StretchDIBits,            /* pStretchDIBits */
168     EMFDRV_StrokeAndFillPath,        /* pStrokeAndFillPath */
169     EMFDRV_StrokePath,               /* pStrokePath */
170     NULL,                            /* pSwapBuffers */
171     NULL,                            /* pUnrealizePalette */
172     EMFDRV_WidenPath                 /* pWidenPath */
173 };
174
175
176 /**********************************************************************
177  *           EMFDRV_DeleteDC
178  */
179 static BOOL EMFDRV_DeleteDC( PHYSDEV dev )
180 {
181     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
182     UINT index;
183
184     if (physDev->emh) HeapFree( GetProcessHeap(), 0, physDev->emh );
185     for(index = 0; index < physDev->handles_size; index++)
186         if(physDev->handles[index])
187             GDI_hdc_not_using_object(physDev->handles[index], dev->hdc);
188     HeapFree( GetProcessHeap(), 0, physDev->handles );
189     HeapFree( GetProcessHeap(), 0, physDev );
190     return TRUE;
191 }
192
193
194 /******************************************************************
195  *         EMFDRV_WriteRecord
196  *
197  * Warning: this function can change the pointer to the metafile header.
198  */
199 BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
200 {
201     DWORD len;
202     ENHMETAHEADER *emh;
203     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
204
205     TRACE("record %d, size %d %s\n",
206           emr->iType, emr->nSize, physDev->hFile ? "(to disk)" : "");
207
208     assert( !(emr->nSize & 3) );
209
210     physDev->emh->nBytes += emr->nSize;
211     physDev->emh->nRecords++;
212
213     if(physDev->hFile) {
214         if (!WriteFile(physDev->hFile, emr, emr->nSize, NULL, NULL))
215             return FALSE;
216     } else {
217         DWORD nEmfSize = HeapSize(GetProcessHeap(), 0, physDev->emh);
218         len = physDev->emh->nBytes;
219         if (len > nEmfSize) {
220             nEmfSize += (nEmfSize / 2) + emr->nSize;
221             emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, nEmfSize);
222             if (!emh) return FALSE;
223             physDev->emh = emh;
224         }
225         memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
226                emr->nSize);
227     }
228     return TRUE;
229 }
230
231
232 /******************************************************************
233  *         EMFDRV_UpdateBBox
234  */
235 void EMFDRV_UpdateBBox( PHYSDEV dev, RECTL *rect )
236 {
237     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
238     RECTL *bounds = &physDev->emh->rclBounds;
239     RECTL vportRect = *rect;
240
241     LPtoDP( dev->hdc, (LPPOINT)&vportRect, 2 );
242
243     /* The coordinate systems may be mirrored
244        (LPtoDP handles points, not rectangles) */
245     if (vportRect.left > vportRect.right)
246     {
247         LONG temp = vportRect.right;
248         vportRect.right = vportRect.left;
249         vportRect.left = temp;
250     }
251     if (vportRect.top > vportRect.bottom)
252     {
253         LONG temp = vportRect.bottom;
254         vportRect.bottom = vportRect.top;
255         vportRect.top = temp;
256     }
257
258     if (bounds->left > bounds->right)
259     {
260         /* first bounding rectangle */
261         *bounds = vportRect;
262     }
263     else
264     {
265         bounds->left   = min(bounds->left,   vportRect.left);
266         bounds->top    = min(bounds->top,    vportRect.top);
267         bounds->right  = max(bounds->right,  vportRect.right);
268         bounds->bottom = max(bounds->bottom, vportRect.bottom);
269     }
270 }
271
272 /**********************************************************************
273  *          CreateEnhMetaFileA   (GDI32.@)
274  */
275 HDC WINAPI CreateEnhMetaFileA(
276     HDC hdc,           /* [in] optional reference DC */
277     LPCSTR filename,   /* [in] optional filename for disk metafiles */
278     const RECT *rect,  /* [in] optional bounding rectangle */
279     LPCSTR description /* [in] optional description */
280     )
281 {
282     LPWSTR filenameW = NULL;
283     LPWSTR descriptionW = NULL;
284     HDC hReturnDC;
285     DWORD len1, len2, total;
286
287     if(filename)
288     {
289         total = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
290         filenameW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
291         MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, total );
292     }
293     if(description) {
294         len1 = strlen(description);
295         len2 = strlen(description + len1 + 1);
296         total = MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, NULL, 0 );
297         descriptionW = HeapAlloc( GetProcessHeap(), 0, total * sizeof(WCHAR) );
298         MultiByteToWideChar( CP_ACP, 0, description, len1 + len2 + 3, descriptionW, total );
299     }
300
301     hReturnDC = CreateEnhMetaFileW(hdc, filenameW, rect, descriptionW);
302
303     HeapFree( GetProcessHeap(), 0, filenameW );
304     HeapFree( GetProcessHeap(), 0, descriptionW );
305
306     return hReturnDC;
307 }
308
309 /**********************************************************************
310  *          CreateEnhMetaFileW   (GDI32.@)
311  */
312 HDC WINAPI CreateEnhMetaFileW(
313     HDC           hdc,        /* [in] optional reference DC */
314     LPCWSTR       filename,   /* [in] optional filename for disk metafiles */
315     const RECT*   rect,       /* [in] optional bounding rectangle */
316     LPCWSTR       description /* [in] optional description */
317     )
318 {
319     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
320     HDC ret;
321     DC *dc;
322     HDC hRefDC = hdc ? hdc : CreateDCW(displayW,NULL,NULL,NULL); 
323         /* If no ref, use current display */
324     EMFDRV_PDEVICE *physDev;
325     HANDLE hFile;
326     DWORD size = 0, length = 0;
327
328     TRACE("%s\n", debugstr_w(filename) );
329
330     if (!(dc = alloc_dc_ptr( OBJ_ENHMETADC ))) return 0;
331
332     physDev = HeapAlloc(GetProcessHeap(),0,sizeof(*physDev));
333     if (!physDev) {
334         free_dc_ptr( dc );
335         return 0;
336     }
337     if(description) { /* App name\0Title\0\0 */
338         length = lstrlenW(description);
339         length += lstrlenW(description + length + 1);
340         length += 3;
341         length *= 2;
342     }
343     size = sizeof(ENHMETAHEADER) + (length + 3) / 4 * 4;
344
345     if (!(physDev->emh = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, size))) {
346         HeapFree( GetProcessHeap(), 0, physDev );
347         free_dc_ptr( dc );
348         return 0;
349     }
350
351     push_dc_driver( &dc->physDev, &physDev->dev, &EMFDRV_Funcs );
352
353     physDev->handles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, HANDLE_LIST_INC * sizeof(physDev->handles[0]));
354     physDev->handles_size = HANDLE_LIST_INC;
355     physDev->cur_handles = 1;
356     physDev->hFile = 0;
357     physDev->dc_brush = 0;
358     physDev->dc_pen = 0;
359     physDev->horzres = GetDeviceCaps(hRefDC, HORZRES);
360     physDev->vertres = GetDeviceCaps(hRefDC, VERTRES);
361     physDev->logpixelsx = GetDeviceCaps(hRefDC, LOGPIXELSX);
362     physDev->logpixelsy = GetDeviceCaps(hRefDC, LOGPIXELSY);
363     physDev->horzsize = GetDeviceCaps(hRefDC, HORZSIZE);
364     physDev->vertsize = GetDeviceCaps(hRefDC, VERTSIZE);
365     physDev->bitspixel = GetDeviceCaps(hRefDC, BITSPIXEL);
366     physDev->textcaps = GetDeviceCaps(hRefDC, TEXTCAPS);
367     physDev->rastercaps = GetDeviceCaps(hRefDC, RASTERCAPS);
368     physDev->technology = GetDeviceCaps(hRefDC, TECHNOLOGY);
369     physDev->planes = GetDeviceCaps(hRefDC, PLANES);
370     physDev->numcolors = GetDeviceCaps(hRefDC, NUMCOLORS);
371     physDev->restoring = 0;
372
373     SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0);
374
375     physDev->emh->iType = EMR_HEADER;
376     physDev->emh->nSize = size;
377
378     physDev->emh->rclBounds.left = physDev->emh->rclBounds.top = 0;
379     physDev->emh->rclBounds.right = physDev->emh->rclBounds.bottom = -1;
380
381     if(rect) {
382         physDev->emh->rclFrame.left   = rect->left;
383         physDev->emh->rclFrame.top    = rect->top;
384         physDev->emh->rclFrame.right  = rect->right;
385         physDev->emh->rclFrame.bottom = rect->bottom;
386     } else {  /* Set this to {0,0 - -1,-1} and update it at the end */
387         physDev->emh->rclFrame.left = physDev->emh->rclFrame.top = 0;
388         physDev->emh->rclFrame.right = physDev->emh->rclFrame.bottom = -1;
389     }
390
391     physDev->emh->dSignature = ENHMETA_SIGNATURE;
392     physDev->emh->nVersion = 0x10000;
393     physDev->emh->nBytes = physDev->emh->nSize;
394     physDev->emh->nRecords = 1;
395     physDev->emh->nHandles = 1;
396
397     physDev->emh->sReserved = 0; /* According to docs, this is reserved and must be 0 */
398     physDev->emh->nDescription = length / 2;
399
400     physDev->emh->offDescription = length ? sizeof(ENHMETAHEADER) : 0;
401
402     physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */
403
404     /* Size in pixels */
405     physDev->emh->szlDevice.cx = physDev->horzres;
406     physDev->emh->szlDevice.cy = physDev->vertres;
407
408     /* Size in millimeters */
409     physDev->emh->szlMillimeters.cx = physDev->horzsize;
410     physDev->emh->szlMillimeters.cy = physDev->vertsize;
411
412     /* Size in micrometers */
413     physDev->emh->szlMicrometers.cx = physDev->horzsize * 1000;
414     physDev->emh->szlMicrometers.cy = physDev->vertsize * 1000;
415
416     memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length);
417
418     if (filename)  /* disk based metafile */
419     {
420         if ((hFile = CreateFileW(filename, GENERIC_WRITE | GENERIC_READ, 0,
421                                  NULL, CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
422             free_dc_ptr( dc );
423             return 0;
424         }
425         if (!WriteFile( hFile, physDev->emh, size, NULL, NULL )) {
426             free_dc_ptr( dc );
427             return 0;
428         }
429         physDev->hFile = hFile;
430     }
431
432     TRACE("returning %p\n", physDev->dev.hdc);
433     ret = physDev->dev.hdc;
434     release_dc_ptr( dc );
435
436     if( !hdc )
437       DeleteDC( hRefDC );
438
439     return ret;
440 }
441
442 /******************************************************************
443  *             CloseEnhMetaFile (GDI32.@)
444  */
445 HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
446 {
447     HENHMETAFILE hmf;
448     EMFDRV_PDEVICE *physDev;
449     DC *dc;
450     EMREOF emr;
451     HANDLE hMapping = 0;
452
453     TRACE("(%p)\n", hdc );
454
455     if (!(dc = get_dc_ptr( hdc ))) return NULL;
456     if (dc->header.type != OBJ_ENHMETADC)
457     {
458         release_dc_ptr( dc );
459         return NULL;
460     }
461     if (dc->refcount != 1)
462     {
463         FIXME( "not deleting busy DC %p refcount %u\n", hdc, dc->refcount );
464         release_dc_ptr( dc );
465         return NULL;
466     }
467     physDev = (EMFDRV_PDEVICE *)dc->physDev;
468
469     if(dc->saveLevel)
470         RestoreDC(hdc, 1);
471
472     if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
473     if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
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 }