Click here to Skip to main content
15,881,715 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: Run a .NET app on a machine without .NET by including DLLS???? Pin
Henry Minute21-May-09 8:57
Henry Minute21-May-09 8:57 
GeneralRe: Run a .NET app on a machine without .NET by including DLLS???? Pin
Hypermommy21-May-09 9:06
Hypermommy21-May-09 9:06 
GeneralRe: Run a .NET app on a machine without .NET by including DLLS???? Pin
Henry Minute21-May-09 9:18
Henry Minute21-May-09 9:18 
GeneralRe: Run a .NET app on a machine without .NET by including DLLS???? Pin
Hypermommy21-May-09 10:17
Hypermommy21-May-09 10:17 
GeneralRe: Run a .NET app on a machine without .NET by including DLLS???? Pin
Henry Minute21-May-09 10:22
Henry Minute21-May-09 10:22 
Question.NET C# TreeView, checkbox, TreeNode checked bug PinPopular
John Kaminski20-May-09 7:44
John Kaminski20-May-09 7:44 
AnswerRe: .NET C# TreeView, checkbox, TreeNode checked bug Pin
John Kaminski1-Jun-09 7:57
John Kaminski1-Jun-09 7:57 
Questionfatal error C1083: Cannot open source file: '.\hello.cpp': No such file or directory Pin
mike73319-May-09 22:40
mike73319-May-09 22:40 
AnswerRe: fatal error C1083: Cannot open source file: '.\hello.cpp': No such file or directory Pin
Dave Kreskowiak20-May-09 2:08
mveDave Kreskowiak20-May-09 2:08 
QuestionEncapsulating Excel Document in Custom Application Pin
Member 319930419-May-09 6:16
Member 319930419-May-09 6:16 
AnswerRe: Encapsulating Excel Document in Custom Application Pin
led mike19-May-09 6:43
led mike19-May-09 6:43 
QuestionRe: Encapsulating Excel Document in Custom Application Pin
Member 319930419-May-09 7:32
Member 319930419-May-09 7:32 
AnswerRe: Encapsulating Excel Document in Custom Application Pin
led mike19-May-09 7:49
led mike19-May-09 7:49 
AnswerRe: Encapsulating Excel Document in Custom Application Pin
syntax28uk21-May-09 5:08
syntax28uk21-May-09 5:08 
QuestionDirectSound doesn't work under Vista? Pin
Andrey U19-May-09 1:26
Andrey U19-May-09 1:26 
AnswerRe: DirectSound doesn't work under Vista? Pin
Mark Salsbery19-May-09 6:06
Mark Salsbery19-May-09 6:06 
GeneralRe: DirectSound doesn't work under Vista? Pin
molesworth19-May-09 22:14
molesworth19-May-09 22:14 
GeneralRe: DirectSound doesn't work under Vista? Pin
Mark Salsbery20-May-09 5:16
Mark Salsbery20-May-09 5:16 
GeneralRe: DirectSound doesn't work under Vista? Pin
led mike20-May-09 5:23
led mike20-May-09 5:23 
GeneralRe: DirectSound doesn't work under Vista? Pin
Mark Salsbery20-May-09 5:41
Mark Salsbery20-May-09 5:41 
GeneralRe: DirectSound doesn't work under Vista? Pin
molesworth20-May-09 5:40
molesworth20-May-09 5:40 
GeneralRe: DirectSound doesn't work under Vista? Pin
Mark Salsbery20-May-09 5:42
Mark Salsbery20-May-09 5:42 
AnswerRe: DirectSound doesn't work under Vista? Pin
musefan20-May-09 0:08
musefan20-May-09 0:08 
AnswerRe: DirectSound doesn't work under Vista? Pin
Andrey U23-May-09 6:44
Andrey U23-May-09 6:44 
QuestionCOMException when getting custom data from system clipboard [modified] Pin
Mike_Finch18-May-09 14:07
Mike_Finch18-May-09 14:07 
I have a custom type, FooNode, defined in my C# code.   I want to add an instance of that custom type to the global System.Windows.Forms.Clipboard, and then retrieve it from the clipboard again.   The add seems to work, but I am not able to retrieve the instance.   Upon retrieval, several exceptions print to standard output like the following:

A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Windows.Forms.dll
(... and 9 more just like above)


The result of the retrieval is a null reference.   There is no crash or halt.   The above exceptions are being dealt with internally;   I am not able to catch them.   The problem is not with the DataObject itself, because I can retrieve my FooNode from it.   I just can't retreive my FooNode from the clipboard's DataObject.

I am able to add and then retreive other types of objects to the system clipboard, such as strings and System.Guid.   Why can I not retrieve an object of my custom type?

Following is my test code.   Call FooTest.Test() to run.

using System;
using System.Diagnostics;
using System.Windows.Forms;
 
 
public class FooNode
{
    private Guid m_Guid;
    private string m_Name = String.Empty;
 
    public FooNode( )
    {
        m_Guid = Guid.NewGuid();
        m_Name = "Foo";
    }
 
    public Guid Guid
    {
        get { return m_Guid; }
        set { m_Guid = value; }
    }
 
    public string Name
    {
        get { return m_Name; }
        set { m_Name = value; }
    }
}
 
 
public class FooTest
{
    // Entry point for test of using system clipboard.
    public static void Test( )
    {
        FooNode fooNode = new FooNode();
 
        // Add a FooNode to the system clipboard.    
        DataObject dob = new DataObject( fooNode );
        dob.SetData( typeof( Guid ), fooNode.Guid );
        dob.SetData( DataFormats.StringFormat, fooNode.Guid.ToString() );
        Clipboard.SetDataObject( dob );
 
        // Retrieve the FooNode from the system clipboard.
        // *** Notice that the returned object is null. ***
        object raw = Clipboard.GetDataObject().GetData( typeof( FooNode ) );
 
        // This spam function demonstrates what can and cannot be retrieved from the clipboard.
        Spam( Clipboard.GetDataObject(), new Type[] { typeof( FooNode ), typeof( Guid ) } );
    }
 
 
    public static void Spam( IDataObject dob, Type[] types )
    {
        Debug.WriteLine( dob );
        Debug.Indent();
 
        Debug.WriteLine( "Data formats:" );
        Debug.Indent();
        string[] formatNames = dob.GetFormats( true );
        foreach ( string name in formatNames )
        {
            Debug.WriteLine( name );
        }
        Debug.Unindent();
 
        // Test if I can access the data by format name.
        foreach ( string name in formatNames )
        {
            if ( dob.GetDataPresent( name ) )
            {
                Debug.WriteLine( String.Format( "Present as format=\"{0}\"", name ) );
                Debug.Indent();
                object raw = dob.GetData( name );
                Debug.WriteLine( String.Format( "raw={0}", raw != null ? raw : "null" ) );
                Debug.Unindent();
            }
        }
 
        // Test if I can access the data by type.
        if ( types != null )
        {
            foreach ( Type type in types )
            {
                if ( dob.GetDataPresent( type ) )
                {
                    Debug.WriteLine( String.Format( "Present as type={0}", type ) );
                    Debug.Indent();
                    object raw = dob.GetData( type );
                    Debug.WriteLine( String.Format( "raw={0}", raw != null ? raw : "null" ) );
                    Debug.Unindent();
                }
            }
        }
 
        Debug.Unindent();
    }
}


modified on Monday, May 18, 2009 8:21 PM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.