vc操作微軟消息隊(duì)列的方法

字號:

定義
    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();
    }
    創(chuàng)建消息隊(duì)列
    try
    {
    // m_ServerName = .\Private$\aaa 創(chuàng)建專有隊(duì)列
    // m_ServerName = .\aaa 公用隊(duì)列
    //
    // 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();
    }