Exemple #1
0
        public void Put1(MQObjectDescriptor od, MQMessage message, MQPutMessageOptions pmo)
        {
            int compCode, reason;

            if (message == null)
            {
                throw new MQException(MQC.MQCC_FAILED, MQC.MQRC_MD_ERROR);
            }
            if (pmo == null)
            {
                throw new MQException(MQC.MQCC_FAILED, MQC.MQRC_PMO_ERROR);
            }

            od.CopyCHARVIntoOD();
            pmo.ValidateOptions();
            byte[] buffer      = message.GetBuffer();
            var    structMQMD  = message.md.StructMQMD;
            var    structMQPMO = pmo.StructMQPMO;

            if (od.Version == MQC.MQOD_VERSION_1 || od.Version == MQC.MQOD_VERSION_2)
            {
                var structMQOD = od.StructMQOD;
                Bindings.MQPUT1(objectHandle, ref structMQOD, ref structMQMD, ref structMQPMO, buffer.Length, buffer, 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.MQPUT1(objectHandle, intPtr, ref structMQMD, ref structMQPMO, buffer.Length, buffer, out compCode, out reason);
                }
                finally
                {
                    if (intPtr != IntPtr.Zero)
                    {
                        Marshal.FreeCoTaskMem(intPtr);
                    }
                }
            }
            if (compCode != MQC.MQCC_OK)
            {
                throw new MQException(compCode, reason);
            }
        }
Exemple #2
0
        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;
        }