Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Could you please, any one tell me which header file I have to include being able to use CString in VC++ 6.0? Win32 DLL. I have looking on the net and I can't find one that works. One suggests to use AFX.h, another suggest us #include <stdafx.h> but my project already have #include <stdafx.h> and it also having #include <windows.h>, and I also tried #include "fstream.h" ; However still I am getting compilation error as
error C2061: syntax error : identifier 'CString'
error C2065: 'CString' : undeclared identifier

Thank you.

[edit]Spurious code blocks removed - OriginalGriff[/edit]
Posted
Updated 18-May-11 23:16pm
v2
Comments
Richard MacCutchan 19-May-11 5:17am    
CString is part of ATL/MFC; is this an ATL/MFC project, and do you have the support libraries installed?
drcool23 19-May-11 5:38am    
Yes, This is MFC project. CString is working in another module. There I have seen that extra header file which they used is #include "fstream.h". Please let me know what would be the solution. This project is VC++ 6.0? Win32 DLL.

I think you are not using MFC in your project.

One solution is use
#include <atlstr.h>
 
Share this answer
 
v2
Comments
drcool23 19-May-11 5:30am    
Hi, Thank you for reply. After including the #include<atlstr.h>, I have got the fatal error as "fatal error C1083: Cannot open include file: 'atlstr.h': No such file or directory" . I am not using ATL, However, I am using MFC. Please let me know, if you have any another suggestion/solution.
CPallini 19-May-11 5:35am    
If you're using MFC in your DLL then there shouldn't be any problem (and you don't need ATL). Anyway you stated you're building a Win32 DLL, not an MFC one. BTW usually Win32 DLLs import/exports strings as LPSTR, why don't you follow this path?
As last resuorce, you may try what suggests David Ching here:
http://www.eggheadcafe.com/software/aspnet/31827704/using-cstring-object-in-non-mfc-programs.aspx
ShilpiP 19-May-11 5:48am    
Cpallini is right. we cannot used in VC6.0. If you are using MFC than you don't get this error.
This you can check in project properties->genral.There is one label Microsoft Foundation Class.
One solution what i did in VC6.0 is using basic_string. it have both string and wstring.
CPallini 19-May-11 5:32am    
However, you cannot use it with VC6 (I believe you can do it since Visual Studio 2003).
ShilpiP 19-May-11 5:39am    
Oh yes, I am doing this in VS2005. Thanks
Two ways:
#include <string.h>

Or
#include <cstring>

The later incudes CString as part of the Std namespace.

[edit]Forgot to convert < and > to HTML safe... :O - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
drcool23 19-May-11 5:26am    
Hi, thank you for reply. I have tried this solution. However, It doesn’t work. Same error is present.
CPallini 19-May-11 5:28am    
Nope: CString is not part of std namespace, as Richard correctly pointed out, CString is an ATL/MFC class.
drcool23 19-May-11 5:40am    
This is MFC project. CString is working in another module. There I have seen that extra header file which they used is #include "fstream.h". Please let me know what would be the solution. This project is VC++ 6.0? Win32 DLL.
Stefan_Lang 19-May-11 7:09am    
I cannot say for sure, but I thought CString was introduced with VS 2003, so VC++ 6 might not even have it.

Alternately, if it was in VC 6, it may only have been included within the namespace ATL, so you might try using ATL::CString, or insert the line
using ATL;

You could also try the earlier name CAtlString (or ATL::CAtlString ? I don't know if that class actually used a namespace).

If neither of this does work, chances are that you nead a newer version of VC++.

P.S.: while searching for more info on ATL::CString I found that it isn't exactly the same as MFC::CString. Also it appears that some people have been working with both, suing VC++ 6 - here is a link to an article that claims as much, with various comments regarding VC 6:
http://www.codeguru.com/Cpp/COM-Tech/atl/atl/article.php/c67
Richard MacCutchan 19-May-11 9:05am    
Your comments are confusing, you start by saying this is MFC and end by saying it's Win32 DLL; so, which one is it? If this is really an MFC project then CString will be automatically included when the project is created (having used VC++ 6, I know this to be true). Note that fstream is part of STL not MFC.
I've found the following article that indicates you should be able to use CString in VC 6 (contrary to the assumption in my initial comment within OriginalGriffs solution):
Add MFC's CString class to ATL with No MFC Dependencies

Some of the comments below that article deal with using it in VC 6, maybe some of that can be of help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900