询问者
vc6 转换到cs2010出错

问题
-
//stdafx.h里面已经包含了代码 #import "c:\program files\common files\system\ole db\oledb32.dll"
void CADODateGridView::OnSource() //选择数据源
{
// TODO: Add your control notification handler code here
HRESULT hr;
IDataSourceLocatorPtr m_slocator=NULL;//DataSourceLocator对象指针 error: C2065: 'IDataSourceLocatorPtr' : undeclared identifier
全部回复
-
你好,
您可以尝试使用以下引用语句
#import "c:\program
files\common files\system\ole db\oledb32.dll"
rename_namespace("dlinks")#import "c:\program
files\common files\system\ado\msado15.dll"
rename_namespace("ado")Rob Pan [MSFT]
MSDN Community Support | Feedback to us
-
用了楼上的办法,以前错误没有了,出现新的错误:
1>c:\cprogram\xuan_gu\debug\msado15.tlh(3174): error C2059: syntax error : '<L_TYPE_raw>'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(3174): error C2238: unexpected token(s) preceding ';'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(4247): error C2059: syntax error : '<L_TYPE_raw>'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(4247): error C2238: unexpected token(s) preceding ';'指向的代码为:
VARIANT_BOOL EOF;
-
一、_WIN32_WINNT 与 _WIN32_IE 设置冲突
_WIN32_WINNT 与 _WIN32_IE设置不兼容会导致如下C1189致命错误:
StdAfx.cpp
c:/program files/microsoft sdks/windows/v6.0a/include/sdkddkver.h(217) : fatal error C1189: #error : _WIN32_WINNT settings conflicts with _WIN32_IE setting
StdAfx.cpp通常是项目中第一个编译的文件,这个错误将导致编译无法继续进行。产生这个错误的原因是原因是_WIN32_WINNT的版本定义太老,老的VC代码对_WIN32_WINNT的典型设置是:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
0x0400相对于VS2008所带的Plarform SDK(在文件sdkddkver.h中)中_WIN32_IE的定义来说太老了,导致不兼容,可以将其改成0x0501或更高的版本避免这个问题,如下所示:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
也可以将这三行_WIN32_WINNT定义删除,这样就会使用Plarform SDK中的_WIN32_WINNT定义,自然就不存在不兼容问题了。不过出于对老版本VC的兼容考虑(毕竟以后可能还要使用VC6编译代码),最好这样修改:
#if _MSC_VER <= 1200 // MFC 6.0 or earlier
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#endif
二、afximpl.h文件中的语法错误
MFC出现的时候STL还没有成为C++的标准,所以MFC使用一套自己的模版库,比如CArray、CList、CMap等等,这些类型声明都在afximpl.h文件中。原来在VC6编译器适用的模版语法可能不适用VC9,特别是当以下四个环境变量设置不兼容时,就会出现这个编译错误,大致情况如下:
e:/software/microsoft visual studio 9.0/vc/atlmfc/src/mfc/afximpl.h(625) : error C2059: syntax error : '<L_TYPE_raw>'
e:/software/microsoft visual studio 9.0/vc/atlmfc/src/mfc/afximpl.h(625) : error C2238: unexpected token(s) preceding ';'
e:/software/microsoft visual studio 9.0/vc/atlmfc/src/mfc/afximpl.h(629) : error C2059: syntax error : '<L_TYPE_raw>'
e:/software/microsoft visual studio 9.0/vc/atlmfc/src/mfc/afximpl.h(629) : error C2238: unexpected token(s) preceding ';'
合理调整stdafx.h中WINVER、_WIN32_WINNT、_WIN32_WINDOWS和_WIN32_IE的设置可以避免这个问题,将三个与Windows版本有关的环境变量设置为0x0501或更高版本,将IE版本的环境变量设置为0x0500以后的版本就可以解决这个问题。当然,考虑到与旧的VC6代码兼容,可以采用上一个问题中提到的最后一个解决办法,用_MSC_VER进行隔离。
麻烦把正确答案设为解答。
-
你好,
您能为我们提供更多有带您错误的信息吗? 例如您可以在这里展示您的部分代码,或者可以向我们提供您引用头文件的信息。这样能够更好的帮助我们理解并解决您的问题。
Rob Pan [MSFT]
MSDN Community Support | Feedback to us
-
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#import "c:\program files\common files\system\ole db\oledb32.dll" rename_namespace("dlinks")
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename_namespace("ado") -
adodategridview.h:
#include "datagrid.h"
//}}AFX_INCLUDES#if !defined(AFX_ADODATEGRIDVIEW_H__8C996179_73C2_4A01_BE0A_3A84DD89FBE2__INCLUDED_)
#define AFX_ADODATEGRIDVIEW_H__8C996179_73C2_4A01_BE0A_3A84DD89FBE2__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000....
-
datagrid.h:
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++// NOTE: Do not modify the contents of this file. If this class is regenerated by
// Microsoft Visual C++, your modifications will be overwritten.
// Dispatch interfaces referenced by this interface
class COleFont;
class CStdDataFormatsDisp;
class CPicture;
class CColumns;
class CSelBookmarks;
class CSplits;/////////////////////////////////////////////////////////////////////////////
// CDataGrid wrapper classclass CDataGrid : public CWnd
{
protected:
DECLARE_DYNCREATE(CDataGrid) -
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename_namespace("ado")
#import "c:\program files\common files\system\ole db\oledb32.dll" rename_namespace("dlinks")可以这样吗?
-
我如果这么写:
#import "c:\program files\common files\system\ole db\oledb32.dll" rename_namespace("dlinks")
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")就会下面警告:
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2065: 'IDataSourceLocatorPtr' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2146: syntax error : missing ';' before identifier 'm_slocator'
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2065: 'm_slocator' : undeclared identifier如果这么写:
#import "c:\program files\common files\system\ole db\oledb32.dll" rename_namespace("dlinks")
#import "C:\program files\common files\system\ado\msado15.dll" no_namespace rename_namespace("ado")1>c:\cprogram\xuan_gu\debug\msado15.tlh(3174): error C2059: syntax error : '<L_TYPE_raw>'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(3174): error C2238: unexpected token(s) preceding ';'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(4247): error C2059: syntax error : '<L_TYPE_raw>'
1>c:\cprogram\xuan_gu\debug\msado15.tlh(4247): error C2238: unexpected token(s) preceding ';'就会下面警告: -
你好,
我建议您可以参考以下文章来使用ADO 建立数据库连接:http://support.microsoft.com/kb/310084
Rob Pan [MSFT]
MSDN Community Support | Feedback to us
-
按照楼上的链接:http://support.microsoft.com/kb/310084 改成下面的形式:
#undef EOF
#import "c:\program files\common files\system\ole db\oledb32.dll" rename_namespace("dlinks")
#import "c:\program files\common files\system\ado\msado15.dll" rename_namespace("ado")结果出现下面的错误:
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C2146: syntax error : missing ';' before identifier 'm_Connection'
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C2146: syntax error : missing ';' before identifier 'm_Recordset'
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2065: 'IDataSourceLocatorPtr' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2146: syntax error : missing ';' before identifier 'm_slocator'
1>c:\cprogram\xuan_gu\adodategridview.cpp(142): error C2065: 'm_slocator' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(143): error C2065: '_ConnectionPtr' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(143): error C2146: syntax error : missing ';' before identifier 'm_Conn'
1>c:\cprogram\xuan_gu\adodategridview.cpp(143): error C2065: 'm_Conn' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(160): error C2065: 'm_Connection' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(160): error C2228: left of '.CreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\cprogram\xuan_gu\adodategridview.cpp(161): error C2065: 'm_Connection' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(161): error C2227: left of '->Open' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\cprogram\xuan_gu\adodategridview.cpp(176): error C2065: 'm_Recordset' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(176): error C2228: left of '.CreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>c:\cprogram\xuan_gu\adodategridview.cpp(176): error C2065: 'Recordset' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(178): error C2065: 'm_Recordset' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(178): error C2065: 'm_Connection' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(178): error C2227: left of '->OpenSchema' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\cprogram\xuan_gu\adodategridview.cpp(178): error C2065: 'adSchemaTables' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(179): error C2065: 'm_Recordset' : undeclared identifier
1>c:\cprogram\xuan_gu\adodategridview.cpp(179): error C2227: left of '->adoEOF' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>c:\cprogram\xuan_gu\adodategridview.cpp(179): fatal error C1903: unable to recover from previous error(s); stopping compilation
1> ADODateGridDoc.cpp
1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1> ADODateGrid.cpp
1> _WIN32_WINNT not defined. Defaulting to _WIN32_WINNT_MAXVER (see WinSDKVer.h)
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C2146: syntax error : missing ';' before identifier 'm_Connection'
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(33): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C2146: syntax error : missing ';' before identifier 'm_Recordset'
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\cprogram\xuan_gu\adodategridview.h(34): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
- 已编辑 Honny_yeyh 2012年2月20日 12:22
-
我是用的vs2010,用vc6没有问题
要不在vc6 + xp下编译,在win7里面运行,不知道要做哪些改变?- 已编辑 Honny_yeyh 2012年2月28日 3:37