1.打开消息队列,获得消息队列的句柄 queueHandle
2.创建完成IO端口 ,hPort=CreateIoCompletionPort,但不与queueHandle绑定
3.创建异步读取msg线程: CreateThread
4.pending hPort and queueHandle, use CreateIoCompletionPort Function
5.try to receive msg from queue,if there are no msg, 'MQReceiveMessage ' will return wrong errNo.(MQ_ERROR_INVALID_PARAMETER)
P.S:在主线程种调用MQReceiveMessage,必须设置参数OVERLAPPED structure ,此为异步接受的关键,若空,则视为同步接受
在步骤3创建的线程中,需要完成以下工作:
a.hr=GetQueuedCompletionStatus,超时时间可设置为INFINITE
b.判断输出参数// OVERLAPPED structure,是否为空
c.Get the final status (last error) for the message received. MQGetOverlappedResult
d.处理读取到的msg
e。下一次接收数据