Posted on 2008-08-20 10:58
黄超 阅读(1025)
评论(0) 编辑 收藏 引用
VC的DLL编程中使用ado,当导入ADO库时,发生错误,如下所示:
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
出现:
Compiling resources...
Compiling...
StdAfx.cpp
F:\source\vc\Query\debug\msado15.tlh(169) : error C2011: 'LockTypeEnum' : 'enum' type redefinition
F:\source\vc\Query\debug\msado15.tlh(212) : error C2011: 'DataTypeEnum' : 'enum' type redefinition
F:\source\vc\Query\debug\msado15.tlh(256) : error C2011: 'FieldAttributeEnum' : 'enum' type redefinition
F:\source\vc\Query\debug\msado15.tlh(277) : error C2011: 'EditModeEnum' : 'enum' type redefinition
F:\source\vc\Query\debug\msado15.tlh(285) : error C2011: 'RecordStatusEnum' : 'enum' type redefinition
F:\source\vc\Query\debug\msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigned
F:\source\vc\Query\debug\msado15.tlh(527) : error C2011: 'ParameterDirectionEnum' : 'enum' type redefinition
Error executing cl.exe.
ADIDllTest.dll - 6 error(s), 1 warning(s)
可以由下面两种办法来解决这个问题
1)
#pragma warning(disable:4146)
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" named_guids rename("EOF","adoEOF"), rename("BOF","adoBOF")
#pragma warning(default:4146)
using namespace ADODB;
2)
#pragma warning(disable:4146)
#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
no_namespace \
rename("EOF","adoEOF") rename("DataTypeEnum","adoDataTypeEnum") \
rename("FieldAttributeEnum", "adoFielAttributeEnum") rename("EditModeEnum", "adoEditModeEnum") \
rename("LockTypeEnum", "adoLockTypeEnum") rename("RecordStatusEnum", "adoRecordStatusEnum") \
rename("ParameterDirectionEnum", "adoParameterDirectionEnum")
相对来说,还是第一种方法显得更加简便。