我先在stdafx.h中用#import引入ADO库文件 
#import "c:\program files\common files\system\ado\msado15.dll"no_namespaces rename("EOF" adoEOF")
(msdao15.dll文件在上述目录路径下)
然后在我的应用程序主类的InitInstance成员函数里初始化OLE/COM库环境
BOOL CCPIMApp::InitInstance()
{
AfxEnableControlContainer();
if(!AfxOleInit())
{
AfxMessageBox("OLE初始化失败");
return FALSE;
}
        ...
}
在程序目录下也生成了msdao15.tli,msdao15.tlh文件
但是在声明以下变量时 _ConnectionPtr m_pConnection;
           _RecordsetPtr m_pRecordset;
编译通不过,错误如下:
error C2501: '_RecordsetPtr' : missing storage-class or type specifiers
error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
折腾了很长时间,希望各路大虾给看看,可有解决的法子
谢谢!

解决方案 »

  1.   

    把#import "c:\program files\common files\system\ado\msado15.dll"no_namespaces rename("EOF" adoEOF") 
    放在stdafx.h中 所有#include的语句后面才可以
      

  2.   

    #import "C:\program Files\Common Files\System\ado\msado15.dll" no_namespace \
    rename("EOF","adoEOF")rename("BOF","adoBOF")这样试试。
      

  3.   

    要还不行就分两行写:第一行:(后面的"\"紧贴着no_namespace)
    #import "C:\program Files\Common Files\System\ado\msado15.dll" no_namespace\
    第二行:(前面两个Tab键)
    rename("EOF","adoEOF")rename("BOF","adoBOF") 
      

  4.   

    把我的代码复制进去也不行?第二行加两个tab键没?要不你自己写一个数据库连接的类吧,别在stdafx.h中用#import引入ADO库文件。
      

  5.   

    按你说的新建了一个类,在这个类的头文件中用#import引入ADO库文件通过
    多谢!