msmqc++接收消息问题
MSMQ c++ receive message problem
我正在尝试从c++中的MSMQ队列中读取消息。队列已成功打开,但我无法从队列中读取任何消息。
此代码示例取自MSDN并在几个地方进行了修改。下面是代码:
// Define the required constants and variables.
const int NUMBEROFPROPERTIES = 5;
DWORD cPropId = 0;
HRESULT hr = MQ_OK; // Return code
ULONG ulBufferSize = 256;
// Define an MQMSGPROPS structure.
MQMSGPROPS msgprops;
MSGPROPID aMsgPropId[NUMBEROFPROPERTIES];
MQPROPVARIANT aMsgPropVar[NUMBEROFPROPERTIES];
HRESULT aMsgStatus[NUMBEROFPROPERTIES];
// Specify the message properties to be retrieved.
aMsgPropId[cPropId] = PROPID_M_LABEL_LEN; // Property ID
aMsgPropVar[cPropId].vt = VT_UI4; // Type indicator
aMsgPropVar[cPropId].ulVal = MQ_MAX_MSG_LABEL_LEN; // Length of label
cPropId++;
WCHAR wszLabelBuffer[MQ_MAX_MSG_LABEL_LEN]; // Label buffer
aMsgPropId[cPropId] = PROPID_M_LABEL; // Property ID
aMsgPropVar[cPropId].vt = VT_LPWSTR; // Type indicator
aMsgPropVar[cPropId].pwszVal = wszLabelBuffer; // Label buffer
cPropId++;
UCHAR * pucBodyBuffer = NULL;
pucBodyBuffer = (UCHAR*)malloc(ulBufferSize);
if (pucBodyBuffer == NULL)
{
return MQ_ERROR_INSUFFICIENT_RESOURCES;
}
memset(pucBodyBuffer, 0, ulBufferSize);
aMsgPropId[cPropId] = PROPID_M_BODY_SIZE; // Property ID
aMsgPropVar[cPropId].vt = VT_NULL; // Type indicator
cPropId++;
aMsgPropId[cPropId] = PROPID_M_BODY; // Property ID
aMsgPropVar[cPropId].vt = VT_VECTOR | VT_UI1; // Type indicator
aMsgPropVar[cPropId].caub.pElems = (UCHAR*)pucBodyBuffer; // Body buffer
aMsgPropVar[cPropId].caub.cElems = ulBufferSize; // Buffer size
cPropId++;
aMsgPropId[cPropId] = PROPID_M_BODY_TYPE; // Property ID
aMsgPropVar[cPropId].vt = VT_NULL; // Type indicator
cPropId++;
// Initialize the MQMSGPROPS structure.
msgprops.cProp = cPropId; // Number of message properties
msgprops.aPropID = aMsgPropId; // IDs of the message properties
msgprops.aPropVar = aMsgPropVar; // Values of the message properties
msgprops.aStatus = aMsgStatus; // Error reports
// HERE IS THE ERROR
hr = MQReceiveMessage(
this->readHandle, // Queue handle
// Max time to (msec) to receive the message
// wait soooooo much
INFINITE,
MQ_ACTION_RECEIVE // Receive action
&msgprops, // Message property structure
NULL, // No OVERLAPPED structure
NULL, // No callback function
NULL, // No cursor handle
MQ_NO_TRANSACTION // Not in a transaction
);
// log reading operation result
f<<"log receive operation"<<endl;
f<<hex<<hr<<endl;
f.close();
if (hr == MQ_ERROR_BUFFER_OVERFLOW)
{
//MessageBox(NULL, TEXT("buffer overflow"), TEXT("Message"), MB_OK);
ulBufferSize = aMsgPropVar[2].ulVal*sizeof(UCHAR);
pucBodyBuffer = (UCHAR*)realloc(pucBodyBuffer, ulBufferSize);
if (pucBodyBuffer == NULL)
{
return MQ_ERROR_INSUFFICIENT_RESOURCES;
}
memset(pucBodyBuffer, 0, ulBufferSize);
aMsgPropVar[3].caub.pElems = (UCHAR*)pucBodyBuffer;
aMsgPropVar[3].caub.cElems = ulBufferSize;
}
在指令"MQReceiveMessage"我得到"MQ_ERROR_ILLEGAL_PROPERTY_VALUE"错误代码。
谁能看看我的代码,告诉我什么是错的,什么属性是非法的?
谢谢,
错误代码表明您请求的属性无效。我的猜测是设置aMsgPropVar[cPropId].vt = VT_NULL;
是错误的身体大小和身体类型- MDSN文档表明两者都有类型VT_UI4 -见这里,例如。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 发送和十六进制消息时套接字代码C++问题
- 使用OpenSSL的SHA 512 HMAC消息身份验证的问题
- Firebase C 云消息传递背景问题
- 我无法弄清楚我的程序的问题,即使我已经查看了错误日志消息
- QT 信号插槽问题。发出信号,不调用时隙。没有警告,没有错误,没有消息
- 消息框和MB_HELP的问题
- AOT问题,消息"正在Xamarin iOS上尝试使用Pinvoke JIT编译方法"
- 发送和将消息从一个类发送到另一堂课的问题.MFC程序
- 消息框线程问题
- 如何解决从客户端接收消息时窗口冻结问题(无响应)
- 如果对象将在消息处理程序中使用,如何解决内存泄漏问题
- Google Protobuf3消息中出现多个字符串问题
- 鼠标挂钩和消息框问题
- 设计问题:消息处理组件..调用不正确的重载函数
- 使用SetWindowsHookEx钩子键盘消息的问题
- Windows (c++)上窗口消息的问题(延迟)
- 使用协议缓冲区从文件读取消息时出现问题
- msmqc++接收消息问题