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

.NET (Core and Framework)

 
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

AnswerRe: COMException when getting custom data from system clipboard Pin
Luc Pattyn18-May-09 14:35
sitebuilderLuc Pattyn18-May-09 14:35 
GeneralRe: COMException when getting custom data from system clipboard Pin
Mike_Finch19-May-09 4:50
Mike_Finch19-May-09 4:50 
GeneralRe: COMException when getting custom data from system clipboard Pin
Luc Pattyn19-May-09 4:58
sitebuilderLuc Pattyn19-May-09 4:58 
QuestionEncrypt Live Audiovideo stream in ASP.NET Web Application Pin
er.sandy18-May-09 2:46
er.sandy18-May-09 2:46 
AnswerRe: Encrypt Live Audiovideo stream in ASP.NET Web Application Pin
Dave Kreskowiak18-May-09 8:51
mveDave Kreskowiak18-May-09 8:51 
GeneralRe: Encrypt Live Audiovideo stream in ASP.NET Web Application Pin
er.sandy18-May-09 18:46
er.sandy18-May-09 18:46 
GeneralRe: Encrypt Live Audiovideo stream in ASP.NET Web Application Pin
Dave Kreskowiak19-May-09 4:41
mveDave Kreskowiak19-May-09 4:41 
QuestionGetting Error message in debuging Pin
deadlyabbas17-May-09 19:02
deadlyabbas17-May-09 19:02 
AnswerRe: Getting Error message in debuging Pin
Dave Kreskowiak18-May-09 8:52
mveDave Kreskowiak18-May-09 8:52 
QuestionFolderBrowserDialog closes my dialog window Pin
Poolee17-May-09 9:24
Poolee17-May-09 9:24 
AnswerRe: FolderBrowserDialog closes my dialog window Pin
Mark Salsbery17-May-09 10:13
Mark Salsbery17-May-09 10:13 
GeneralRe: FolderBrowserDialog closes my dialog window Pin
Poolee17-May-09 12:02
Poolee17-May-09 12:02 
GeneralRe: FolderBrowserDialog closes my dialog window Pin
Mark Salsbery17-May-09 15:14
Mark Salsbery17-May-09 15:14 
GeneralRe: FolderBrowserDialog closes my dialog window Pin
Poolee17-May-09 16:47
Poolee17-May-09 16:47 
AnswerRe: FolderBrowserDialog closes my dialog window Pin
Poolee17-May-09 18:48
Poolee17-May-09 18:48 
GeneralRe: FolderBrowserDialog closes my dialog window Pin
Mark Salsbery17-May-09 19:05
Mark Salsbery17-May-09 19:05 
QuestionMySql connector problem Pin
JayKhatri15-May-09 21:39
JayKhatri15-May-09 21:39 

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.