[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, string lpszFile);
None.
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.
Please add some!
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);
Do you know one? Please contribute it!