Use CString in console app when using VS Express

大城市里の小女人 提交于 2019-11-28 10:15:37

问题


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 !


回答1:


You could replace CString with CStdString




回答2:


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 :)



来源:https://stackoverflow.com/questions/5760186/use-cstring-in-console-app-when-using-vs-express

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!