_bstr_t class encapsulates the BSTR inside the C ++ class. In the first case:
LPCTSTR asdfsdf = (LPCTSTR)(_bstr_t)v;
you create the _bstr_t object by extracting _bstr_t from it, but then the temporary _bstr_t object is _bstr_t . Regardless of what is specified asdfsdf , is now freed and can no longer be used.
In your second example
printf("%s\n", (LPCTSTR)(_bstr_t)v);
the temporary _bstr_t object _bstr_t not destroyed until printf() is called, so there is no problem using the value of LPCTSTR .
source share