We are developing 32 bit Automation components using VB 5.0 and MFC ClassWizard. On our components we have several accessor methods that manipulate a CString and then return a BSTR back to the consumer by using the AllocSysString() method:
// get the string
aBSTRString = anObject->getSomeString()
// do something with it, like convert back to a CString
strResult = CString(aString);
// Free the BSTR... Is this necessary?
BoundsChecker flags an error indicating the SysFreeString is freeing memory in a bad address location.
The MSDN indicates that you should use ::SysFreeString in the rare case that you need to deallocate the returned string. Should we not be using this function on BSTR's converted from CStrings using the CString::AllocSysString method?