刚学ADO,编译错误,引入库了,还需要包含什么头文件啊

kangde 2003-05-05 06:53:37
我在stdafx.h文件中这样引入:
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")
然后在程序类中生成一个成员变量:
_ConnectionPtr m_pConnection;
在程序类的InitInstance函数中:
m_pConnection.CreateInstance(Connection);
却出现以下编译错误:
f:\程序学习\mydocument\mydocument.h(26) : error C2146: syntax error : missing ';' before identifier 'm_pConnection'
f:\程序学习\mydocument\mydocument.h(26) : error C2501: '_ConnectionPtr' : missing storage-class or type specifiers
f:\程序学习\mydocument\mydocument.h(26) : error C2501: 'm_pConnection' : missing storage-class or type specifiers
F:\程序学习\MyDocument\MyDocument.cpp(97) : error C2065: 'm_pConnection' : undeclared identifier
F:\程序学习\MyDocument\MyDocument.cpp(97) : error C2228: left of '.CreateInstance' must have class/struct/union type

这个错误是不是因为头文件的问题,如果是的话,还要包含哪个头文件啊
...全文
87 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
kangde 2003-05-05
  • 打赏
  • 举报
回复
to:Virtuoso and chenhz
这样也可以的:AfxOleInit(),就不用在退出的时候关掉了,
谢谢,Skt32,接分
Skt32 2003-05-05
  • 打赏
  • 举报
回复
rebuild all 一下

或者把STDAFX.cpp重编译以下
chenhz 2003-05-05
  • 打赏
  • 举报
回复
你没有在声明_ConnectionPtr指针前加if(FAILED(::CoInitialize(NULL)))
return;
和结束时加::CoUninitialize();
在当然会错啦!
Virtuoso 2003-05-05
  • 打赏
  • 举报
回复
你没有在声明_ConnectionPtr指针前加if(FAILED(::CoInitialize(NULL)))
return;
和结束时加::CoUninitialize();
在当然会错啦!
kangde 2003-05-05
  • 打赏
  • 举报
回复
就在那里啊,我看到例子程序的FileView中有一个External Dependency目录,下面有msado15.dll,我的没有,是不是跟这个有关啊
kangde 2003-05-05
  • 打赏
  • 举报
回复
真是奇怪啊,我在vckbase上下载的例子就能编译成功,为什么我的就不行呢,只是定义了一个变量就出问题,
Skt32 2003-05-05
  • 打赏
  • 举报
回复
c:\program files\common files\system\ado\msado15.dll

这个存在吗?或者在别的地方?
kangde 2003-05-05
  • 打赏
  • 举报
回复
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

// 加入ADO支持库
#import "c:\program files\common files\system\ado\msado15.dll" \
no_namespace \
rename ("EOF", "adoEOF")

以上是我的stdafx.h头文件的部分内容,谢谢,那篇文章我看了,可是现在的问题是在程序类中定义_ConnectionPtr m_pConnection;时,提示不认识_ConnectionPtr标识符,这是怎么回事啊,谢谢你的帮助:)
Skt32 2003-05-05
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc.asp?id=215
Skt32 2003-05-05
  • 打赏
  • 举报
回复
sorry, 不要上面的


stdafx.h如下:


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers


#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#pragma warning(disable:4146)
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF", "adoEOF")

kangde 2003-05-05
  • 打赏
  • 举报
回复
在程序的初始化函数中也加入了AfxOleInit();我的程序是SDI的,请大侠帮忙
kangde 2003-05-05
  • 打赏
  • 举报
回复
不行啊,我在stdafx.h和程序类中包含afxdb.h都不能编译通过,
另外,我的m_pConnection.CreateInstance(Connection);
敲错了,应为:m_pConnection.CreateInstance(__uuidof(Connection));这样也不行
着急啊!!!!!!!
Skt32 2003-05-05
  • 打赏
  • 举报
回复
#include <afxdb.h>

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧