Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
543 views
in Technique[技术] by (71.8m points)

c++ - Use CString in console app when using VS Express

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:ProgramDelade filerSystemadomsado15.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 !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...