I have this code that uses the USE_CONVERSION macro in a C++ project...
I was wondering if this is written well, (not written by me), and if there's any better ways to do it, without the USES_CONVERSION and W2A macros.
STDMETHODIMP CInterpreter::GetStringVar(BSTR bstrNamespace, BSTR bstrVar, BSTR *pbstrValue)
{
USES_CONVERSION;
try
{
if (!pbstrValue) return E_POINTER;
char* pszNamespace= W2A(_bstr_t(bstrNamespace).operator wchar_t*());
char* pszVar= W2A(_bstr_t(bstrVar).operator wchar_t*()); // Is this not better done another way????
char pszErrStr[kPYTHONERRBUFSIZE];
char pszStrValue[kPYTHONSTRVALUESIZE];
BOOL bResult= Python_GetStringVar(pszNamespace, pszVar, pszErrStr, pszStrValue, kPYTHONSTRVALUESIZE);
*pbstrValue= _bstr_t(pszStrValue).operator BSTR();
if (!bResult)
throw x::internal_error(A2W(pszErrStr));
return S_OK;
}
}