Another solution:
[code]
//-------------------------------------------------------------------
// This class using ConvertEmf2Wmf.dll, which must be "visible", eg.
// in AutoCAD directory, or in directory of this assembly, or ...
//-------------------------------------------------------------------
using System ;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Imaging;
using Autodesk.AutoCAD.Runtime ;
using System.Runtime.InteropServices;
[assembly: CommandClass(typeof(ConvertLIB.EMF2WMFClass))]
namespace ConvertLIB
{
public class EMF2WMFClass
{
//----------------------------------------------
// Command for testing ConvertEmf2Wmf function
//----------------------------------------------
[CommandMethod("EMF2WMF")]
static public void test()
{
ConvertEmf2Wmf("C:\\input.emf","C:\\output.wmf");
}
//-----------------------------------------------
// Function for converting EMF-file to WMF-file
//-----------------------------------------------
[System.Security.SuppressUnmanagedCodeSecurity]
[DllImport("ConvertEmf2Wmf.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
private extern static void ConvertEmf2Wmf(string emf_path, string wmf_path);
}
}
[/code]
Source code of ConvertEmf2Wmf.dll
[code]
#include "stdafx.h"
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
return TRUE;
}
extern "C" __declspec(dllexport) void ConvertEmf2Wmf(char *sFileEmf, char *sFileWmf)
{
HDC hDc = GetDC(GetDesktopWindow()),
hDcComp = CreateCompatibleDC(hDc);
ReleaseDC(GetDesktopWindow(), hDc);
SetMapMode(hDcComp,MM_ANISOTROPIC);
HENHMETAFILE hEmf = GetEnhMetaFile(sFileEmf);
UINT uSize = GetWinMetaFileBits(hEmf, 0, NULL, MM_ANISOTROPIC, hDcComp);
BYTE *pBuffer = (BYTE *) GlobalAlloc(GPTR, uSize);
GetWinMetaFileBits(hEmf, uSize, pBuffer, MM_ANISOTROPIC, hDcComp);
HMETAFILE hWmf = SetMetaFileBitsEx(uSize, pBuffer);
PlayMetaFile(hDcComp, hWmf);
HMETAFILE hWmfNew = CopyMetaFile(hWmf, sFileWmf);
DeleteMetaFile(hWmfNew);
DeleteMetaFile(hWmf);
DeleteEnhMetaFile(hEmf);
GlobalFree(pBuffer);
DeleteDC(hDcComp);
}
[/code]
In attachment I post ConvertEmf2Wmf.dll