Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than coredll, prefix the name with the module name and a period.
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.
.
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
<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
Private Sub WriteToClipboard(ByVal text As String)
<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
' 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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUManage As New StringPtr("CopyString")
OpenClipboard(Nothing)
EmptyClipboard()
SetClipboardData(uFormat.CF_UNICODETEXT, strUManage.GetIntPtr) ' copy to clipboad
CloseClipboard()
strUManage.Free() ' error occur.
End Sub
' http://www.microsoft.com/japan/msdn/net/compactframework/netcfadvinterop.aspx
Public Class Memory
...
' Replace this sub
Public Shared Sub FreeHLocal(ByVal hlocal As IntPtr)
If Not hlocal.Equals(IntPtr.Zero) Then
If Not IntPtr.Zero.Equals(LocalFree(hlocal)) Then
' Occurs Error. may be memory leak.
MessageBox.Show("LocalFree Fail" & Marshal.GetLastWin32Error())
'Throw New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())
End If
hlocal = IntPtr.Zero
End If
End Sub
...
End Class
Public Structure StringPtr
...
' Add this Property
Public ReadOnly Property GetIntPtr() As IntPtr
Get
Return szString
End Get
End Property
End Structure
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).