Prorblem assigning _variant_t to _bstr when _variant_t is an integer



Hi,

I have a problem with a simple sql program I alm writing. The code
below fails on the line else b = tvar.bstrVal when the variant contains
an integer (i.e. it has collected an integer from a query). It works
fine when it contains any other sql type.

code:

while(!pRecset->EndOfFile){

for(long l = 0; l < c; l++){
tvar = pRecset->Fields->GetItem(l)->Value;

if(tvar.vt == VT_NULL) b = "";
else b = tvar.bstrVal;
std::cout << b;
}

It fails in this function:

inline _bstr_t::Data_t::Data_t(const wchar_t* s)
: m_str(NULL), m_RefCount(1)
{
m_wstr = ::SysAllocString(s); // <--- it fails here

if (m_wstr == NULL && s != NULL) {
_com_issue_error(E_OUTOFMEMORY);
}
}


Somehow it seems like it is unable to assign the variant to the bstr
when the variant is an integer. I am sure I have written code that has
worked with integer in the past.

Can anyone help?

Please let me know if this is not the appropriate forum to post this.

Thanks and regards
Karl Nilsson

.



Relevant Pages

  • Re: COM Interop problem with variants holding object references
    ... discovered that my code works fine in C# but fails in VB.NET. ... calling from VB6 into a .NET component and passing Variant parameters ByRef ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Addpolyline function
    ... The code also fails. ... The main point is VB should be able to convert variable types on the fly ... array as variant, the coordinates are dimmed as integer, which might be why ... the AddPolyline code fails. ...
    (microsoft.public.excel.programming)
  • Re: [PATCH 01/32] Add an ERR_CAST() macro to complement ERR_PTR and co. [try #2]
    ... One like one variant, another like another variant. ... Both fails to say why. ... More majordomo info at http://vger.kernel.org/majordomo-info.html ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)