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 ;
}
vc 添加HTTP mime类型
最新推荐文章于 2021-03-08 22:23:03 发布