今天在做项目的时候,遇到一个非常郁闷的问题,捣鼓了半天,最后在国外的一个论坛上获得了思路,终于把它解决掉,在此给大家分享一下。
我们知道,在C++中用ADO操作数据库,首先需要用#import将ado组件导入进来,然后才能正常使用它。
1 2 3 |
#pragma once #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF", "EndOfFile") using namespace ADODB; |
以下是我原来出错时的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#pragma once #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF", "EndOfFile") using namespace ADODB; #include <wx/wx.h> //////////////////////////// class DB { public: static void Init(); static bool Open(_ConnectionPtr& pConnection,wxString server,wxString database,wxString uid,wxString pwd); static bool Execute(_ConnectionPtr& pConnection,wxString sql); static bool Recordset(_ConnectionPtr& pConnection,_RecordsetPtr& pRecordset,wxString sql); }; |
这个时候的错误提示是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
d:\wxwidgets\include\wx\msw\winundef.h(39) : error C2664: 'CreateDialogParamW' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(70) : error C2664: 'CreateFontW' : cannot convert parameter 14 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(96) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(112) : error C2664: 'LoadMenuW' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(127) : error C2664: 'FindTextW' : cannot convert parameter 1 from 'struct tagFINDREPLACEA *' to 'struct tagFINDREPLACEW *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(318) : error C2664: 'LoadIconW' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\wxwidgets\include\wx\msw\winundef.h(331) : error C2664: 'LoadBitmapW' : cannot convert parameter 2 from 'const char *' to 'const unsigned short *' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast |
一开始以为是wxWidgets的编译配置问题,于是我建立了一个全新的不用到wxWidgets框架的类,编译可以通过。但一旦加上#include <wx/wx.h>引入头文件,就出错。
最后在wxWidgets官方论坛上找到一个帖子,这个同行是用的SQLite数据库,用到的是Poco库,出的错误是一样的。后面解释说是可能是在引入wx.h之前引用到了windows.h,于是恍然大悟,把#include <wx/wx.h>写到文档最前面,问题成功解决!
最后正确的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <wx/wx.h> #pragma once #import "C:\Program Files\Common Files\System\ado\msado15.dll" rename("EOF", "EndOfFile") using namespace ADODB; class DB { public: static void Init(); static bool Open(_ConnectionPtr& pConnection,wxString server,wxString database,wxString uid,wxString pwd); static bool Execute(_ConnectionPtr& pConnection,wxString sql); static bool Recordset(_ConnectionPtr& pConnection,_RecordsetPtr& pRecordset,wxString sql); }; |
郑重声明:
除特别声明为转载内容外,本站所有内容均为作者原创,谢绝任何单位和个人不经许可的复制和转播!
对于确有转载需要的,请先与作者联系,在获得允许后烦请在转载时保留文章出处。
本文出自Lupin's Blog:http://www.cnzui.com/archives/317
除特别声明为转载内容外,本站所有内容均为作者原创,谢绝任何单位和个人不经许可的复制和转播!
对于确有转载需要的,请先与作者联系,在获得允许后烦请在转载时保留文章出处。
本文出自Lupin's Blog:http://www.cnzui.com/archives/317