#1 |
|||
|
|||
How to add a new MimeType to a Virtual Directory with VC++? Hi, I can't seem to figure out how to add a new MimeType to a virtual With VB, all you have to do is (Microsoft example): With C++, the problem is that aMimeMap(i) is actually of type CComPtr<IISMimeType> pMimeType; hr will return with a "Class not Registered" error. Ideally I want to do something similar to (some code omitted): CComPtr<IISMimeType> pMimeType; pMimeType->put_Extension(_bstr_t(szExtension)); So how do I do what the VB code did with VC++? Thanks for the help |
|
|||||
Re: How to add a new MimeType to a Virtual Directory with VC++? You're right. It's a pain. The following code has worked for me in the past. #include <windows.h> #import "inetsrv/adsiis.dll" _COM_SMARTPTR_TYPEDEF(IADs, __uuidof(IADs)); #define RETURN_ON_FAILURE(hr) if (FAILED(hr)) return (hr); // Trivial wrapper to ensure that array gets cleaned up by destructor VariantArray( ~VariantArray() class SafeArray SafeArray( ~SafeArray() // Updates the MimeMap for pwszMimeMapPath. hr = ADsGetObject(pwszMimeMapPath, IID_IADs, (void**) &pADs); hr = pADs->GetEx(bstrPropname, &var); // We should now have an array of variants, each of which is a if ((VT_VARIANT | VT_ARRAY) != V_VT(&var)) LONG i, j, lSLBound, lSUBound, cVariants = 0; hr = SafeArrayGetLBound(V_ARRAY(&var), 1, &lSLBound ); hr = SafeArrayGetUBound(V_ARRAY(&var), 1, &lSUBound ); cVariants = lSUBound - lSLBound + 1; // Allocate an array to make a local copy of the mime maps that // Copy the mime maps into the local array VariantInit(&varTemp); hr = SafeArrayGetElement(V_ARRAY(&var), &i, &varTemp); if (VT_DISPATCH != V_VT(&varTemp)) hr = V_DISPATCH(&varTemp)->QueryInterface( _bstr_t bstrExtn(pmt->GetExtension()); printf("%ls -> %ls/n", (LPCWSTR) bstrExtn, (LPCWSTR) bstrMimeType); if (bstrExtn == bstrNewExtn) // Remove or update the mapping for pwszExtn? // Update the mapping pmt->PutExtension(bstrNewExtn); // Append pmt to the array ++cVariants; // Create a safearray to hold the full set of mappings VARIANT varArray; V_VT(&varArray) = (VT_VARIANT | VT_ARRAY); for (i = 0; i < cVariants; ++i) // Finally, write the map back. If the map is empty, ADS_PROPERTY_OPERATION_ENUM apo hr = pADs->PutEx(apo, bstrPropname, varArray); hr = pADs->SetInfo(); return hr; int CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); // hr = MimeMap(L"IIS://localhost/MimeMap", NULL, NULL); hr = MimeMap(L"IIS://localhost/w3svc/1/Root", L".foo", L"bar/quux"); CoUninitialize(); return 0; -- -- "C K" < > wrote in message |
|||||
#3 |
|||||
|
|||||
Re: How to add a new MimeType to a Virtual Directory with VC++? Hi George, Thank you very much for the code! I still don't understand why I wasn't able to createinstance an #include <iiis.h> I also linked with: ActiveDS.lib Adsiid.lib The only difference is that you did it the #import way. Is there CComPtr<IISMimeType> pMimeType; which returned that class not registered failure. Would you happen to know why this is? Thanks. "George V. Reilly" < > wrote in message news:<# >... |
|||||
#4 |
|||
|
|||
Re: How to add a new MimeType to a Virtual Directory with VC++? There are no C++ headers that expose IISMimeType. The only way to get the "C K" < > wrote in message |
|||
#5 |
|||
|
|||
Re: How to add a new MimeType to a Virtual Directory with VC++? Hi George, I did some spelunking because it kinda ticked me off I found that #include <atlbase.h> CComPtr<IUnknown> pUnk; hr = pUnk.CoCreateInstance(__uuidof(MimeMap)); But your class is still very nice and handy, thanks "George V. Reilly" < > wrote in message news:<ew1K# >... |
Hi,
I can't seem to figure out how to add a new MimeType to a virtual
directory's MimeMap. The problem is how do I create an IISMimeType
object to add to the MimeMap's SAFEARRAY?
With VB, all you have to do is (Microsoft example):
Const ADS_PROPERTY_UPDATE = 2
'Get the mimemap object.
Set MimeMapObj = GetObject("IIS://LocalHost/MimeMap")
'Get the mappings from the MimeMap property.
aMimeMap = MimeMapObj.GetEx("MimeMap")
i = UBound(aMimeMap) + 1
Redim Preserve aMimeMap(i)
Set aMimeMap(i) = CreateObject("MimeMap")
aMimeMap(i).Extension = ".jnq"
aMimeMap(i).MimeType = "junque/my-junque"
MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", aMimeMap
MimeMapObj.SetInfo
With C++, the problem is that aMimeMap(i) is actually of type
IISMimeType. But since IISMimeType is an abstract base class, how do
I create the new MimeType?
It's not possible to do :