Skip to content

Instantly share code, notes, and snippets.

@atifaziz
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifaziz/9625878 to your computer and use it in GitHub Desktop.
Save atifaziz/9625878 to your computer and use it in GitHub Desktop.
XlTable clipboard format used by Excel in DDE
#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