Connecting Tech Pros Worldwide Help | Site Map

Adding a new MIMEType

Newbie
 
Join Date: Jan 2009
Posts: 8
#1: Apr 2 '09
Hello der !

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
  1. long CWinWebAppController::CreateMimeType(/*[in]*/ const CMimeType& objCMimeType,
  2.                                           /*[out]*/      wstring& strErr)
  3. {
  4.   IADs*                ptrADs         = 0;
  5.   HRESULT              hr             = S_FALSE;
  6.   CComPtr<IISMimeType> ptrMimeType    = 0;
  7.  
  8.   _variant_t vntMimeMap;
  9.  
  10.  
  11.   //Reinitialise the error code
  12.   m_lError                    = 0;
  13.   m_wstrMethodName            = L"CreateMimeType";
  14.   strErr                      = SUCCESS;
  15.  
  16.  
  17.   try
  18.   {
  19.     //Get the handle to the MimeMap 
  20.     hr = ADsGetObject(L"IIS://LocalHost/MimeMap",IID_IADs,(void**) &ptrADs);
  21.     if(FAILED(hr)) 
  22.     {
  23.       strErr = ADS_GETOBJECT_FAILED;
  24.       throw hr;
  25.     }
  26.  
  27.     hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
  28.     if(FAILED(hr)) 
  29.     {
  30.     }
  31.  
  32.     //Load the property MimeMap
  33.     hr = ptrADs->GetEx(L"MimeMap",&vntMimeMap);
  34.  
  35.  
  36.       SAFEARRAY*  pArrMimeMap ;
  37.       //point the safearray to the array inside the variant..
  38.       pArrMimeMap = vntMimeMap.parray;
  39.  
  40.       //*******************************************************
  41.       long lHigh;
  42.       SAFEARRAY * psa;    // The safearray
  43.       SAFEARRAYBOUND rgsabound[1];    // A one dimensional array
  44.       long * pData;
  45.       long lValue, lIndex;
  46.  
  47.       _variant_t vntNewMimeType;
  48.  
  49.       SafeArrayGetUBound(pArrMimeMap, 1, &lHigh);
  50.  
  51.       rgsabound[0].lLbound = 0;    // With lower bound 0;
  52.       rgsabound[0].cElements = lHigh + 1;
  53.       psa = SafeArrayCreate(VT_BSTR, 1, rgsabound);    
  54.  
  55.       //Copy the existing data into the new one...
  56.       SafeArrayCopyData(pArrMimeMap,psa);
  57.  
  58.       //set the properties of the new mimetype object...
  59.       ptrMimeType->put_Extension((_bstr_t)objCMimeType.GetMimeExtension().c_str());
  60.       ptrMimeType->put_MimeType((_bstr_t)objCMimeType.GetMimeExtension().c_str());
  61.  
  62.       //assign the mime type object to the variant...it is of type IDispatch...
  63.       vntNewMimeType.pdispVal = ptrMimeType;
  64.  
  65.       //put the variant in safe array...
  66.       lIndex = lHigh-1;
  67.  
  68.       SafeArrayPutElement(psa,&lHigh,(void*)&vntNewMimeType);
  69.  
  70.       //now return the newly created safe array in the variant...
  71.       vntMimeMap.parray = psa;
  72.  
  73.       //save the data..
  74.       hr = ptrADs->PutEx(ADS_PROPERTY_UPDATE,L"MimeMap",vntMimeMap);
  75.       if(FAILED(hr)) 
  76.       {
  77.         strErr = GRANT_BY_DEFAULT_FAILED; 
  78.         //LOG_ERROR_MESSAGE(m_wstrClassName,m_wstrMethodName,GRANT_BY_DEFAULT_FAILED);
  79.         throw hr;
  80.       }
  81.  
  82.       //********************************************************
  83.  
  84.  
  85.    }//end try
  86.   CATCH_BLOCK1(m_lError,strErr)
  87.     //delete all the pointers...
  88.   //TRACE_END(m_wstrClassName,m_wstrMethodName)
  89.   return m_lError ;
  90. }

please ignore the various variables used...thats internally used in my class...the problematic part is this line..
Expand|Select|Wrap|Line Numbers
  1. hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
simple that this line seems, for some reason this line results in linking error with :
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 ???
Reply


Similar IIS / Microsoft Internet Information Services bytes