Conversion between QString and BSTR
why not use the toWcharArray?

BSTR ExcelClass::qstringToBstr(const QString &amp;qstring) const
{
        WCHAR* const pBuffer = new WCHAR[qstring.size()+1]; //large enough to hold the string plus null terminator
        qstring.toWCharArray(pBuffer);
        pBuffer[qstring.size()]=0;//terminate with 0
        BSTR result = SysAllocString(pBuffer);
        delete [] pBuffer;
        return result;
}


or simply preallocate result with SysAllocStringLen(&amp;result, qstring.length()); and translate into that

BSTR ExcelClass::qstringToBstr(const QString &amp;qstring) const
{            
        BSTR result= SysAllocStringLen(0, qstring.length());
        qstring.toWCharArray(result);
        return result;
}