first:
LPCTSTR asdfsdf = (LPCTSTR)(_bstr_t)v;
printf("%s\n", asdfsdf);
second:
printf("%s\n", (LPCTSTR)(_bstr_t)v);
they are the same, but the first condition causes unreadable code
why?
The _bstr_t class encapsulates a BSTR inside a C++ class. In your first instance:
LPCTSTR asdfsdf = (LPCTSTR)(_bstr_t)v;
you are creating a _bstr_t object, extracting the LPCTSTR out of it, but then the temporary _bstr_t object gets destructed. Whatever asdfsdf pointed to is now deallocated and can no longer be used.
In your second example
printf("%s\n", (LPCTSTR)(_bstr_t)v);
the temporary _bstr_t object is not destructed until after the printf() is called, so there is no problem using the LPCTSTR value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With