at my wits end and cant figure out what is the problem..
my task is to programmatically configure IIS , part of which is to add MIMETypes...
after googling for a like a million years , found very little help with regard to this topic..finally managed to write some code but there seems to be some strange error..
following is the function..
Expand|Select|Wrap|Line Numbers
- long CWinWebAppController::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 ;
- }
please ignore the various variables used...thats internally used in my class...the problematic part is this line..
Expand|Select|Wrap|Line Numbers
- hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
unresolved external symbol _IID_IISMimeType (note the extra underscore...there is no such word in any of the files...)
specifically on windows 2003 machine. it complies fine on my XP professional machine !!!
the msdn doc states all u need to do is include "IIIS.h" header file which is done , it even finds the IID in the header but failes during linking....
one whole day has been already wasted on this...can someone please tel me what goin on here ?? there is no mention of any lib as well...i thought COM usage didn require any libs to be included in the first place!!!
well the reason i need it to compile in windows 2003 machien is that thsi can only be tested on the test machine(which is 2003 machine)...my dev machien with XP doesn seem to have "properties " as an option when right click on local computer in IIS manager ....properties is required to configure MIME types...which is present in 2003 machines....not in XP...why is that so ???