日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

windows消息队列C语言,08年计算机二级C语言辅导:vc操作微软消息队列的方法

發布時間:2023/12/15 windows 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 windows消息队列C语言,08年计算机二级C语言辅导:vc操作微软消息队列的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

定義

IMSMQQueuePtr qDest; // Represents Destination Queue

IMSMQQueueInfoPtr qInfo; //Represents an open instance of the destination queue

IMSMQQueueInfoPtr qRead;

IMSMQMessagePtr qMsg; //Represents the message

初始化

qDest = NULL;

CoInitialize(NULL);

try{

qInfo.CreateInstance("MSMQ.MSMQQueueInfo");

qRead.CreateInstance("MSMQ.MSMQQueueInfo");

qMsg.CreateInstance("MSMQ.MSMQMessage");

lpszSystemInfo = tchBuffer;

GetComputerName(lpszSystemInfo,&cchBuff); // Getting the ComputerName

m_ServerName=lpszSystemInfo;

UpdateData(FALSE);

}

catch (_com_error)

{

MessageBox("Failed in CreateInstance of MSMQQueueInfo","MSMQ QueueInfo",1);

PostQuitMessage(1);

ReleaseAll();

}

創建消息隊列

try

{

// m_ServerName = .\Private$\aaa 創建專有隊列

// m_ServerName = .\aaa 公用隊列

//

// qInfo->PathName = m_ServerName.AllocSysString(); // Setting the Queue Path

CString fname;

fname="DIRECT=OS:";

fname+=m_ServerName;

qInfo->PathName = m_ServerName.AllocSysString();

qInfo->FormatName = fname.AllocSysString();

qInfo->Label= m_msgLabel.AllocSysString(); // Setting the Queue Label

ht = qInfo->Create();

qInfo->Journal=1; // Enabling the Journal Option

qInfo->Update();

qInfo->Refresh();

}

catch (_com_error e)

{

CString str;

str.Format("%s",e.ErrorMessage());

MessageBox("Creating a Queue Failed","Create Queue",1);

//ReleaseAll();

}

給消息隊列發送數據

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.71\\Private$\\test" 私有

// qInfo->FormatName L"DIRECT=TCP:10.9.255.71\\test" 公共

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();

}

總結

以上是生活随笔為你收集整理的windows消息队列C语言,08年计算机二级C语言辅导:vc操作微软消息队列的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。