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

 

posted @ 2013-03-26 15:19  Jingle Guo  阅读(395)  评论(0编辑  收藏  举报