前段时间在用MFC连接数据库做作业,在动态连接msado15.dll时有时会出现下面问题,然后改来改去,还是有时能运行,有时出问题。自己总结了一下自己的错误,在此和大家分享下。
1、导入ADO动态连接库方法:
在工程的stdafx.h中加入如下语句
#import "c:\program files\commonfiles\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
上述语句写在同一行,用空格把四部分分割开。
或是如下所示用“\”来换行连接,
#import "c:\program files\commonfiles\system\ado\msado15.dll" \
no_namespace\
rename("EOF","adoEOF")
2、错误
换行书写时,编译器有时会报如下的错误:
--------------------Configuration: LessonSet - Win32 Debug--------------------
Compilingresources...
Compiling...
StdAfx.cpp
c:\users\1\desktop\lessonset\lessonset\stdafx.h(25): warning C4185: ignoring unknown #import attribute'no_namespacerename'
c:\users\1\desktop\lessonset\lessonset\debug\msado15.tlh(481): warning C4146: unary minus operator applied to unsignedtype, result still unsigned
c:\users\1\desktop\lessonset\lessonset\debug\msado15.tlh(1390): error C2629: unexpected 'short ('
c:\users\1\desktop\lessonset\lessonset\debug\msado15.tlh(1390): error C2238: unexpected token(s) preceding ';'
c:\users\1\desktop\lessonset\lessonset\debug\msado15.tlh(3417): error C2629: unexpected 'short ('
c:\users\1\desktop\lessonset\lessonset\debug\msado15.tlh(3417): error C2238: unexpected token(s) preceding ';'
开始遇到这种错误时特别的令人头疼的。程序本是可以运行,但是拷贝到其他文件下就出问题,报上述错误,尤其是在VC6.0编译器中。我认为错误原因是“\”后的空格我们忽略了,忘了写上,然后就把“no_namespace”和“rename("EOF","adoEOF")”连到了一起,引起错误。
我的解决方法是:
1、把项目Debug里的内容全部删除,把语句写到同一行去,然后重新组建工程,这样就可以对msado15.dll重新引用
2、在换行书写时,在“no_namespace”前加上空格,同时在“rename”前也加上空格,避免“no_namespace”和“rename("EOF","adoEOF")”连到一起
这是遇到的问题后自己的解决方法,希望对也遇到这种问题的朋友有个帮助,也希望大家对这种问题有更好的解释。