Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

SetClipboardData (coredll)
 

coredll is for smart devices, not desktop Windows. Therefore, this information only applies to code using the .NET Compact Framework. To see if information for SetClipboardData in other DLLs exists, click on Find References to the right.

.
Summary
Set Clipboad data(Text, bitmap, etc).
Relation
OpenClipboard(), CloseClipboard(), EmptyClipboard()

C# Signature:

[DllImport("Coredll.dll", SetLastError=true)]
static extern int SetClipboardData(int uFormat, IntPtr hMem);

VB Signature:

VB.Net Signature:

<DllImport("coredll.dll")> Shared Function SetClipboardData(ByVal uFormat As Integer, ByVal hMem As IntPtr) As Integer
End Function

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

    <DllImport("coredll.dll")> Shared Function OpenClipboard(ByVal hWndNewOwner As Integer) As Boolean
    End Function
    <DllImport("coredll.dll")> Shared Function CloseClipboard() As Boolean
    End Function
    <DllImport("coredll.dll")> Shared Function EmptyClipboard() As Boolean
    End Function
    <DllImport("coredll.dll")> Shared Function SetClipboardData(ByVal uFormat As Integer, ByVal hMem As IntPtr) As Integer
    End Function

    Enum uFormat
        CF_TEXT = 1
        CF_BITMAP = 2
        CF_SYLK = 4
        CF_DIF = 5
        CF_TIFF = 6
        CF_OEMTEXT = 7
        CF_DIB = 8
        CF_PALETTE = 9
        CF_PENDATA = 10
        CF_RIFF = 11
        CF_WAVE = 12
        CF_UNICODETEXT = 13
    End Enum

    Private Sub WriteToClipboard(ByVal text As String)

        Dim pText As IntPtr = Marshal.StringToHGlobalUni(text)
        OpenClipboard(Nothing)
        EmptyClipboard()
        Dim hReturn = SetClipboardData(uFormat.CF_UNICODETEXT, pText)
        CloseClipboard()

        ' If SetClipboardData succeeds, the system owns the object identified by the hMem parameter.
        ' The application may not write to or free the data
        If hReturn <> 0 Then
            Marshal.FreeHGlobal(pText)
        End If
    End Sub

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions