WEB开发网
开发学院软件开发VC vc操作微软消息队列的方法 阅读

vc操作微软消息队列的方法

 2010-07-06 20:42:54 来源:WEB开发网   
核心提示:给消息队列发送数据try{// Create a direct format name of the queue, and// set the FormatName property of the MSMQQueueInfo object.// qInfo->FormatName L"DIRECT=TC

给消息队列发送数据

try
{
// Create a direct format name of the queue, and
// set the FormatName property of the MSMQQueueInfo object.
// qInfo->FormatName L"DIRECT=TCP:10.9.255.71Private$  est" 私有
// qInfo->FormatName L"DIRECT=TCP:10.9.255.71  est" 公共
fname="DIRECT=OS:";
fname+=m_ServerName;
qInfo->PathName=m_ServerName.AllocSysString();
qInfo->FormatName = fname.AllocSysString();
// Open the queue.
qDest = qInfo->Open(MQ_SEND_ACCESS, MQ_DENY_NONE);
qMsg->Label = m_msgLabel.AllocSysString();
VariantInit(&vMessage);
vMessage.vt=VT_BSTR;
vMessage.bstrVal=m_msgData.AllocSysString();
qMsg->put_Body(vMessage);
VariantClear(&vMessage);
qMsg->Send(qDest);
qDest->Close();
}
catch(_com_error)
{
MessageBox("Sending the Queue failed","Send Queue",1);
//ReleaseAll();
}

读取消息队列内容

try
{
qRead->PathName=m_ServerName.AllocSysString();
fname="DIRECT=OS:";
fname+=m_ServerName;
if(status==1) fname=fname+";Journal"; // If Journal Option is Checked
qInfo->PathName=m_ServerName.AllocSysString();
qRead->FormatName = fname.AllocSysString();
qDest = qRead->Open(MQ_RECEIVE_ACCESS,MQ_DENY_NONE);
qMsg = qDest->Receive(&vtMissing,&vtMissing,&vtMissing,&vtReceiveTimeout);
if (qMsg == NULL)
{
return;
}
label=qMsg->GetLabel();
body=qMsg->GetBody().bstrVal;
m_msgLabel=(LPSTR)label;
m_msgData=(LPSTR)body;
UpdateData(FALSE);
qDest->Close();
}
catch(_com_error)
{
MessageBox("Reading the Queue Failed","Read Queue",1);
//ReleaseAll();
}

上一页  1 2 

Tags:vc 操作 微软

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接