64 位迁移问题:指针更改
64-bit migration issue: pointer change
我正在使用 A Lightweight C++ Wrapper for Microsoft's ODBC API by Ernesto Guisado, although couldn't download source file from DDJ, I managed to find a copy on github。
我可以在 win32 中使用当前代码进行编译,但在 x64 中编译会出错
error C2664: 'SQLRETURN SQLDescribeCol(SQLHSTMT,SQLUSMALLINT,SQLCHAR *,SQLSMALLINT,SQLSMALLINT *,SQLSMALLINT *,SQLULEN *,SQLSMALLINT *,SQLSMALLINT *)' :
cannot convert argument 7 from 'ULONG *' to 'SQLULEN *'
,基本上不能把一个ULONG *
(ULONG
是32位)赋值给SQLULEN *
(SQLULEN
是64位)。
如何从ULONG顺利升级到64位版本?
代码期望一个类型等同于另一个可能不同的类型,这是一种不好的做法。
为了保持 class 界面完整,您应该将函数更改为如下内容:
void SqlStatement::DescribeCol(USHORT number, UCHAR *name,
USHORT BufferLength, SHORT *NameLength,
SHORT *DataType, ULONG *ColumnSize,
SHORT *DecimalDigits, SHORT *Nullable)
{
SQLULEN tmpColumnSize; // store column size before converting to ULONG
assert(IsValid());
CheckStatus(::SQLDescribeCol(m_hstmt, number, name,
BufferLength, NameLength,
DataType, &tmpColumnSize,
DecimalDigits, Nullable));
if(ColumnSize) *ColumnSize = (ULONG)tmpColumnSize;
}
如果class接口无所谓,你也可以把函数中的ULONG换成SQLULEN
我正在使用 A Lightweight C++ Wrapper for Microsoft's ODBC API by Ernesto Guisado, although couldn't download source file from DDJ, I managed to find a copy on github。
我可以在 win32 中使用当前代码进行编译,但在 x64 中编译会出错
error C2664: 'SQLRETURN SQLDescribeCol(SQLHSTMT,SQLUSMALLINT,SQLCHAR *,SQLSMALLINT,SQLSMALLINT *,SQLSMALLINT *,SQLULEN *,SQLSMALLINT *,SQLSMALLINT *)' :
cannot convert argument 7 from 'ULONG *' to 'SQLULEN *'
,基本上不能把一个ULONG *
(ULONG
是32位)赋值给SQLULEN *
(SQLULEN
是64位)。
如何从ULONG顺利升级到64位版本?
代码期望一个类型等同于另一个可能不同的类型,这是一种不好的做法。
为了保持 class 界面完整,您应该将函数更改为如下内容:
void SqlStatement::DescribeCol(USHORT number, UCHAR *name,
USHORT BufferLength, SHORT *NameLength,
SHORT *DataType, ULONG *ColumnSize,
SHORT *DecimalDigits, SHORT *Nullable)
{
SQLULEN tmpColumnSize; // store column size before converting to ULONG
assert(IsValid());
CheckStatus(::SQLDescribeCol(m_hstmt, number, name,
BufferLength, NameLength,
DataType, &tmpColumnSize,
DecimalDigits, Nullable));
if(ColumnSize) *ColumnSize = (ULONG)tmpColumnSize;
}
如果class接口无所谓,你也可以把函数中的ULONG换成SQLULEN