Can't cast SQLINTEGER* to SQLLEN* (x64)

I'm calling SQLGetData() to get a field value. This works fine as a 32-bit application, but it's trashing the stack as 64-bit.

The strange thing is that SQLLEN is #defined as SQLINTEGER, so they are one and the same. They are both long types, as it turns out.

unsigned long Field::asUnsignedLong() const
{
unsigned long result;
SQLINTEGER sizeNeeded = 0;

    // Trashes the stack around sizeNeeded...
    if(!SQL_SUCCEEDED(SQLGetData(_statement, _columnIndex, SQL_C_ULONG, &result, sizeof(result), &sizeNeeded)))
    {
        throw std::runtime_error(getError(SQL_HANDLE_STMT, _statement));
    }

    return result;
}

博客了半天,在论坛看到了这么一个答案

The typedef has changed on the 64-bit API. Here's what's causing your stack corruption:

#ifdef _WIN64
typedef INT64 SQLLEN;
typedef UINT64 SQLULEN;
#else
#define SQLLEN SQLINTEGER
#define SQLULEN SQLUINTEGER
#endif

You're passing in a 32-bit integer (SQLINTEGER is typedef'd to long) when it is expecting a 64-bit one

32位的SQLINTEGER需要修改成INT64!!!!

猜你喜欢

转载自blog.csdn.net/qq_37457202/article/details/81261406
今日推荐