Any idea how to convert a CComVarint to a CString? Thx. 
Author Message
 Any idea how to convert a CComVarint to a CString? Thx.



Wed, 22 Sep 2004 02:07:45 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
Seems works:

CComVariant var = L"Sample String";
TCHAR buff[1024] = {0};
 wcsncpy(buff, V_BSTR(&var), 1024);
CString string(buff);

But the problem is I have to use a buff[1024], which I really have no
idea if the buff is huge enough, otherwise, you might suggest me to
use dynamical allocation, God! I hate that, is there any simpler means?




Wed, 22 Sep 2004 02:27:19 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
// Function name : V2S
// Description     : Converts a VARIANT to a string
// Return type  : static tstring
// Argument         :  VARIANT* pv
// Argument         : LPCTSTR szDefault = _T(""
static tstring V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
 if ( pv )
 {
  if ( pv->vt == VT_ERROR )
   return szDefault;

  CComVariant vt;
  if ( SUCCEEDED( vt.ChangeType( VT_BSTR, pv ) ) )
  {
   USES_CONVERSION;
   return OLE2T(V_BSTR( &vt ));
  }
 }
 return szDefault;

Quote:
}

Mike

Quote:
> Seems works:

> CComVariant var = L"Sample String";
> TCHAR buff[1024] = {0};
>  wcsncpy(buff, V_BSTR(&var), 1024);
> CString string(buff);

> But the problem is I have to use a buff[1024], which I really have no
> idea if the buff is huge enough, otherwise, you might suggest me to
> use dynamical allocation, God! I hate that, is there any simpler means?






Tue, 21 Sep 2004 14:33:35 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
CString string = V_BSTR(&var);

--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Seems works:

> CComVariant var = L"Sample String";
> TCHAR buff[1024] = {0};
>  wcsncpy(buff, V_BSTR(&var), 1024);
> CString string(buff);

> But the problem is I have to use a buff[1024], which I really have no
> idea if the buff is huge enough, otherwise, you might suggest me to
> use dynamical allocation, God! I hate that, is there any simpler
means?






Wed, 22 Sep 2004 02:08:18 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
That's not the best way to do it.

Try your line of code using this:)  CComVariant vt((long)1);

Mike


Quote:
> CString string = V_BSTR(&var);

> --
> With best wishes,
>     Igor Tandetnik

> "For every complex problem, there is a solution that is simple, neat,
> and wrong." H.L. Mencken



> > Seems works:

> > CComVariant var = L"Sample String";
> > TCHAR buff[1024] = {0};
> >  wcsncpy(buff, V_BSTR(&var), 1024);
> > CString string(buff);

> > But the problem is I have to use a buff[1024], which I really have no
> > idea if the buff is huge enough, otherwise, you might suggest me to
> > use dynamical allocation, God! I hate that, is there any simpler
> means?






Tue, 21 Sep 2004 16:06:11 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
Yes, sure, my example assumes one already knows the variant holds a
string. I should have added that error checking is omitted for
simplicity.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> That's not the best way to do it.

> Try your line of code using this:)  CComVariant vt((long)1);

> Mike



> > CString string = V_BSTR(&var);

> > --
> > With best wishes,
> >     Igor Tandetnik

> > "For every complex problem, there is a solution that is simple,
neat,
> > and wrong." H.L. Mencken



> > > Seems works:

> > > CComVariant var = L"Sample String";
> > > TCHAR buff[1024] = {0};
> > >  wcsncpy(buff, V_BSTR(&var), 1024);
> > > CString string(buff);

> > > But the problem is I have to use a buff[1024], which I really have
no
> > > idea if the buff is huge enough, otherwise, you might suggest me
to
> > > use dynamical allocation, God! I hate that, is there any simpler
> > means?






Wed, 22 Sep 2004 03:26:11 GMT  
 Any idea how to convert a CComVarint to a CString? Thx.
Thank you all a lot. I really appreciate that.




Thu, 23 Sep 2004 03:44:51 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Newbie: Howto convert char variable __gc into CString?

2. CString problems in converting from Vcp6 to Vcp7

3. how to convert constant char to Cstring?

4. Convert COleVariant to CString (or anything for that matter)

5. Converting CString to COleVariant,etc..

6. How to convert CString into TCHAR*

7. Converting CString to BSTR

8. HOW to Convert BSTR Type to CString type

9. Error in convert from bstr to CString

10. Converting BSTR to CString

11. Convert BSTR to CString and VV

12. Convert an int or double to CString?

 

 
Powered by phpBB® Forum Software