closeclipboard (user32)
Last changed: -82.226.104.223

.
Summary

C# Signature:

[DllImport("user32.dll", SetLastError=true)]
static extern bool CloseClipboard();

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

I read on google about a flaw in the .Net System.Windows.Forms.Clipboard.SetDataObject

where you had to run the SetDataObject function twice for it to work. On the first

try it would just error out and the second with work just fine. Well I found that

by using the 3 clipboard API's below first it work every time and you don't have to

wait for the error.

Sample Code:

OpenClipboard(IntPtr.Zero);
EmptyClipboard();
CloseClipboard();

try
{
     System.Windows.Forms.Clipboard.SetDataObject("your message here \n if you would like", true);
}
catch
{
     try
     {
     System.Windows.Forms.Clipboard.SetDataObject("your message here \n if you would like", true);
     }
     catch { };
}

Alternative Managed API:

System.Windows.Forms.Clipboard.SetDataObject("your message here \n if you would like", true);

Documentation