private static unsafe uint getCount(string path) { MQMGMTPROPS props = new MQMGMTPROPS(); props.cProp = 1; int aPropId = PROPID_MGMT_QUEUE_MESSAGE_COUNT; props.aPropID = &aPropId; MQPROPVariant aPropVar = new MQPROPVariant(); aPropVar.vt = VT_NULL; props.aPropVar = &aPropVar; int status = 0; props.status = &status; IntPtr objectName = Marshal.StringToBSTR("queue=Direct=OS:" + path); try { int result = MQMgmtGetInfo(null, (char*)objectName, &props); if (result != 0 || *props.status != 0 || props.aPropVar->vt != VT_UI4) { return 0; } else { return props.aPropVar->ulVal; } } finally { Marshal.FreeBSTR(objectName); } }
private static long GetCount(string computerName, string queuePath) { var props = new MQMGMTPROPS { cProp = 1, aPropID = Marshal.AllocHGlobal(sizeof(int)), aPropVar = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MQPROPVariant))), status = Marshal.AllocHGlobal(sizeof(int)) }; Marshal.WriteInt32(props.aPropID, PROPID_MGMT_QUEUE_MESSAGE_COUNT); Marshal.StructureToPtr(new MQPROPVariant { vt = VT_NULL }, props.aPropVar, false); Marshal.WriteInt32(props.status, 0); try { int result = MQMgmtGetInfo(computerName, queuePath, ref props); //Console.WriteLine("{0} {1} Result:{2:X}", computerName, queuePath, result); switch (result) { case 0: break; case MQ_ERROR_QUEUE_NOT_ACTIVE: return(0); default: throw new Win32Exception(result); } if (Marshal.ReadInt32(props.status) != 0) { return(-1); } var variant = (MQPROPVariant)Marshal.PtrToStructure(props.aPropVar, typeof(MQPROPVariant)); if (variant.vt != VT_UI4) { return(-2); } return(variant.ulVal); } finally { Marshal.FreeHGlobal(props.aPropID); Marshal.FreeHGlobal(props.aPropVar); Marshal.FreeHGlobal(props.status); } }
/// <summary> /// The get count. /// </summary> /// <param name="path"> /// The path. /// </param> /// <returns> /// The <see cref="uint"/>. /// </returns> private static unsafe uint GetCount(string path) { if (!MessageQueue.Exists(path)) { return(0); } var props = new MQMGMTPROPS(); props.cProp = 1; var aPropId = PROPID_MGMT_QUEUE_MESSAGE_COUNT; props.aPropID = &aPropId; var aPropVar = new MQPROPVariant(); aPropVar.vt = VT_NULL; props.aPropVar = &aPropVar; var status = 0; props.status = &status; var objectName = Marshal.StringToBSTR("queue=Direct=OS:" + path); try { uint rtn; lock (LockObject) { var result = MQMgmtGetInfo(null, (char *)objectName, &props); if (result != 0 || *props.status != 0 || props.aPropVar->vt != VT_UI4) { rtn = 0; } else { rtn = props.aPropVar->ulVal; } } return(rtn); } finally { Marshal.FreeBSTR(objectName); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <returns></returns> private static uint GetCount(string path) { if (!MessageQueue.Exists(path)) { return 0; } MQMGMTPROPS props = new MQMGMTPROPS { cProp = 1 }; try { props.aPropID = Marshal.AllocHGlobal(sizeof(int)); Marshal.WriteInt32(props.aPropID, PROPID_MGMT_QUEUE_MESSAGE_COUNT); props.aPropVar = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MQPROPVariant))); Marshal.StructureToPtr(new MQPROPVariant { vt = VT_NULL }, props.aPropVar, false); props.status = Marshal.AllocHGlobal(sizeof(int)); Marshal.WriteInt32(props.status, 0); int result = MQMgmtGetInfo(null, "queue=Direct=OS:" + path, ref props); if (result != 0 || Marshal.ReadInt32(props.status) != 0) { return 0; } MQPROPVariant propVar = (MQPROPVariant)Marshal.PtrToStructure(props.aPropVar, typeof(MQPROPVariant)); if (propVar.vt != VT_UI4) { return 0; } else { return propVar.ulVal; } } finally { Marshal.FreeHGlobal(props.aPropID); Marshal.FreeHGlobal(props.aPropVar); Marshal.FreeHGlobal(props.status); } }
public static unsafe uint GetCount(string path) { if (!MessageQueue.Exists(path)) { return(0); } MQMGMTPROPS props = new MQMGMTPROPS(); props.cProp = 1; int aPropId = PROPID_MGMT_QUEUE_MESSAGE_COUNT; props.aPropID = &aPropId; MQPROPVariant aPropVar = new MQPROPVariant(); aPropVar.vt = VT_NULL; props.aPropVar = &aPropVar; int status = 0; props.status = &status; IntPtr objectName = Marshal.StringToBSTR("queue=Direct=OS:" + path); try { int result = MQMgmtGetInfo(null, (char *)objectName, &props); if (result != 0 || *props.status != 0 || props.aPropVar->vt != VT_UI4) { return(0); } else { return(props.aPropVar->ulVal); } } finally { Marshal.FreeBSTR(objectName); } }
private static unsafe uint GetCount(string path) { var props = new MQMGMTPROPS { cProp = 1 }; var aPropId = PROPID_MGMT_QUEUE_MESSAGE_COUNT; props.aPropID = &aPropId; var aPropVar = new MQPROPVariant { vt = VT_NULL }; props.aPropVar = &aPropVar; var status = 0; props.status = &status; var objectName = Marshal.StringToBSTR("queue=Direct=OS:" + path); try { var result = MQMgmtGetInfo(null, (char *)objectName, &props); if (result != 0 || *props.status != 0 || props.aPropVar->vt != VT_UI4) { return(0); } else { return(props.aPropVar->ulVal); } } finally { Marshal.FreeBSTR(objectName); } }
internal static extern int MQMgmtGetInfo([MarshalAs(UnmanagedType.BStr)] string computerName, [MarshalAs(UnmanagedType.BStr)] string objectName, ref MQMGMTPROPS mgmtProps);
internal static extern int MQMgmtGetInfo([InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string pMachineName, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPWStr)] string pObjectName, ref MQMGMTPROPS pMgmtProps);
private static extern int MQMgmtGetInfo( [MarshalAs(UnmanagedType.BStr)]string computerName, [MarshalAs(UnmanagedType.BStr)]string objectName, ref MQMGMTPROPS mgmtProps);
private static long GetCount(string computerName, string queuePath) { var props = new MQMGMTPROPS { cProp = 1, aPropID = Marshal.AllocHGlobal(sizeof(int)), aPropVar = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MQPROPVariant))), status = Marshal.AllocHGlobal(sizeof(int)) }; Marshal.WriteInt32(props.aPropID, PROPID_MGMT_QUEUE_MESSAGE_COUNT); Marshal.StructureToPtr(new MQPROPVariant { vt = VT_NULL }, props.aPropVar, false); Marshal.WriteInt32(props.status, 0); try { int result = MQMgmtGetInfo(computerName, queuePath, ref props); //Console.WriteLine("{0} {1} Result:{2:X}", computerName, queuePath, result); switch (result) { case 0: break; case MQ_ERROR_QUEUE_NOT_ACTIVE: return 0; default: throw new Win32Exception(result); } if (Marshal.ReadInt32(props.status) != 0) return -1; var variant = (MQPROPVariant)Marshal.PtrToStructure(props.aPropVar, typeof(MQPROPVariant)); if (variant.vt != VT_UI4) return -2; return variant.ulVal; } finally { Marshal.FreeHGlobal(props.aPropID); Marshal.FreeHGlobal(props.aPropVar); Marshal.FreeHGlobal(props.status); } }
internal static extern int MQMgmtGetInfo([InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string pMachineName, [InAttribute()] [MarshalAsAttribute(UnmanagedType.LPWStr)] string pObjectName, ref MQMGMTPROPS pMgmtProps);
private static unsafe extern int MQMgmtGetInfo(char* computerName, char* objectName, MQMGMTPROPS* mgmtProps);
/// <summary> /// The get count. /// </summary> /// <param name="path"> /// The path. /// </param> /// <returns> /// The <see cref="uint"/>. /// </returns> private static unsafe uint GetCount(string path) { if (!MessageQueue.Exists(path)) { return 0; } var props = new MQMGMTPROPS(); props.cProp = 1; var aPropId = PROPID_MGMT_QUEUE_MESSAGE_COUNT; props.aPropID = &aPropId; var aPropVar = new MQPROPVariant(); aPropVar.vt = VT_NULL; props.aPropVar = &aPropVar; var status = 0; props.status = &status; var objectName = Marshal.StringToBSTR("queue=Direct=OS:" + path); try { uint rtn; lock (LockObject) { var result = MQMgmtGetInfo(null, (char*) objectName, &props); if (result != 0 || *props.status != 0 || props.aPropVar->vt != VT_UI4) { rtn = 0; } else { rtn = props.aPropVar->ulVal; } } return rtn; } finally { Marshal.FreeBSTR(objectName); } }