_variant_t to CString
-
I (and Microsoft, who wrote the _variant_t and CString code) have helped you - you just assign the _variant_t to the CString - what more do you want?!?!?!?!?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Noooooo - you don't need to bother with that - there's a VariantChangeType function that'll do that for you when you convert a VARIANT to a BSTR. And even more conveniently, the combination of _variant_t extractor operators and CString constructors will do all that for you. A simple assignment of _variant_t to CString is all that's needed...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Nice to know :thumbsup:. What about
_variant_t
containing arrays? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I (and Microsoft, who wrote the _variant_t and CString code) have helped you - you just assign the _variant_t to the CString - what more do you want?!?!?!?!?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
See what happen.
_variant_t vtValue;
vtValue = m_pRset->Fields->GetItem("Bianry")->GetValue();
CString b=vtValue;
output is b = "??4"
when i copy the vtValues at the time of debug then i got values
safearray of UI1 = [20](54 '6',53 '5',52 '4',54 '6',52 '4',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)Any more information if you nedd then i will give you.
-
Thanks for responce.I hava a biray type data in _variant_t. _variant_t v1; v1=(54 '6',53 '5',52 '4',54 '6',52 '4',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0); Can i convert these values in CString or not. Origal values is"65464". Plz help me
What is
v1.vt
value? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
See what happen.
_variant_t vtValue;
vtValue = m_pRset->Fields->GetItem("Bianry")->GetValue();
CString b=vtValue;
output is b = "??4"
when i copy the vtValues at the time of debug then i got values
safearray of UI1 = [20](54 '6',53 '5',52 '4',54 '6',52 '4',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)Any more information if you nedd then i will give you.
As it's an array, VariantChangeType's not going to work. So, I'd suggest the code below. I'm assuming you want to access the non-null characters of the array and make them into a string?
CComSafeArray<char, VT_UI1> sa(V_ARRAY(&v));
CString s;
for(int index=sa.GetLowerBound();index<=sa.GetUpperBound()&&sa[index];++index)
{
s+=sa[index];
}[edit] You'll also need to #include atlsafe.h and oleauto.h [/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Nice to know :thumbsup:. What about
_variant_t
containing arrays? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]CPallini wrote:
What about _variant_t containing arrays?
Use CComSafeArray[^].
_variant_t v;
// Assign a SAFEARRAY value to v
CComSafeArray<char, VT_UI1> sa(V_ARRAY(&v));
// Now we can access the SAFEARRAY using sa.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
As it's an array, VariantChangeType's not going to work. So, I'd suggest the code below. I'm assuming you want to access the non-null characters of the array and make them into a string?
CComSafeArray<char, VT_UI1> sa(V_ARRAY(&v));
CString s;
for(int index=sa.GetLowerBound();index<=sa.GetUpperBound()&&sa[index];++index)
{
s+=sa[index];
}[edit] You'll also need to #include atlsafe.h and oleauto.h [/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi Stuart, What do you think about this VT_UI1 SAFEARRAY to CStringA conversion method?
BSTR b; BstrFromVector(pSA,&b); CStringA s = (LPCSTR)b;
Best Wishes, -David DelauneNew to me - that'll teach me to do what I've told many other people to do and read the documentation :laugh: And of course it'll work with wide CStrings as well.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
As it's an array, VariantChangeType's not going to work. So, I'd suggest the code below. I'm assuming you want to access the non-null characters of the array and make them into a string?
CComSafeArray<char, VT_UI1> sa(V_ARRAY(&v));
CString s;
for(int index=sa.GetLowerBound();index<=sa.GetUpperBound()&&sa[index];++index)
{
s+=sa[index];
}[edit] You'll also need to #include atlsafe.h and oleauto.h [/edit]
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p