Question

In this example m_Amount is CString. stringToNumber function converts it to a LONGLONG number successfully. But when I want to assign it to a variant I get this error:

error C2440: 'type cast' : cannot convert from '__int64' to 'class _variant_t'

mycode

_variant_t  myVar = _variant_t( (LONGLONG)stringToNumber(m_Amount) );
Was it helpful?

Solution 4

I was using _variant_t to insert LONGLONG data into the SQL server database. As mentioned in this asnwer numeric is mapped to CString in C++. So I retrieve my numeric data from database as string, convert it to LONGLONG, change and then convert it to string again and store result string to database.

SQL numeric --(retrieve from database)--> string -> LONGLONG -> string --(insert into the database)--> SQL numeric

OTHER TIPS

You don't need the cast.

Use:

_variant_t(
   __int64 i8Src
)

See _variant_t MSDN for further reference.

Windows CE however does not provide all data types available on a regular Windows XP/Vista/Win 7 installation. In your case, this means that WinCE does not support 64-bit signed/unsigned integers. So, you are best advised to use either a narrower data type or roll your own type (that uses perhaps two ints) to get a LONGLONG.

What toolchain are you using?

There should be a conversion from __int64 to _variant_t if _WIN32_WINNT >= 0x501, which corresponds to a target of at least WinXP. That should be true for up to date Windows toolchains, but you may need to explicitly set that macros definition yourself with some older tools (like VS 2005, I believe).

Try this one:

union UltimateCast
{
   __int64 From;
   __variant_t To;
};

Put the __int64 value you need to cast from into the From field. After that read the resulting value from the To field.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top