Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CopyEnhMetaFile (gdi32)
 
.
Summary

C# Signature:

[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, string lpszFile);

User-Defined Types:

None.

Notes:

Please note that this API method needs to be called twice! 1st to get the size of the enh meta file and 2nd to fill the buffer.

Metafile.GetHenhmetafile() should be called only once on the instance. Subsequent calls result with "Parameter is not valid" error.

Tips & Tricks:

Please add some!

Sample Code:

public static byte[] GetEnhMetaFileBits(Metafile mf)
    {
        ResetLastError(); // sets last error to 0 using  [DllImport("kernel32.dll", SetLastError = false)]public static extern int SetLastError(uint dwErrCode);
        IntPtr hMf = mf.GetHenhmetafile();
        uint bufferSize = GetEnhMetaFileBits(hMf, 0, null); // Get required buffer size specifying 0 and NULL.
        if (bufferSize == 0)
        {
        int lastError = Marshal.GetLastWin32Error();
        throw new Exception("GetEnhMetaFileBits failed.", new Win32Exception(lastError));
        }
        byte[] buffer = new byte[bufferSize];
        if (GetEnhMetaFileBits(hMf, bufferSize, buffer) == 0) // Get raw metafile data.
        {
        int lastError = Marshal.GetLastWin32Error();
        throw new Exception("GetEnhMetaFileBits failed.", new Win32Exception(lastError));
        }
        return buffer;
    }

[DllImport("gdi32.dll", EntryPoint = "CopyEnhMetaFile", SetLastError = true, CharSet = CharSet.Auto)]
    private static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, string lpszFile);

Alternative Managed API:

Do you know one? Please contribute it!

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions