|
Hi All
How can i convert _variant_t to CString?
|
|
|
|
|
I suppose you need the string representation of the _variant_t value.
You've to properly format a CString object, depending on the value of the vt member of the encapsulated VARIANT struct. For instance
CString str;
_variant_t v1;
v1 = 0.53;
switch (v1.vt)
{
case VT_R8:
str.Format(_T("%g"), v1.dblVal);
break;
}
MessageBox(str, _T("Variant 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]
|
|
|
|
|
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 .
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;
CComSafeArray<char, VT_UI1> sa(V_ARRAY(&v));
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
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]
|
|
|
|
|
In VS2008, this should do the job...
_variant_t v;
CString s = v;
CString has assignment operator and constructor overl;oads that take a const VARIANT& . _variant_t has an extrractor that returns a VARIANT .
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
|
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.
|
|
|
|
|
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 Delaune
|
|
|
|
|
New to me - that'll teach me to do what I've told many other people to do and read the documentation
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
|
|
|
|
|
thanks it's working for me.
|
|
|
|
|
Hi rdop,
The following snippit will work on all Microsoft compilers:
_variant_t v;
v = 3.141;
::VariantChangeType(&v, &v, 0, VT_BSTR);
CString s = (LPTSTR)(_bstr_t)v.bstrVal;
Best Wishes,
-David Delaune
|
|
|
|
|
Hi vc++ programmers,
I am migrating my project from vs-2003 to vs-2008...I am getting bolow linking error when i am building my project.
errorfwstsrv.obj : error LNK2019: unresolved external symbol "public: int __thiscall DomIssuerInfo::HasSurvFeeBillableDebt(class DblDateTime const &,class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > > const &)
I have set the linker settings.When i am saying project Settings->linker->General->Use library dependencies:YES,i am getting above error.. If i say NO i am getting the corresponding library also added with the above error.I have set all my libraries through linker settings...but notknow why i am getting....................please give some remeby to this.... thanks in advance........
|
|
|
|
|
CString changed between VS2003 and VS2008 - have the libraries been recompiled with VS2008?
Presuming you know which library that function should be defined in, you could use Dependency Walker to check if the library does actually export that function.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
HI Thankyou for your reply,I have recompiled again and again...my project is working in release mode.But when comes to debug mode it is giving linking errors(362) of the same type.....
And i have also tried to giv the library paths through #pragma comment(lib,"..."),,,but i am not exactly getting where should i include this pragma directive.....
can you further help?
modified on Tuesday, September 15, 2009 7:04 AM
|
|
|
|
|
OK - you sdee where you said 'I have set the linker settings.' in your first settings - you realise that Release and Debug modes have different settings?
Vetukuri Raju wrote: And i have also tried to giv the library paths through #pragma comment(lib,"...")
You can put it any where - I usually put the #pragma right after the #include that brings in that library's header file.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
No,,,i dinnt find any major differences.....out of 10 libraries it is anable to link three libraries...
My application is succesfully working on vs-2003....i have compared with 2003 debug setting also....
|
|
|
|
|
Ok,well i needed to write a program to display all alphabets,ie A to Z and i got a question(s) to ask.
The program i wrote is as follow :
#include<iostream>
using namespace std;
int main()
{
char letter='A';
while(letter<='Z')
{
cout<<letter;
letter++;
}
return 0;
}
1) The part where i bold-ed, why is there a need to put in the sign '...'?I tried running it without the '...' sign but the program won't run. It says its undeclared.
2)From (1),whats the difference if i put ".." instead of '...'?
3)If i were to declare something of type int,say "count=1".Why will the program run with count=1 and NOT run if i put count='1'.(see (4)where i put a '...' sign before and after the 0/26 after count)
4)If i were to modify my program into the following :
#include<iostream>
using namespace std;
int main()
{
char letter='A',count='0';
while(count<='26')
{
cout<<letter;
letter++;
count++;
}
return 0;
}
the whole program keeps running and i need to restart my laptop as the compiler somehow stuck. Why?
Thanks for answering.
|
|
|
|
|
UKM_Student wrote: he part where i bold-ed, why is there a need to put in the sign '...'?
Because that's (with one letter inside the quotes) the syntax for character constant s, see [^].
UKM_Student wrote: I tried running it without the '...' sign but the program won't run. It says its undeclared.
That's fine: without the quotes, A is no more a character constant , but instead an undeclared identifier .
UKM_Student wrote: 2)From (1),whats the difference if i put ".." instead of '...'?
Double quotes are used for string literals [^].
UKM_Student wrote: 3)If i were to declare something of type int,say "count=1".Why will the program run with count=1 and NOT run if i put count='1'.(see (4)where i put a '...' sign before and after the 0/26 after count)
The program will run in both cases, generating, of course, different outputs.
UKM_Student wrote: 4)If i were to modify my program into the following :
#include<iostream>
using namespace std;
int main()
{
char letter='A',count='0';
while(count<='26')
{
cout<<letter;
letter++;
count++;
}
return 0;
}<="" blockquote="">
Typing nearly random statements inside the IDE maybe amusing, I guess...
I strongly suggest you read a good C/C++ tutorial.
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]
|
|
|
|
|
What do u mean by IDE?
And regarding part 3, when i put count='1',the whole compiler runs it and gets stuck O_O,need to restart :X
|
|
|
|
|
UKM_Student wrote: What do u mean by IDE?
The same thing quite a lot of people mean too, I suppose [^].
(Should I say 'editor '?)
UKM_Student wrote: And regarding part 3, when i put count='1',the whole compiler runs it and gets stuck O_O,need to restart :X
The compiler runs and compiles the program. At the end you've an executable that, in turn, runs badly (make you restarting the computer). When a program hangs a system, it is, of course running, and producing (pretty noticeable) output.
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]
|
|
|
|
|