使用 VS Express 时在控制台应用程序中使用 CString
我在尝试使用 CString 时遇到问题。
我有一个使用 VS2010Express 编写的控制台应用程序。我有一段代码想要使用,但它使用 CString。当我尝试包含适当的标头 atlstr.h (据我所知)时,我收到著名的错误:无法打开源文件。 浏览了一段时间后,似乎一般来说应该是可以的,但是 atlstr.h 对 Express 用户不可用。 问题:
1)是这样吗? 2)我能以某种方式避免这个问题吗?
下面是代码,(来源:http://www.cprogramming.com/tutorial/ ado_c++_wrapper_classes.html)
如果有人知道我如何继续使用此代码,无论使用或不使用 CString,请帮我......
#import "C:\Program\Delade filer\System\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace
#include <atlstr.h>
class CADOConnection
{ private:
_ConnectionPtr pConnection;
CString m_szConnectionString;
BOOL Initialize();
public:
void SetConnectionString(CString& szConnectionString);
TCHAR *GetConnectionString(){return m_szConnectionString);
BOOL IsClosed();
BOOL IsOpen();
BOOL Open();
BOOL Open(CString& szConnectionString, CString szUser=_T(""), CString szPassword=_T(""));
BOOL Close();
CADOConnection(CString& szConnectionString);
CADOConnection(void);
~CADOConnection(void);
};
谢谢,复活节快乐!
I have a problem when trying to use CString.
I have a console application written using VS2010Express. I have a piece of code I would like to use, but it uses CString. When I try to include the appropriate header atlstr.h (as far as I know) I get the famous error: Cannot open source file.
After Goggling around for a while it seems that in general it should be possible, but the atlstr.h is not available to Express users.
Questions:
1) Is that right ?
2) Can I avoid this problem somehow?
Below is the code, (origin: http://www.cprogramming.com/tutorial/ado_c++_wrapper_classes.html)
If anyone has an Idea how I can continue using this code, with or without the use of CString, please give me a hand....
#import "C:\Program\Delade filer\System\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace
#include <atlstr.h>
class CADOConnection
{ private:
_ConnectionPtr pConnection;
CString m_szConnectionString;
BOOL Initialize();
public:
void SetConnectionString(CString& szConnectionString);
TCHAR *GetConnectionString(){return m_szConnectionString);
BOOL IsClosed();
BOOL IsOpen();
BOOL Open();
BOOL Open(CString& szConnectionString, CString szUser=_T(""), CString szPassword=_T(""));
BOOL Close();
CADOConnection(CString& szConnectionString);
CADOConnection(void);
~CADOConnection(void);
};
Thank you, and happy Easter !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是正确的(CString 实际上是现已结合的 MFC 和 ATL 的一部分)。
在几乎所有情况下,我发现在其他一些字符串类中翻译 CString 的使用都很简单(想到了 std::string),
我不太确定是否导入类型库(#import)不过,VSExpress 完全支持。可能是 - 因为 COM 是二进制标准并且 MIDL 可以生成纯 C 头文件...但仍然:)
Yes it is right (CString is actually part of now-wedded MFC and ATL).
In almost all circumstances I found it trivial to translate the use of CString in som other string class (std::string comes to mind)
I'm not so sure whether the importing of typelibraries (#import) is fully supported in VSExpress, though. It could be - since COM is a binary standard and MIDL can generate pure C header files... but still :)
您可以将 CString 替换为 CStdString
You could replace CString with CStdString