vc 添加HTTP mime类型

long CreateMimeType(/*[in]*/ const CMimeType& objCMimeType,
                                          /*[out]*/wstring& strErr)
{
 IADs*  ptrADs= 0;
 HRESULT  hr= S_FALSE;
 CComPtr<IISMimeType>ptrMimeType=0; 
 _variant_t vntMimeMap; 
 //Reinitialise the error code
 m_lError= 0;
 m_wstrMethodName=L"CreateMimeType";
 strErr=SUCCESS; 
 try
 { //Get the handle to the MimeMap
  hr = ADsGetObject(L"IIS://LocalHost/MimeMap",IID_IADs,(void**) &ptrADs);
  if(FAILED(hr))
  {
   strErr = ADS_GETOBJECT_FAILED;
   throw hr;
  }  
  hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
  if(FAILED(hr))
  {
  }  
  //Load the property MimeMap
  hr = ptrADs->GetEx(L"MimeMap",&vntMimeMap);  
  SAFEARRAY*  pArrMimeMap ;
  //point the safearray to the array inside the variant..
  pArrMimeMap = vntMimeMap.parray;  
  //*******************************************************
  long lHigh;
  SAFEARRAY *psa;    // The safearray
  SAFEARRAYBOUND rgsabound[1];    // A one dimensional array
  long * pData;
  long lValue, lIndex;  
  _variant_t vntNewMimeType;  
  SafeArrayGetUBound(pArrMimeMap, 1, &lHigh);  
  rgsabound[0].lLbound=0;    // With lower bound 0;
  rgsabound[0].cElements=lHigh + 1;
  psa=SafeArrayCreate(VT_BSTR, 1, rgsabound);  
  //Copy the existing data into the new one...
  SafeArrayCopyData(pArrMimeMap,psa);  
  //set the properties of the new mimetype object...
  ptrMimeType->put_Extension((_bstr_t)objCMimeType.GetMimeExtension().c_str());
  ptrMimeType->put_MimeType((_bstr_t)objCMimeType.GetMimeExtension().c_str());  
  //assign the mime type object to the variant...it is of type IDispatch...
  vntNewMimeType.pdispVal = ptrMimeType;  
  //put the variant in safe array...
  lIndex = lHigh-1;  
  SafeArrayPutElement(psa,&lHigh,(void*)&vntNewMimeType);  
  //now return the newly created safe array in the variant...
  vntMimeMap.parray=psa;  
  //save the data..
  hr= ptrADs->PutEx(ADS_PROPERTY_UPDATE,L"MimeMap",vntMimeMap);
  if(FAILED(hr))
  {
   strErr = GRANT_BY_DEFAULT_FAILED;
   //LOG_ERROR_MESSAGE(m_wstrClassName,m_wstrMethodName,GRANT_BY_DEFAULT_FAILED);
   throw hr;
  }  
  //********************************************************  
 }//end try
 CATCH_BLOCK1(m_lError,strErr)
  //delete all the pointers...
  //TRACE_END(m_wstrClassName,m_wstrMethodName)
  return m_lError ;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值