public IEnumerable <DataObjectFormat> GetFormats() { IEnumFORMATETC enumFormatEtc = null !; try { enumFormatEtc = DataObject.EnumFormatEtc(DATADIR.DATADIR_GET); if (enumFormatEtc == null) { return(Array.Empty <DataObjectFormat>()); } enumFormatEtc.Reset(); var fe = new FORMATETC[1]; var fs = new List <DataObjectFormat>(); while (enumFormatEtc.Next(1, fe, null) == 0) { fs.Add(new DataObjectFormat(fe[0])); } return(fs); } finally { if (enumFormatEtc != null) { Marshal.ReleaseComObject(enumFormatEtc); } } }
public virtual string[] GetFormats(bool autoConvert) { Debug.Assert(innerData != null, "You must have an innerData on all DataObjects"); IEnumFORMATETC enumFORMATETC = null; ArrayList formats = new ArrayList(); try { enumFORMATETC = innerData.EnumFormatEtc(DATADIR.DATADIR_GET); } catch { } if (enumFORMATETC != null) { enumFORMATETC.Reset(); FORMATETC[] formatetc = new FORMATETC[] { new FORMATETC() }; int[] retrieved = new int[] { 1 }; while (retrieved[0] > 0) { retrieved[0] = 0; try { enumFORMATETC.Next(1, formatetc, retrieved); } catch { } if (retrieved[0] > 0) { string name = DataFormats.GetFormat(formatetc[0].cfFormat).Name; if (autoConvert) { string[] mappedFormats = GetMappedFormats(name); for (int i = 0; i < mappedFormats.Length; i++) { formats.Add(mappedFormats[i]); } } else { formats.Add(name); } } } } string[] temp = new string[formats.Count]; formats.CopyTo(temp, 0); return(GetDistinctStrings(temp)); }
public virtual string[] GetFormats(bool autoConvert) { Debug.Assert(innerData != null, "You must have an innerData on all DataObjects"); IEnumFORMATETC enumFORMATETC = null; // Since we are only adding elements to the HashSet, the order will be preserved. HashSet <string> distinctFormats = new HashSet <string>(); try { enumFORMATETC = innerData.EnumFormatEtc(DATADIR.DATADIR_GET); } catch { } if (enumFORMATETC != null) { enumFORMATETC.Reset(); FORMATETC[] formatetc = new FORMATETC[] { new FORMATETC() }; int[] retrieved = new int[] { 1 }; while (retrieved[0] > 0) { retrieved[0] = 0; try { enumFORMATETC.Next(1, formatetc, retrieved); } catch { } if (retrieved[0] > 0) { string name = DataFormats.GetFormat(formatetc[0].cfFormat).Name; if (autoConvert) { string[] mappedFormats = GetMappedFormats(name); for (int i = 0; i < mappedFormats.Length; i++) { distinctFormats.Add(mappedFormats[i]); } } else { distinctFormats.Add(name); } } } } return(distinctFormats.ToArray()); }
private static int Reset(IntPtr thisPtr) { try { IEnumFORMATETC instance = ComInterfaceDispatch.GetInstance <IEnumFORMATETC>((ComInterfaceDispatch *)thisPtr); instance.Reset(); return(S_OK); } catch (Exception ex) { Debug.WriteLine(ex); return(ex.HResult); } }