예제 #1
0
        internal static uint Count(this PipeName pipeName)
        {
            MSMQExt.MQMGMTPROPS props = new MSMQExt.MQMGMTPROPS {
                cProp = 1
            };
            try
            {
                props.aPropID = Marshal.AllocHGlobal(sizeof(int));
                Marshal.WriteInt32(props.aPropID, (int)MSMQExt.MQMGMT_QUEUE_PROPERTIES.PROPID_MGMT_QUEUE_MESSAGE_COUNT);

                // Marshal.SizeOf(typeof(MSMQExt.MQPROPVARIANT))
                props.aPropVar = Marshal.AllocHGlobal(24);
                Marshal.StructureToPtr(new MSMQExt.MQPROPVARIANT {
                    vt = MSMQExt.VT_NULL
                }, props.aPropVar, false);

                props.aStatus = Marshal.AllocHGlobal(sizeof(int));
                Marshal.WriteInt32(props.aStatus, 0);

                string machineName = (pipeName.IsLocal()) ? null : pipeName.MachineName;
                string specialPath = "QUEUE=" + pipeName.GetMSMQDirectName();

                int result = MSMQExt.MQMgmtGetInfo(machineName, specialPath, ref props);
                if (result != 0 || Marshal.ReadInt32(props.aStatus) != 0)
                {
                    return(0);
                }

                MSMQExt.MQPROPVARIANT propVar = (MSMQExt.MQPROPVARIANT)Marshal.PtrToStructure(props.aPropVar, typeof(MSMQExt.MQPROPVARIANT));
                if (propVar.vt != MSMQExt.VT_UI4)
                {
                    return(0);
                }
                else
                {
                    return(propVar.Union1.ulVal);
                }
            }
            finally
            {
                Marshal.FreeHGlobal(props.aPropID);
                Marshal.FreeHGlobal(props.aPropVar);
                Marshal.FreeHGlobal(props.aStatus);
            }
        }
예제 #2
0
        internal static uint Count(this PipeName pipeName)
        {
            MSMQExt.MQMGMTPROPS props = new MSMQExt.MQMGMTPROPS { cProp = 1 };
            try
            {
                props.aPropID = Marshal.AllocHGlobal(sizeof(int));
                Marshal.WriteInt32(props.aPropID, (int)MSMQExt.MQMGMT_QUEUE_PROPERTIES.PROPID_MGMT_QUEUE_MESSAGE_COUNT);

                // Marshal.SizeOf(typeof(MSMQExt.MQPROPVARIANT))
                props.aPropVar = Marshal.AllocHGlobal(24);
                Marshal.StructureToPtr(new MSMQExt.MQPROPVARIANT { vt = MSMQExt.VT_NULL }, props.aPropVar, false);

                props.aStatus = Marshal.AllocHGlobal(sizeof(int));
                Marshal.WriteInt32(props.aStatus, 0);

                string machineName = (pipeName.IsLocal()) ? null : pipeName.MachineName;
                string specialPath = "QUEUE=" + pipeName.GetMSMQDirectName();

                int result = MSMQExt.MQMgmtGetInfo(machineName, specialPath, ref props);
                if (result != 0 || Marshal.ReadInt32(props.aStatus) != 0)
                {
                    return 0;
                }

                MSMQExt.MQPROPVARIANT propVar = (MSMQExt.MQPROPVARIANT)Marshal.PtrToStructure(props.aPropVar, typeof(MSMQExt.MQPROPVARIANT));
                if (propVar.vt != MSMQExt.VT_UI4)
                {
                    return 0;
                }
                else
                {
                    return propVar.Union1.ulVal;
                }
            }
            finally
            {
                Marshal.FreeHGlobal(props.aPropID);
                Marshal.FreeHGlobal(props.aPropVar);
                Marshal.FreeHGlobal(props.aStatus);
            }
        }