Message Queuing(MSMQ)学习之旅(三)——获取机器信息
MSMQ能够通过MQGetMachineProperties 获取本机或其他机器的的公共密钥,site list,path name等信息。这里需要注意的就是如果PROPID_QM_ENCRYPTION_PK和PROPID_QM_ENCRYPTION_PK_BASE同时存在,将有一个属性不能成功获取。而MS推荐使用的是PROPID_QM_ENCRYPTION_PK_BASE参数,所以就当PROPID_QM_ENCRYPTION_PK不存在吧。不多说,上代码。
void GetMachineProp(){ const int NUMBEROFPROPERTIES = 8; QMPROPID aPropId[NUMBEROFPROPERTIES]; MQPROPVARIANT aPropVar[NUMBEROFPROPERTIES]; HRESULT aStatus[NUMBEROFPROPERTIES]; HRESULT hr = MQ_OK; DWORD cPropId = 0; aPropId[cPropId] = PROPID_QM_CONNECTION; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_ENCRYPTION_PK_BASE; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_ENCRYPTION_PK_ENHANCED; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_MACHINE_ID; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_PATHNAME; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_SITE_ID; aPropVar[cPropId].vt = VT_NULL; cPropId++; aPropId[cPropId] = PROPID_QM_PATHNAME_DNS; aPropVar[cPropId].vt = VT_NULL; cPropId++; MQQMPROPS pQMProps; pQMProps.cProp =cPropId; pQMProps.aPropID = aPropId; pQMProps.aPropVar = aPropVar; pQMProps.aStatus = aStatus; MQGetMachineProperties(NULL,NULL,&pQMProps); for(int i=0;i<cPropId;i++){ HandleMsmqError(pQMProps.aStatus[i]); if( pQMProps.aPropVar[i].vt== (VT_VECTOR | VT_LPWSTR)){ for (int j = 0; j < pQMProps.aPropVar[i].calpwstr.cElems; j++) { std::wcout<<pQMProps.aPropVar[i].calpwstr.pElems[j]<<std::endl; MQFreeMemory(pQMProps.aPropVar[i].calpwstr.pElems[j]); //Free each element } MQFreeMemory(pQMProps.aPropVar[i].calpwstr.pElems); } else if( pQMProps.aPropVar[i].vt== (VT_VECTOR | VT_UI1)){ MQFreeMemory(pQMProps.aPropVar[i].caub.pElems); } else{ MQFreeMemory(pQMProps.aPropVar[i].pwszVal); } } }
作者:Jingle Guo
出处:http://www.cnblogs.com/studynote/
若标题中有“转载”字样,则本文版权归原作者所有。若无转载字样,本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.