tags:

views:

71

answers:

1

Is it possible to use the Clipboard class to grab all the data from the clipboard, like full skype quotes? They use some kind of metadata I think, which is how it knows when something is a quote or not.

How can I access that from the Clipboard class? What functions would I call to set/restore Skype quotations?

Thanks for the help!

Imports System.IO
Imports System.Text

Public Class Form1
    Dim locale As New MemoryStream()
    Private Sub l() Handles MyBase.Load

        Dim strr As New StreamReader(CType(Clipboard.GetData("SkypeMessageFragment"), System.IO.Stream))
        locale = Clipboard.GetData("locale")
        TextBox1.Text = strr.ReadToEnd()
        For Each x In Clipboard.GetDataObject().GetFormats()
            'MessageBox.Show("Format " + x + ": " + Clipboard.GetData(x).ToString)
        Next
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Clipboard.Clear()
        Clipboard.SetData("SkypeMessageFragment", StreamFromString(TextBox1.Text))
        Clipboard.SetData("Text", "testing")
        Clipboard.SetData("System.String", "testing")
        Clipboard.SetData("UnicodeText", "testing")
        Clipboard.SetData("OEMText", "testing")
        Clipboard.SetData("locale", locale)
    End Sub
    Private Shared Function StreamFromString(ByVal s As String) As Stream
        Dim encoding As New System.Text.UnicodeEncoding()
        Dim mem As New MemoryStream(encoding.GetBytes(s))
        Return mem
    End Function


End Class
+1  A: 

If you don't know the format then you'll have to experiment. Start by iterating and displaying the available formats, use Clipboard.GetDataObject().GetFormats(). These are strings, you might recognize something. You can pass one of them to Clipboard.GetData(), you'll get an opaque object back. Put it in a watch expression, maybe the debugger can make sense of it.

If Skype uses the clip board for its own use, there's little hope you can dig anything usable out. If it intends to provide clipboard data to common apps like MS Word, without some kind of add-in, there will be lots of hope.

Hans Passant
SkypeMessageFragment is the "type". How can I access this? +1, there's something I didn't know before I started.
Cyclone
As stated, use Clipboard.GetData("some name");
Hans Passant
I got that working, it returns a system.io.stream. How can I set the data now? I can't seem to convert my string back into a system.io.stream again.
Cyclone
Use Stream.Read() in a loop until it return 0. Out will pop something interesting, no doubt.
Hans Passant
I can now set the data, but it isn't being loaded as the actual quote object in Skype. I set all the types to the proper value...
Cyclone
Move over a bit, I can't see over your shoulder from here.
Hans Passant
Added my current code, Textbox1 is a large multiline textbox on the form. Doesn't appear to be working. I commented out the line which will show you the contents of a skype quotation (copy a skype message as a quote to your clipboard). I MUST be missing something.
Cyclone
Also, I thought I made it pretty clear in my comment, it simply isn't loading the skype quotes, even when I set all data.
Cyclone