public int ReadStruct(byte[] b, int Offset, int Length) { int versionLength = this.GetVersionLength(); int result = Offset; int length = this.GetLength(); int requiredBufferSize = this.GetRequiredBufferSize(); IntPtr intPtr = IntPtr.Zero; try { if (intPtr == IntPtr.Zero) { intPtr = Marshal.AllocCoTaskMem(length); this.mqODSize = versionLength; } Marshal.Copy(b, Offset, intPtr, versionLength); if (this.useNativePtrSz) { this.mqOD = (MQOD)Marshal.PtrToStructure(intPtr, typeof(MQOD)); this.copyToMQOD32(); } else { this.mqOD32 = (MQOD32)Marshal.PtrToStructure(intPtr, typeof(MQOD32)); this.copyToMQOD(); } result = Offset + requiredBufferSize; if (this.mqOD.Version >= 4) { this.objectString.ReadStruct(b, Offset, Offset + this.OBJSTRING_OFFSET); this.objectString.GetEndPosAligned(Offset); this.selectionString.ReadStruct(b, Offset, Offset + this.SELSTRING_OFFSET); this.selectionString.GetEndPosAligned(Offset); this.resolvedObjectString.ReadStruct(b, Offset, Offset + this.ROBJSTRING_OFFSET); this.resolvedObjectString.GetEndPosAligned(Offset); } this.ClearInvalidFields(this.mqOD.Version); } finally { if (intPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(intPtr); intPtr = IntPtr.Zero; } } return(result); }
protected void Open(MQObjectDescriptor od) { int hobj, compCode, reason; od.CopyCHARVIntoOD(); if (od.Version == MQC.MQOD_VERSION_1 || od.Version == MQC.MQOD_VERSION_2) { MQOD structMQOD = od.StructMQOD; Bindings.MQOPEN(qMgr.Handle, ref structMQOD, OpenOptions, out hobj, out compCode, out reason); } else { byte[] array = new byte[od.GetRequiredBufferSize()]; od.WriteStruct(array, 0); IntPtr intPtr = Marshal.AllocCoTaskMem(array.Length); try { Marshal.Copy(array, 0, intPtr, array.Length); Bindings.MQOPEN(qMgr.Handle, intPtr, OpenOptions, out hobj, out compCode, out reason); } finally { if (intPtr != IntPtr.Zero) { Marshal.FreeCoTaskMem(intPtr); } } } if (compCode != MQC.MQCC_OK) { throw new MQException(compCode, reason); } objectHandle = hobj; ObjectName = od.ObjectName; ObjectType = od.ObjectType; }