Microsoft KB Archive/86429

{|
 * width="100%"|

PRB: Successful LoadResource of Metafile Yields Random Data

 * }

Q86429

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK)
 * Microsoft Win32 Software Development Kit (SDK)

-

SYMPTOMS
When an application for the Microsoft Windows graphical environment calls the LoadResource function to load a metafile from the application's resources, locks the metafile with the LockResource function, and uses the metafile, the application receives random data even though the LoadResource and LockResource functions indicate successful completion.

CAUSE
The application loaded the metafile previously and when the application freed the metafile, it used the DeleteMetaFile function to invalidate the metafile handle.

RESOLUTION
Modify the code that unloads the metafile from memory to call the FreeResource function.

MORE INFORMATION
The LoadResource and FreeResource functions change the lock count for a memory block that contains the resource. If the application calls DeleteMetaFile, Windows does not change the lock count. When the application subsequently calls LoadResource for the metafile, Windows does not load the metafile because the lock count indicates that it remains in memory. However, the returned memory handle points to the random contents of that memory block.

For more information on the resource lock count, query in the Microsoft Knowledge Base on the following words:

"multiple and references and LoadResource" Most of the time, an application uses the DeleteMetaFile function to remove a metafile from memory. This function is appropriate for metafiles created with the CopyMetaFile or CreateMetaFile functions, or metafiles loaded from disk with the GetMetaFile function. However, DeleteMetaFile does not decrement the lock count of a metafile loaded as a resource.

Additional query words: EnumMetaFile GetMetaFile GetMetaFileBits PlayMetaFile PlayMetaFileRecord SetMetaFileBits SetMetaFileBitsBetter

Keywords : kbOSWinNT kbOSWin2000 kbResource kbSDKWin32 kbGrpDSUser kbOSWin

Issue type : kbprb

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch kbWinSDKSearch