VC (WinCE 消息队列)

WinCE 下提供了消息队列机制

首先是创建消息队列的方法

创建消息队列需要传入配置项 使用MSGQUEUEOPTIONS 结构体来进行配置

		MSGQUEUEOPTIONS	option;
		option.dwSize = sizeof(MSGQUEUEOPTIONS);//结构体大小
		option.dwMaxMessages  = 100;        //最大消息数
		option.cbMaxMessage = sizeof(MSG);    //单个消息最大内存占用
		option.bReadAccess = FALSE;	//创建一个写消息队列(false) 创建一个读消息队列则是(true)
		option.dwFlags =  MSGQUEUE_ALLOW_BROKEN ;//消息队列行为

https://docs.microsoft.com/zh-cn/previous-versions/windows/embedded/ms886759%28v%3dmsdn.10%29 详细解释 

创建一个消息队列 

hFileServerSendQ = CreateMsgQueue(“消息队列名字”, &option);//创建一个消息队列 返回的是一个句柄

 读取消息

BOOL ReadMsgQueue(HANDLEhMsgQ,LPVOIDlpBuffer,DWORDcbBufferSize,LPDWORDlpNumberOfBytesRead,DWORDdwTimeout,DWORD* pdwFlags);

参数详解

  • hMsgQ
    [in] Handle to an open message queue.//消息队列名称
  • lpBuffer//读取消息的指针
    [out] Pointer to a buffer to store a read message. This parameter cannot be NULL.
  • cbBufferSize//读取数据大小
    [in] Size of the buffer, in bytes, specified by lpBuffer. This parameter cannot be 0 (zero).
  • lpNumberOfBytesRead
    [out] Number of bytes stored in lpBuffer. This parameter cannot be NULL.
  • dwTimeout//等待时间,如果是0 则不等待 如果是INFINITE 则一直阻塞
    [in] Time in milliseconds (ms) before the read operation times out. If set to zero, the read operation will not block if there is no data to read. If set to INFINITE, the read operation will block until data is available or the status of the queue changes.
  • pdwFlags //返回的消息的属性
    [out] Pointer to a DWORD to indicate the properties of the message. A value of MSGQUEUE_MSGALERT specifies that the message is an alert message.

读取成功返回true 读取失败返回false

如果出现错误可以使用GetLastError() 获取更多错误信息

 

ValueDescription
ERROR_INSUFFICIENT_BUFFERThe buffer specified by lpBuffer is too small to read a message. The read will succeed but only cbBufferSize bytes of data will be copied.
ERROR_PIPE_NOT_CONNECTEDNo writers are attached to the message queue and MSGQUEUE_ALLOW_BROKEN is not specified. All the writers exit while a reader is blocked and MSGQUEUE_ALLOW_BROKEN is not specified, the read will fail.
ERROR_TIMEOUTdwTimeout is zero and there is no data to read.

(解释转自MSDN)

写入消息

BOOL WriteMsgQueue(HANDLEhMsgQ,LPVOIDlpBuffer,DWORDcbDataSize,DWORDdwTimeout,DWORDdwFlags);

  • hMsgQ
    [in] Handle to an open message queue.
  • lpBuffer
    [in] Pointer to a buffer that contains data to write to a message queue. This parameter cannot be NULL.
  • cbDataSize
    [in] Number of bytes stored in lpBuffer that comprise a message. This parameter cannot be 0 (zero).
  • dwTimeout
    [in] Amount of time, in milliseconds (ms), before the write operation will time out. If zero is specified, the write operation will not block if the write operation cannot succeed. If you set the parameter to INFINITE, the write operation will block until the write operation succeeds or the queue status changed.
  • dwFlags
    [in] DWORD value to indicate the properties of the message. You can set it to MSGQUEUE_MSGALERT to specify that the message is an alert message.

基本一致

具体可以参考(https://docs.microsoft.com/zh-cn/previous-versions/windows/embedded/aa450991(v=msdn.10)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值