void IBclAdviseSink.OnRename(BclComTypes.IMoniker moniker) { if (null != bclSink) { bclSink.OnRename(moniker); } else { // TODO: Use the IMoniker converter when ready. oleSink.OnRename(null); } }
internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr) { if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) { return new ComTypeClassDesc(typeInfo, null); } else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM) { return new ComTypeEnumDesc(typeInfo, null); } else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) || (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)) { ComTypeDesc typeDesc = new ComTypeDesc(typeInfo, ComType.Interface, null); return typeDesc; } else { throw new InvalidOperationException("Attempting to wrap an unsupported enum type."); } }
internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo, ComTypes.TYPEATTR typeAttr) { if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) { return new ComTypeClassDesc(typeInfo); } else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM) { return new ComTypeEnumDesc(typeInfo); } else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) || (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)) { return new ComTypeDesc(typeInfo); } else { throw Error.UnsupportedEnumType(); } }
private void AddInterface(ComTypes.ITypeInfo itfTypeInfo, bool isSourceItf) { string itfName = ComRuntimeHelpers.GetNameOfType(itfTypeInfo); if (isSourceItf) { if (_sourceItfs == null) { _sourceItfs = new LinkedList<string>(); } _sourceItfs.AddLast(itfName); } else { if (_itfs == null) { _itfs = new LinkedList<string>(); } _itfs.AddLast(itfName); } }
internal static ComTypeDesc FromITypeInfo(ComTypes.ITypeInfo typeInfo) { ComTypes.TYPEATTR typeAttr; typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo); if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_COCLASS) { return new ComTypeClassDesc(typeInfo); } else if (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_ENUM) { return new ComTypeEnumDesc(typeInfo); } else if ((typeAttr.typekind == ComTypes.TYPEKIND.TKIND_DISPATCH) || (typeAttr.typekind == ComTypes.TYPEKIND.TKIND_INTERFACE)) { ComTypeDesc typeDesc = new ComTypeDesc(typeInfo); return typeDesc; } else { throw Error.UnsupportedEnumType(); } }
internal ComTypeClassDesc(ComTypes.ITypeInfo typeInfo) : base(typeInfo) { ComTypes.TYPEATTR typeAttr = ComRuntimeHelpers.GetTypeAttrForTypeInfo(typeInfo); Guid = typeAttr.guid; for (int i = 0; i < typeAttr.cImplTypes; i++) { int hRefType; typeInfo.GetRefTypeOfImplType(i, out hRefType); ComTypes.ITypeInfo currentTypeInfo; typeInfo.GetRefTypeInfo(hRefType, out currentTypeInfo); ComTypes.IMPLTYPEFLAGS implTypeFlags; typeInfo.GetImplTypeFlags(i, out implTypeFlags); bool isSourceItf = (implTypeFlags & ComTypes.IMPLTYPEFLAGS.IMPLTYPEFLAG_FSOURCE) != 0; AddInterface(currentTypeInfo, isSourceItf); } }
internal static ComTypeLibDesc GetFromTypeLib(ComTypes.ITypeLib typeLib) { // check whether we have already loaded this type library ComTypes.TYPELIBATTR typeLibAttr = ComRuntimeHelpers.GetTypeAttrForTypeLib(typeLib); ComTypeLibDesc typeLibDesc; lock (_CachedTypeLibDesc) { if (_CachedTypeLibDesc.TryGetValue(typeLibAttr.guid, out typeLibDesc)) { return typeLibDesc; } } typeLibDesc = new ComTypeLibDesc(); typeLibDesc._typeLibName = ComRuntimeHelpers.GetNameOfLib(typeLib); int countTypes = typeLib.GetTypeInfoCount(); for (int i = 0; i < countTypes; i++) { ComTypes.TYPEKIND typeKind; typeLib.GetTypeInfoType(i, out typeKind); ComTypes.ITypeInfo typeInfo; if (typeKind == ComTypes.TYPEKIND.TKIND_COCLASS) { typeLib.GetTypeInfo(i, out typeInfo); ComTypeClassDesc classDesc = new ComTypeClassDesc(typeInfo); typeLibDesc._classes.AddLast(classDesc); } else if (typeKind == ComTypes.TYPEKIND.TKIND_ENUM) { typeLib.GetTypeInfo(i, out typeInfo); ComTypeEnumDesc enumDesc = new ComTypeEnumDesc(typeInfo); typeLibDesc._enums.Add(enumDesc.TypeName, enumDesc); } } // cache the typelib using the guid as the dictionary key lock (_CachedTypeLibDesc) { //check if we are late and somebody already added the key. ComTypeLibDesc curLibDesc; if (_CachedTypeLibDesc.TryGetValue(typeLibAttr.guid, out curLibDesc)) { return curLibDesc; } _CachedTypeLibDesc.Add(typeLibAttr.guid, typeLibDesc); } return typeLibDesc; }
void IBclAdviseSink.OnDataChange(ref BclComTypes.FORMATETC format, ref BclComTypes.STGMEDIUM stgmedium) { if (null != bclSink) { bclSink.OnDataChange(ref format, ref stgmedium); } else { // As in the previous case we have to copy the parameters. OleInterop.FORMATETC[] pFormatetc = new OleInterop.FORMATETC[1]; pFormatetc[0] = StructConverter.BclFormatETC2Ole(ref format); OleInterop.STGMEDIUM[] pStgmed = new OleInterop.STGMEDIUM[1]; pStgmed[0] = StructConverter.BclSTGMEDIUM2Ole(ref stgmedium); // Call the original interface. oleSink.OnDataChange(pFormatetc, pStgmed); } }
/// <summary> /// Filetimes a FILETIME to a DateTime. /// </summary> /// <param name="fileTime">The FILETIME object.</param> /// <returns>A DateTime object cointaining the converted value.</returns> private static DateTime FiletimeToDateTime(ComType.FILETIME fileTime) { try { if (fileTime.dwLowDateTime < 0) { fileTime.dwLowDateTime = 0; } if (fileTime.dwHighDateTime < 0) { fileTime.dwHighDateTime = 0; } long rawFileTime = (((long)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime; return DateTime.FromFileTimeUtc(rawFileTime); } catch (ArgumentOutOfRangeException) { return new DateTime(); } }
// FORMATETC /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // STGMEDIUM internal static OleInterop.STGMEDIUM BclSTGMEDIUM2Ole(ref BclComTypes.STGMEDIUM bclMedium) { OleInterop.STGMEDIUM oleMedium; oleMedium.pUnkForRelease = bclMedium.pUnkForRelease; oleMedium.tymed = (uint)bclMedium.tymed; oleMedium.unionmember = bclMedium.unionmember; return oleMedium; }
// STGMEDIUM /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // STATDATA internal static OleInterop.STATDATA BclSTATDATA2Ole(ref BclComTypes.STATDATA bclData) { OleInterop.STATDATA oleData; if (null == bclData.advSink) { oleData.pAdvSink = null; } else { oleData.pAdvSink = bclData.advSink as OleInterop.IAdviseSink; if (null == oleData.pAdvSink) oleData.pAdvSink = (new AdviseSink(bclData.advSink)); } oleData.ADVF = (uint)bclData.advf; oleData.dwConnection = (uint)bclData.connection; oleData.FORMATETC = BclFormatETC2Ole(ref bclData.formatetc); return oleData; }
/////////////////////////////////////////////////////////////////////////////////// // FORMATETC internal static OleInterop.FORMATETC BclFormatETC2Ole(ref BclComTypes.FORMATETC bclFormat) { OleInterop.FORMATETC oleFormat; oleFormat.cfFormat = (ushort)bclFormat.cfFormat; oleFormat.dwAspect = (uint)bclFormat.dwAspect; oleFormat.lindex = bclFormat.lindex; oleFormat.ptd = bclFormat.ptd; oleFormat.tymed = (uint)bclFormat.tymed; return oleFormat; }
int BclComTypes.IEnumFORMATETC.Next(int celt, BclComTypes.FORMATETC[] rgelt, int[] pceltFetched) { if (null != bclEnum) { return bclEnum.Next(celt, rgelt, pceltFetched); } OleInterop.FORMATETC[] oleStat = new OleInterop.FORMATETC[celt]; uint[] fetched = new uint[1]; int hr = oleEnum.Next((uint)celt, oleStat, fetched); if (NativeMethods.Failed(hr)) return hr; if (null != pceltFetched) pceltFetched[0] = (int)fetched[0]; for (uint i = 0; i < fetched[0]; i++) { rgelt[i] = StructConverter.OleFormatETC2Bcl(ref oleStat[i]); } return hr; }
void BclComTypes.IDataObject.SetData(ref BclComTypes.FORMATETC formatIn, ref BclComTypes.STGMEDIUM medium, bool release) { if (null != bclData) { bclData.SetData(ref formatIn, ref medium, release); return; } OleInterop.FORMATETC[] oleFormat = new OleInterop.FORMATETC[1]; oleFormat[0] = StructConverter.BclFormatETC2Ole(ref formatIn); OleInterop.STGMEDIUM[] oleMedium = new OleInterop.STGMEDIUM[1]; oleMedium[0] = StructConverter.BclSTGMEDIUM2Ole(ref medium); oleData.SetData(oleFormat, oleMedium, release ? 1 : 0); }
int BclComTypes.IEnumSTATDATA.Next(int celt, BclComTypes.STATDATA[] rgelt, int[] pceltFetched) { if (null != bclEnum) { return bclEnum.Next(celt, rgelt, pceltFetched); } OleInterop.STATDATA[] oleStat = new OleInterop.STATDATA[celt]; uint fetched; int hr = oleEnum.Next((uint)celt, oleStat, out fetched); if (NativeMethods.Failed(hr)) return hr; if (null != pceltFetched) pceltFetched[0] = (int)fetched; for (int i = 0; i < fetched; i++) { rgelt[i] = StructConverter.OleSTATDATA2Bcl(ref oleStat[i]); } return hr; }
BclComTypes.IEnumFORMATETC BclComTypes.IDataObject.EnumFormatEtc(BclComTypes.DATADIR direction) { if (bclData != null) return bclData.EnumFormatEtc(direction); OleInterop.IEnumFORMATETC oleEnum; NativeMethods.ThrowOnFailure(oleData.EnumFormatEtc((uint)direction, out oleEnum)); if (null == oleEnum) return null; BclComTypes.IEnumFORMATETC bclEnum = oleEnum as BclComTypes.IEnumFORMATETC; if (null == bclEnum) bclEnum = (BclComTypes.IEnumFORMATETC)(new EnumFORMATETC(oleEnum)); return bclEnum; }
internal EnumSTATDATA(BclComTypes.IEnumSTATDATA bclEnum) { if (null == bclEnum) throw new ArgumentNullException("System.Runtime.InteropServices.ComTypes.IEnumSTATDATA"); this.oleEnum = bclEnum as OleInterop.IEnumSTATDATA; this.bclEnum = bclEnum; }
int BclComTypes.IDataObject.EnumDAdvise(out BclComTypes.IEnumSTATDATA enumAdvise) { if (null != bclData) return bclData.EnumDAdvise(out enumAdvise); OleInterop.IEnumSTATDATA oleEnum; int hr = oleData.EnumDAdvise(out oleEnum); NativeMethods.ThrowOnFailure(hr); if (null == oleEnum) { enumAdvise = null; } else { enumAdvise = oleEnum as BclComTypes.IEnumSTATDATA; if (null == enumAdvise) enumAdvise = (BclComTypes.IEnumSTATDATA)(new EnumSTATDATA(oleEnum)); } return hr; }
int BclComTypes.IDataObject.DAdvise(ref BclComTypes.FORMATETC pFormatetc, BclComTypes.ADVF advf, BclComTypes.IAdviseSink adviseSink, out int connection) { if (null != bclData) return bclData.DAdvise(ref pFormatetc, advf, adviseSink, out connection); OleInterop.FORMATETC[] oleFormat = new OleInterop.FORMATETC[1]; oleFormat[0] = StructConverter.BclFormatETC2Ole(ref pFormatetc); uint result; OleInterop.IAdviseSink oleSink = adviseSink as OleInterop.IAdviseSink; if (null == oleSink) oleSink = (OleInterop.IAdviseSink)(new AdviseSink(adviseSink)); int hr = oleData.DAdvise(oleFormat, (uint)advf, oleSink, out result); NativeMethods.ThrowOnFailure(hr); connection = (int)result; return hr; }
internal Ole2BclDataObject(BclComTypes.IDataObject bclData) { if (null == bclData) throw new ArgumentNullException("System.Runtime.InteropServices.ComTypes.IDataObject"); //this.oleData = bclData as OleInterop.IDataObject; this.oleData = null; this.bclData = bclData; }
void BclComTypes.IEnumFORMATETC.Clone(out BclComTypes.IEnumFORMATETC newEnum) { newEnum = null; if (null != bclEnum) { bclEnum.Clone(out newEnum); } else { OleInterop.IEnumFORMATETC oleCloned; oleEnum.Clone(out oleCloned); newEnum = oleCloned as BclComTypes.IEnumFORMATETC; if (null == newEnum) newEnum = (BclComTypes.IEnumFORMATETC)(new EnumFORMATETC(oleCloned)); } }
void BclComTypes.IDataObject.GetDataHere(ref BclComTypes.FORMATETC format, ref BclComTypes.STGMEDIUM medium) { if (null != bclData) { bclData.GetDataHere(ref format, ref medium); return; } OleInterop.FORMATETC[] oleFormat = new OleInterop.FORMATETC[1]; oleFormat[0] = StructConverter.BclFormatETC2Ole(ref format); OleInterop.STGMEDIUM[] oleMedium = new OleInterop.STGMEDIUM[1]; oleMedium[0] = StructConverter.BclSTGMEDIUM2Ole(ref medium); oleData.GetDataHere(oleFormat, oleMedium); medium = StructConverter.OleSTGMEDIUM2Bcl(ref oleMedium[0]); }
internal EnumFORMATETC(BclComTypes.IEnumFORMATETC bclEnum) { if (null == bclEnum) throw new ArgumentNullException("System.Runtime.InteropServices.ComTypes.IEnumFORMATETC"); this.oleEnum = bclEnum as OleInterop.IEnumFORMATETC; this.bclEnum = bclEnum; }
int BclComTypes.IDataObject.QueryGetData(ref BclComTypes.FORMATETC format) { if (null != bclData) return bclData.QueryGetData(ref format); OleInterop.FORMATETC[] oleFormat = new OleInterop.FORMATETC[1]; oleFormat[0] = StructConverter.BclFormatETC2Ole(ref format); return oleData.QueryGetData(oleFormat); }
int BclComTypes.IDataObject.GetCanonicalFormatEtc(ref BclComTypes.FORMATETC formatIn, out BclComTypes.FORMATETC formatOut) { if (null != bclData) return bclData.GetCanonicalFormatEtc(ref formatIn, out formatOut); OleInterop.FORMATETC[] oleFormatIn = new OleInterop.FORMATETC[1]; OleInterop.FORMATETC[] oleFormatOut = new OleInterop.FORMATETC[1]; oleFormatIn[0] = StructConverter.BclFormatETC2Ole(ref formatIn); int hr = oleData.GetCanonicalFormatEtc(oleFormatIn, oleFormatOut); NativeMethods.ThrowOnFailure(hr); formatOut = StructConverter.OleFormatETC2Bcl(ref oleFormatOut[0]); return hr; }
void BclComTypes.IEnumSTATDATA.Clone(out BclComTypes.IEnumSTATDATA newEnum) { newEnum = null; if (null != bclEnum) { bclEnum.Clone(out newEnum); } else { OleInterop.IEnumSTATDATA oleCloned; oleEnum.Clone(out oleCloned); newEnum = oleCloned as BclComTypes.IEnumSTATDATA; if (null == newEnum) newEnum = (BclComTypes.IEnumSTATDATA)(new EnumSTATDATA(oleCloned)); } }