ID Number: Q80842
3.00
WINDOWS
buglist3.00 fixlist3.10
Summary:
PROBLEM ID: WIN9202001
SYMPTOMS
When an application calls the CopyMetaFile function to read a
metafile from a floppy disk after a call to the GetMetaFile
function, an unrecoverable application error (UAE) occurs. The UAE
occurs only for the first call to CopyMetaFile after a call to
GetMetaFile for each Windows session. The following code fragment
demonstrates this UAE:
hMTF1 = GetMetaFile("a:\\pict.wmf");
if (hMTF1 != NULL) {
hMTF2 = CopyMetaFile(hMTF1 , NULL); // UAE here!
DeleteMetaFile(hMTF1);
}
RESOLUTION
Microsoft has confirmed this to be a problem in Windows version
3.0. To avoid this problem, copy the metafile from the floppy disk-
based file into a memory buffer. Then copy the metafile from the
buffer to the destination. A code fragment demonstrating this
technique appears below.
This problem was corrected in Windows version 3.1.
More Information:
The following code fragment provides a method to work around this
problem. Although error checking has been omitted from this example to
improve readability of the code, the values returned from each
function must be checked in production code.
// ------------- variables --------------
int hDiskMF; // MS-DOS file handle
DWORD lFileLength; // Disk metafile length
HANDLE hMem; // Handle to file buffer
LPSTR lpMem; // Pointer to file buffer
HANDLE hMF; // Handle to memory metafile
// ------------- code fragment --------------
// Get handle to file.
hDiskMF = _lopen("a:\\pict.wmf", OF_READ);
// Get file length.
// NOTE: Must be <= 0x7FFF for this example.
lFileLength = _llseek(hDiskMF, 0, 2);
// Allocate buffer.
hMem = GlobalAlloc(GMEM_MOVEABLE, lFileLength + 1);
// Get pointer to locked buffer.
lpMem = GlobalLock(hMem);
// Reset file pointer and read the file.
_llseek(hDiskMF, 0, 0);
_lread(hDiskMF, lpMem, (WORD) lFileLength);
GlobalUnlock(hMem);
_lclose(hDiskMF);
// Copy disk metafile at hMem to hMF.
hMF = CopyMetaFile(hMem, NULL);
GlobalFree(hMem);
// ------------- end code fragment --------------
Additional reference words: 3.00 GetMetaFile UAE