0

I have this code below:

static internal bool SaveEnhMetafileToFile(Metafile mf, string fileName)
{
  bool bResult = false;
    IntPtr hEMF;
    hEMF = mf.GetHenhmetafile(); // invalidates mf 
    if (!hEMF.Equals(new IntPtr(0)))
    {
        StringBuilder tempName = new StringBuilder(fileName);
        CopyEnhMetaFile(hEMF, tempName);
        DeleteEnhMetaFile(hEMF);

   }
    return bResult;
}

When CopyEnhMetaFile(hEMF, tempName); is called, the picture is created but after calling DeleteEnhMetaFile(hEMF); function I cannot delete the picture because it is used by my program (vshost.exe). The program is created in C#

Ștefan Blaga
  • 404
  • 1
  • 5
  • 22

1 Answers1

1

As stated in the link I posted - you need to delete the handle created by CopyEnhMetaFile :

static internal bool SaveEnhMetafileToFile(Metafile mf, string fileName)
{
  bool bResult = false;
  IntPtr hEMF;
  hEMF = mf.GetHenhmetafile(); // invalidates mf 
  if (!hEMF.Equals(new IntPtr(0)))
  {
    StringBuilder tempName = new StringBuilder(fileName);
    IntPtr hCopyEMF = CopyEnhMetaFile(hEMF, tempName.ToString());
    DeleteEnhMetaFile(hCopyEMF);
    DeleteEnhMetaFile(hEMF);
  }
return bResult;
}
PaulF
  • 6,673
  • 2
  • 18
  • 29