Use CString in console app when using VS Express

2019-01-29 02:08发布

问题:

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



标签: c++ atl wtl