copy paste problem

L

Lloyd Dupont

I'm implementing my own, custom, internationalized text editor.
I'm trying to implement copy/paste right now. Which cause me some trouble.
I'm using .NET 2.0 beta 2 (I have ordered and I'm waiting for VS Standart
edition to upgrade).

Basically I have some simple code like that:
===============
public void SelectionCopy()
{
Document doc = GetSelection();
IDataObject ido = new DataObject();
ido.SetData(DataFormats.Text, doc.ToString());
ido.SetData(Document.DataFormat_1_0, doc);
Clipboard.SetDataObject(ido);
}
public void SelectionPaste()
{
IDataObject ido = Clipboard.GetDataObject();
if (ido.GetDataPresent(Document.DataFormat_1_0))
ReplaceSelection((Document)ido.GetData(Document.DataFormat_1_0));
else if(ido.GetDataPresent(DataFormats.Text))
ReplaceSelection((string)ido.GetData(DataFormats.Text));
}
===============

If I copy from my text editor and paste in Notepad it works fine (most of
the time).
However if I copy from my TextEditor to my TextEditor I get and exception
like that:
the debugger catch multiple exception like below deep in the method I'm
calling
=========
System.Runtime.InteropServices.COMException was unhandled
Message="Error HRESULT E_FAIL has been returned from a call to a COM
component."
Source="mscorlib"
ErrorCode=-2147467259
StackTrace:
at
System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32
errorCode, IntPtr errorInfo
at System.Windows.Forms.DataObject.GetDataIntoOleStructs(FORMATETC&
formatetc, STGMEDIUM& medium)
at
System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetDataHere(FORMATETC&
formatetc, STGMEDIUM& medium)
at
System.Windows.Forms.DataObject.System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC&
formatetc, STGMEDIUM& medium)
=======
but they are all catched and finally
ido.GetData(Document.DataFormat_1_0)
return me a null value (instead of the expected document).


Any tip? clue? advice?
 

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