CopyEnhMetaFile (gdi32)
Last changed: -12.47.208.50

.
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.

Tips & Tricks:

Please add some!

Sample Code:

public static byte[] GetEnhMetaFileBits(Metafile mf)
    {
        ResetLastError();
        uint bufferSize = GetEnhMetaFileBits(mf.GetHenhmetafile(), 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(mf.GetHenhmetafile(), 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