@msdn=http://search.microsoft.com/search/results.aspx?qu=$$$ @pinvoke=http://pinvoke.net/$$$.htm @IDataObject=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/oin_d_8cl0.asp @OleGetClipboard=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/htm/ofn_oa2k_8vvo.asp @SystemInvalidCastException=http://msdn2.microsoft.com/library/System.InvalidCastException.aspx @SystemRuntimeInteropServicesDllImport=http://msdn2.microsoft.com/library/System.Runtime.InteropServices.DllImportAttribute.aspx @SystemWindowsFormsClipboardGetDataObject=http://msdn2.microsoft.com/library/System.Windows.Forms.Clipboard.GetDataObject.aspx @SystemWindowsFormsIDataObject=http://msdn2.microsoft.com/library/System.Windows.Forms.IDataObject.aspx @SystemWindowsFormsDataObject=http://msdn2.microsoft.com/library/System.Windows.Forms.DataObject.aspx Summary: Retrieves a data object that you can use to access the contents of the clipboard. !!!!C# Signature: ''alternative'' [DllImport("ole32.dll")] static extern int OleGetClipboard([MarshalAs(UnmanagedType.IUnknown)]out object ppDataObj); ''original'' [DllImport("ole32.dll")] static extern int OleGetClipboard(out IDataObject ppDataObj); !!!!User-Defined Types: None. !!!!Notes: The original signature requires a definition for the COM version of IDataObject@IDataObject, as defined in objidl.h. The lack of this definition implies that the System.Windows.Forms.IDataObject@SystemWindowsFormsIDataObject interface can be used, but this interface, although COM-visible, is not the same as the COM one and results in a System.InvalidCastException@SystemInvalidCastException. The alternative posted uses an object, which can then be passed to a System.Windows.Forms.DataObject@SystemWindowsFormsDataObject ctor. Ideally though there should be a complete definition for the COM IDataObject@IDataObject interface (and all of its supporting types). !!!!Tips & Tricks: I find it better to turn off PreserveSig@SystemRuntimeInteropServicesDllImport for methods that return an HRESULT and have a trailing out parameter, providing that the HRESULT does not have more that one success code (typically S_OK only). This results in a slightly cleaner syntax where the out parameter becomes the return value and a failing HRESULT results in an exception. [DllImport("ole32.dll", PreserveSig=false)] [return: MarshalAs(UnmanagedType.IUnknown)] static extern object OleGetClipboard(); !!!!C# Sample Code: using System.Diagnostics; using System.Runtime.Interop; using System.Windows.Forms; ''PreserveSig=true'' class Program { [DllImport("ole32.dll")] static extern int OleGetClipboard([MarshalAs(UnmanagedType.IUnknown)]out object ppDataObj); [STAThread()] static void Main(string[] args) { object unk; int result = OleGetClipboard(out unk); Debug.Assert(result == 0); DataObject data = new DataObject(unk); foreach (string format in data.GetFormats()) Debug.WriteLine(format); } } ''PreserveSig=false'' class Program { [DllImport("ole32.dll", PreserveSig=false)] [return: MarshalAs(UnmanagedType.IUnknown)] static extern object OleGetClipboard(); [STAThread()] static void Main(string[] args) { object unk = OleGetClipboard(); DataObject data = new DataObject(unk); foreach (string format in data.GetFormats()) Debug.WriteLine(format); } } !!!!Alternative Managed API: System.Windows.Forms.Clipboard.GetDataObject@SystemWindowsFormsClipboardGetDataObject Documentation: OleGetClipboard@OleGetClipboard on MSDN
Edit ole32.olegetclipb...
You do not have permission to change this page. If you feel this is in error, please send feedback with the contact link on the main page.