I am working on a diagram editor written in .NET 2.0 using Windows.Forms. Diagrams must be copied into Microsoft Word and Visio as vector graphics.
The editor has a Save as EMF function that works: Word and Visio can import the resulting file as a vector graphics image. The code is similar to this.
I am now adding a Copy as EMF function to support direct copy and paste into Word and Visio,
using the same System.Drawing.Imaging.Metafile
used in the Save as EMF function.
Copying it onto the clipboard using SetData(DataFormats.EnhancedMetafile, ...)
produces a result that Word claims it can paste as EMF, but shows up empty. The documentation explains this and provides a workaround using unmanaged API functions. I have copied that code.
Now the EMF image shows up when pasted into Word, but it doesn't when pasted into Visio! When I paste it into Word, then copy it there and paste it into Visio, it also shows up there.
How can I make this work?
- What is Word doing that my code is not?
- Why does the route via a file work without unmanaged API calls, but not the route via the clipboard?
- Why do I need unmanaged objects (handles) in the first place?
- Is there any self-contained documentation I can read to understand these issues without having to learn Win32 programming?