Question : Empty/Clear Clipboard

Hi

I want to empty clipboard before getting the required data on to the clipboard by sending keys to some other application. So that I can validate after sending the keys if the clipboard is empty or not before going any furhter. I will get a meta file in clipboard by sending the keys. If I did not get a meta file in clipboard, I wanted to send the keys again.

I have tried
1. Clipboard.setdataobject(string.empty)
2. Clipboard.setdataobject(new dataobject) where the new data object is just declared, it is not set to any object. Say it is a null or empty object.

But both of them return true If I check for contents of clipboard after sending the keys, irrespective of whether sendkeys were sent or not.

When I was going through Microsoft website, they have given the following options as the solutions but, I do not know how to code in VB.Net to do the following
1. PInvoke and call OleSetClipboard API from ole32.dll or
2. Use PInvoke and call the following sequence of methods declared in
user32.dll
OpenClipboard
EmptyClipboard
CloseClipboard

any code for the PInvoke would be very helpfull. Thanks in advance


Answer : Empty/Clear Clipboard

Like this?....

    Private Declare Function OpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hWnd As Integer) As Integer
    Private Declare Function EmptyClipboard Lib "user32" Alias "EmptyClipboard" () As Integer
    Declare Function CloseClipboard Lib "user32" Alias "CloseClipboard" () As Integer

    Public Sub ClearClipboard()
        Call OpenClipboard(Me.Handle.ToInt32)
        Call EmptyClipboard()
        Call CloseClipboard()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ClearClipboard()
    End Sub
Random Solutions  
 
programming4us programming4us