convert Variant to CString?
-
hiho@ll i have to convert a string from Variant to CString (or LPCTSTR) i read some articles about bstr conversion, but doesn't seem to work 1. i have a variant variable 2. i want to use MessageBox to show the Variant-String how do i do this? some code would be perfect thx
-
hiho@ll i have to convert a string from Variant to CString (or LPCTSTR) i read some articles about bstr conversion, but doesn't seem to work 1. i have a variant variable 2. i want to use MessageBox to show the Variant-String how do i do this? some code would be perfect thx
I'll help with the conversion (I'm sure you can handle the MessageBox!)
CString GetString(const VARIANT* pvaData) { if (pvaData->vt == VT_BSTR) return pvaData->bstrVal; if (pvaData->vt == (VT_BSTR | VT_BYREF)) return *pvaData->pbstrVal; if (pvaData->vt == (VT_VARIANT | VT_BYREF)) return GetString(pvaData->pvarVal); VARIANT varDest; VariantInit(&varDest); if (SUCCEEDED(VariantChangeTypeEx(&varDest, (VARIANT*) pvaData, LOCALE_SYSTEM_DEFAULT, 0, VT_BSTR))) return GetString(&varDest); return _T(""); }
-
hiho@ll i have to convert a string from Variant to CString (or LPCTSTR) i read some articles about bstr conversion, but doesn't seem to work 1. i have a variant variable 2. i want to use MessageBox to show the Variant-String how do i do this? some code would be perfect thx
-
wow cool thx to both of you
-
hiho@ll i have to convert a string from Variant to CString (or LPCTSTR) i read some articles about bstr conversion, but doesn't seem to work 1. i have a variant variable 2. i want to use MessageBox to show the Variant-String how do i do this? some code would be perfect thx
-
hiho@ll i have to convert a string from Variant to CString (or LPCTSTR) i read some articles about bstr conversion, but doesn't seem to work 1. i have a variant variable 2. i want to use MessageBox to show the Variant-String how do i do this? some code would be perfect thx
If you know that the
VARIANT
contains aBSTR
you can get theBSTR
, which is really a special form of a wide-character string, and pass it to the wide-character version ofMessageBox
:MessageBoxW( hWndParent, vtMyVariant.bstrVal, L"The Caption", ( MB_ICONINFORMATION | MB_OK ) )
(You could also pass in a dereferenced
pbstrVal
.) Peace! -=- James
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Tip for new SUV drivers: Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
DeleteFXPFiles & CheckFavorites (Please rate this post!)