Last active
August 29, 2015 13:57
-
-
Save atifaziz/9625878 to your computer and use it in GitHub Desktop.
XlTable clipboard format used by Excel in DDE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if WINFORMS | |
using System.Windows.Forms; | |
static partial class XlTableFormat | |
{ | |
static int? _clipboardId; | |
public static int ClipboardId { get { return (_clipboardId ?? (_clipboardId = DataFormats.GetFormat("XlTable").Id)).Value; }} | |
} | |
#else | |
using System; | |
using System.ComponentModel; | |
using System.Runtime.InteropServices; | |
static partial class XlTableFormat | |
{ | |
static readonly Lazy<int> CachedClipboardId = new Lazy<int>(() => (int) LastErrorGate(() => RegisterClipboardFormat("XlTable"))); | |
public static int ClipboardId { get { return CachedClipboardId.Value; }} | |
static uint LastErrorGate(Func<uint> api) | |
{ | |
var result = api(); | |
if (result == 0) throw new Win32Exception(); | |
return result; | |
} | |
[DllImport("user32.dll", SetLastError = true)] | |
public static extern uint RegisterClipboardFormat(string lpszFormat); | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment