void Write(MarshalSig ms) { Write((int)ms.NativeInstrinsic); switch (ms.NativeInstrinsic) { case NativeType.ARRAY: MarshalSig.Array ar = (MarshalSig.Array)ms.Spec; Write((int)ar.ArrayElemType); if (ar.ParamNum != -1) { Write(ar.ParamNum); } if (ar.NumElem != -1) { Write(ar.NumElem); } if (ar.ElemMult != -1) { Write(ar.ElemMult); } break; case NativeType.CUSTOMMARSHALER: MarshalSig.CustomMarshaler cm = (MarshalSig.CustomMarshaler)ms.Spec; Write(cm.Guid); Write(cm.UnmanagedType); Write(cm.ManagedType); Write(cm.Cookie); break; case NativeType.FIXEDARRAY: MarshalSig.FixedArray fa = (MarshalSig.FixedArray)ms.Spec; Write(fa.NumElem); if (fa.ArrayElemType != NativeType.NONE) { Write((int)fa.ArrayElemType); } break; case NativeType.SAFEARRAY: Write((int)((MarshalSig.SafeArray)ms.Spec).ArrayElemType); break; case NativeType.FIXEDSYSSTRING: Write(((MarshalSig.FixedSysString)ms.Spec).Size); break; } }
public MarshalSig GetMarshalSig(MarshalDesc mSpec) { MarshalSig ms = new MarshalSig (mSpec.NativeIntrinsic); if (mSpec is ArrayMarshalDesc) { ArrayMarshalDesc amd = mSpec as ArrayMarshalDesc; MarshalSig.Array ar = new MarshalSig.Array (); ar.ArrayElemType = amd.ElemType; ar.NumElem = amd.NumElem; ar.ParamNum = amd.ParamNum; ar.ElemMult = amd.ElemMult; ms.Spec = ar; } else if (mSpec is CustomMarshalerDesc) { CustomMarshalerDesc cmd = mSpec as CustomMarshalerDesc; MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler (); cm.Guid = cmd.Guid.ToString (); cm.UnmanagedType = cmd.UnmanagedType; cm.ManagedType = cmd.ManagedType; cm.Cookie = cmd.Cookie; ms.Spec = cm; } else if (mSpec is FixedArrayDesc) { FixedArrayDesc fad = mSpec as FixedArrayDesc; MarshalSig.FixedArray fa = new MarshalSig.FixedArray (); fa.ArrayElemType = fad.ElemType; fa.NumElem = fad.NumElem; ms.Spec = fa; } else if (mSpec is FixedSysStringDesc) { MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString (); fss.Size = (mSpec as FixedSysStringDesc).Size; ms.Spec = fss; } else if (mSpec is SafeArrayDesc) { MarshalSig.SafeArray sa = new MarshalSig.SafeArray (); sa.ArrayElemType = (mSpec as SafeArrayDesc).ElemType; ms.Spec = sa; } return ms; }
MarshalSig ReadMarshalSig(byte [] data) { int start; MarshalSig ms = new MarshalSig((NativeType)Utilities.ReadCompressedInteger(data, 0, out start)); switch (ms.NativeInstrinsic) { case NativeType.ARRAY: MarshalSig.Array ar = new MarshalSig.Array(); ar.ArrayElemType = (NativeType)Utilities.ReadCompressedInteger(data, start, out start); if (start < data.Length) { ar.ParamNum = Utilities.ReadCompressedInteger(data, start, out start); } if (start < data.Length) { ar.NumElem = Utilities.ReadCompressedInteger(data, start, out start); } if (start < data.Length) { ar.ElemMult = Utilities.ReadCompressedInteger(data, start, out start); } ms.Spec = ar; break; case NativeType.CUSTOMMARSHALER: MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler(); cm.Guid = ReadUTF8String(data, start, out start); cm.UnmanagedType = ReadUTF8String(data, start, out start); cm.ManagedType = ReadUTF8String(data, start, out start); cm.Cookie = ReadUTF8String(data, start, out start); ms.Spec = cm; break; case NativeType.FIXEDARRAY: MarshalSig.FixedArray fa = new MarshalSig.FixedArray(); fa.NumElem = Utilities.ReadCompressedInteger(data, start, out start); if (start < data.Length) { fa.ArrayElemType = (NativeType)Utilities.ReadCompressedInteger(data, start, out start); } ms.Spec = fa; break; case NativeType.SAFEARRAY: MarshalSig.SafeArray sa = new MarshalSig.SafeArray(); if (start < data.Length) { sa.ArrayElemType = (VariantType)Utilities.ReadCompressedInteger(data, start, out start); } ms.Spec = sa; break; case NativeType.FIXEDSYSSTRING: MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString(); if (start < data.Length) { fss.Size = Utilities.ReadCompressedInteger(data, start, out start); } ms.Spec = fss; break; } return(ms); }
MarshalSig ReadMarshalSig(byte [] data) { int start; MarshalSig ms = new MarshalSig ((NativeType) Utilities.ReadCompressedInteger (data, 0, out start)); switch (ms.NativeInstrinsic) { case NativeType.ARRAY: MarshalSig.Array ar = new MarshalSig.Array (); ar.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start); if (start < data.Length) ar.ParamNum = Utilities.ReadCompressedInteger (data, start, out start); if (start < data.Length) ar.NumElem = Utilities.ReadCompressedInteger (data, start, out start); if (start < data.Length) ar.ElemMult = Utilities.ReadCompressedInteger (data, start, out start); ms.Spec = ar; break; case NativeType.CUSTOMMARSHALER: MarshalSig.CustomMarshaler cm = new MarshalSig.CustomMarshaler (); cm.Guid = ReadUTF8String (data, start, out start); cm.UnmanagedType = ReadUTF8String (data, start, out start); cm.ManagedType = ReadUTF8String (data, start, out start); cm.Cookie = ReadUTF8String (data, start, out start); ms.Spec = cm; break; case NativeType.FIXEDARRAY: MarshalSig.FixedArray fa = new MarshalSig.FixedArray (); fa.NumElem = Utilities.ReadCompressedInteger (data, start, out start); if (start < data.Length) fa.ArrayElemType = (NativeType) Utilities.ReadCompressedInteger (data, start, out start); ms.Spec = fa; break; case NativeType.SAFEARRAY: MarshalSig.SafeArray sa = new MarshalSig.SafeArray (); if (start < data.Length) sa.ArrayElemType = (VariantType) Utilities.ReadCompressedInteger (data, start, out start); ms.Spec = sa; break; case NativeType.FIXEDSYSSTRING: MarshalSig.FixedSysString fss = new MarshalSig.FixedSysString (); if (start < data.Length) fss.Size = Utilities.ReadCompressedInteger (data, start, out start); ms.Spec = fss; break; } return ms; }