473,662 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FatalExecutionE ngineError calling Clipboard.GetDa taObject().GetD ata() with EnhancedMetafil e

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.GetDa taObject();
IDataObject prevClipboard = new DataObject();

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

I got the error on the oldClipboard.Ge tData(s) line when the data in
the clipboard is of type "EnahancedMetaf ile" (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 "EnhancedMetafi le" format.

Thanks.
Andrea
Aug 8 '07 #1
5 3438
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("user 32.dll")]
private static extern int IsClipboardForm atAvailable(int wFormat);
[DllImport("user 32.dll")]
private static extern IntPtr GetClipboardDat a(int wFormat);

static public Metafile GetEnhMetafileO nClipboard(IntP tr hWnd)
{
Metafile meta = null;
if (OpenClipboard( hWnd))
{
try
{
if (IsClipboardFor matAvailable(CF _ENHMETAFILE) != 0)
{
IntPtr hEMF = GetClipboardDat a(CF_ENHMETAFIL E);
meta = new Metafile(hEMF, true);
}
}
finally
{
CloseClipboard( );
}
}
return meta;
}

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

Metafile mf = ClipboardMetafi leHelper.GetEnh MetafileOnClipb oard(Handle);
if (mf != null)
{
ClipboardMetafi leHelper.PutEnh MetafileOnClipb oard(Handle, mf);
}
Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, 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.

Aug 8 '07 #2
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

On Wed, 08 Aug 2007 08:13:07 GMT, wa****@online.m icrosoft.com ("Walter
Wang [MSFT]") wrote:
>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("user 32.dll")]
private static extern int IsClipboardForm atAvailable(int wFormat);
[DllImport("user 32.dll")]
private static extern IntPtr GetClipboardDat a(int wFormat);

static public Metafile GetEnhMetafileO nClipboard(IntP tr hWnd)
{
Metafile meta = null;
if (OpenClipboard( hWnd))
{
try
{
if (IsClipboardFor matAvailable(CF _ENHMETAFILE) != 0)
{
IntPtr hEMF = GetClipboardDat a(CF_ENHMETAFIL E);
meta = new Metafile(hEMF, true);
}
}
finally
{
CloseClipboard( );
}
}
return meta;
}

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

Metafile mf = ClipboardMetafi leHelper.GetEnh MetafileOnClipb oard(Handle);
if (mf != null)
{
ClipboardMetafi leHelper.PutEnh MetafileOnClipb oard(Handle, mf);
}
Hope this helps.
Regards,
Walter Wang (wa****@online. microsoft.com, 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.
Aug 8 '07 #3
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 (wa****@online. microsoft.com, 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.

Aug 9 '07 #4
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.Enh ancedMetafile, 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 (wa****@online. microsoft.com, 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.
Aug 14 '07 #5
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 (wa****@online. microsoft.com, 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.

Aug 16 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
6599
by: Joshua Campbell | last post by:
I am working on an application that needs to parse out data that has been copied into the clipboard. My first questions are how can I detect if the clipboard is empty, and how can I empty the clipboard? I tried the code below, but it didn't seem to tell me if the clipboard was empty. If Clipboard.GetDataObject() Is Nothing Then MessageBox.Show("Clipboard is empty") Else Dim txtdata As IDataObject = Clipboard.GetDataObject() If...
1
2149
by: andrew | last post by:
I have a MSchart object (COM Component) which I wish to insert as an image into a picture box so that I can print it out. 'I call the chart controls's EditCopy to pass data to the clipboard. Dim Img As Image MyChart.EditCopy() 'I then declare an IDataObject
1
3090
by: B. Cline | last post by:
Hi, I need to write a conversion routine to split pictures out of about 10000 word documents. (Actually the text is converted to RTF, the pictures should be converted to jpg). I thought I could simply save the word doc as rtf and strip the picture. That works. The problem is getting the picture to save correctly. I can use word to determine which pictures are in the original document and can get them to the clipboard. I can't seem to...
3
6720
by: Scott Friedrich | last post by:
Hi group I am using a 3rd party AX control in a VB.NET application. One of the methods of this control is to capture the current map within the control to the windows clipboard as .WMF. I am automating some precesses for the client and I don't know how to programmatically paste the WMF from the clipboard to another control in the application. The picture box control supports WMF but I don't know how to set its image property to whats in...
2
8003
by: George Yefchak | last post by:
Hi I need to retrieve a metafile image from the clipboard and render it as a bitmap in my application. In particular, an image will be placed on the clipboard by pasting from PowerPoint (I really do need to do this!). The original image is a bitmap, but PowerPoint doesn't place it on the clipboard as such. A call to GetFormats() indicates that MetafilePict and EnhancedMetaFile are available formats. The following does NOT work:
2
3878
by: fred | last post by:
I am trying to Copy and paste using a custom format but I canot retrieve the data. In the main Form's class I have declared: Dim myDocmanFormat as DataFormats.Format then in the New Sub of the main form I have: myDocmanFormat = DataFormats.GetFormat("DocmanFormat")
7
11614
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
6
3955
by: Ed Bitzer | last post by:
Appreciate some help. Want to continuously check clipboard and if text present unhide and display in a text. The following code can find nothing in the clipboard even though I paste information there from Notepad. \\ Public Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click Dim t As New System.Timers.Timer(2000) AddHandler t.Elapsed, AddressOf TimerFired t.Enabled = True End Sub
3
6579
by: NoDozing | last post by:
Trying load an embedded object to the clipboard and then save it to a file. When I try and save to the file, I'm getting a "Object reference not set to an instance of an object". I've marked the line with ---->>> where the error occurs. Any help would be appreciated. Dim InShapeObj As Word.InlineShape Dim SaveObj As New DataObject Dim ImageObj As Image Dim WordApp As New Word.ApplicationClass...
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
1992
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.