FatalExecutionEngineError calling Clipboard.GetDataObject().GetData() with EnhancedMetafile

N

nagar

I have a .NET 2.0 application that needs to backup and restore the
contents of the clipboard.

When I back it up, I use this code:

DataObject oldClipboard = Clipboard.GetDataObject();
IDataObject prevClipboard = new DataObject();

string[] formats;
formats = oldClipboard.GetFormats(); //gets all the possible formats
for that data
foreach (string s in formats) {
object clipdata = oldClipboard.GetData(s);
prevClipboard.SetData(s, clipdata ); //re-associate the old
data with the proper types
}

I got the error on the oldClipboard.GetData(s) line when the data in
the clipboard is of type "EnahancedMetafile" (I could reproduce it
copying a piece of text which contained an HTML email from OneNote).

The error message says: Error address 0x79f387cc. Error code
0xc0000005

I saw there's no way I can trap this error in the code. At the moment,
I'm just ignoring the "EnhancedMetafile" format.

Thanks.
Andrea
 
W

Walter Wang [MSFT]

Hi Andrea,

This is because .NET Framework uses a new Clipboard format for the
metafiles, to interop with other programs, we will have to use Clipboard
APIs to get/put the metafiles:

#PRB: Metafiles on Clipboard Are Not Visible to All Applications
http://support.microsoft.com/kb/323530

The above KB only has a method to put a metafile on clipboard, I've added
another function to get the metafile from clipboard:


private const int CF_ENHMETAFILE = 14;
[DllImport("user32.dll")]
private static extern int IsClipboardFormatAvailable(int wFormat);
[DllImport("user32.dll")]
private static extern IntPtr GetClipboardData(int wFormat);

static public Metafile GetEnhMetafileOnClipboard(IntPtr hWnd)
{
Metafile meta = null;
if (OpenClipboard(hWnd))
{
try
{
if (IsClipboardFormatAvailable(CF_ENHMETAFILE) != 0)
{
IntPtr hEMF = GetClipboardData(CF_ENHMETAFILE);
meta = new Metafile(hEMF, true);
}
}
finally
{
CloseClipboard();
}
}
return meta;
}



Add above code in the KB's class ClipboardMetafileHelper, passed following
test code:

Metafile mf = ClipboardMetafileHelper.GetEnhMetafileOnClipboard(Handle);
if (mf != null)
{
ClipboardMetafileHelper.PutEnhMetafileOnClipboard(Handle, mf);
}


Hope this helps.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

nagar

Thanks Walter.
Currently, I've solved my problem avoiding to backup the metafile data
(I noticed that v.1.1 of the framework worked fine). Do you know if
there are other breaking changes with other file formats in .NET 2.0?
Thanks
Andrea
 
W

Walter Wang [MSFT]

Hi Andrea,

Thanks for your quick reply.

I'll ask the KB owner to see if there's any other changes related to this
behavior. I'll keep you posted.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Andrea,

I've consulted your question and got following information for you:

1) The CF_ENHMETAFILE data format isn't compatible with .NET's
DataFormats.EnhancedMetafile, this applies for both .NET Framework 1.1 and
2.0; but .NET 1.1 it's not throwing exception, the return value is
undefined.

2) So far we're not aware of any other data formats are not compatible with
standard formats.

Hope this helps.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Andrea,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else I can help. Thanks.



Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top