Quantcast

Maximum PC

It is currently Mon Jul 28, 2014 7:25 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: C++ compile errors in one project but not another
PostPosted: Thu Aug 13, 2009 1:38 pm 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
I've run into a problem I cannot figure out at all. I have a demo project that was given to me that was originally developed in MS Visual Studio 6. I opened it in Visual Studio 2005 and it did a quick upgrade to the configuration to make it compatible. It builds and runs fine without errors.

I created a new project and copied two of the source code files (both .cpp and .h files) to reuse some of the functionality. When I compile this project, it gives compile errors on several lines of these files. These are the exact same files (unedited) that compiled perfectly fine in the previous project. The errors are of the type:

error C2664: 'strlen' : cannot convert parameter 1 from 'CString' to 'const char *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

And in some cases:
error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'

Does anyone have idea why I would get compile errors in one project, but not the other? I looked for all kinds of project settings might cause this and couldn't see anything.


Top
  Profile  
 
 Post subject:
PostPosted: Thu Aug 13, 2009 3:18 pm 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
If you're able to release the code, seeing it would help.

As for your problems, it sounds to me that they lie with the CString type, documented here: http://msdn.microsoft.com/en-us/library/ms174288.aspx

But as far as the strlen function goes, that's just looking for a c-style string. It says here that you should be able to just typecast it.

Like I said we'd be able to help much more effectively if we could take a look at the code.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 7:09 am 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
Here are a couple examples of the errors:

error C2664: 'strlen' : cannot convert parameter 1 from 'CString' to 'const char *'
if(strlen(ps->Text)==0)
return 2 * ps->PointSize;

error C2440: 'type cast' : cannot convert from 'CString' to 'LPCSTR'
lstrcpy((LPSTR)lf.lfFaceName, (LPCSTR)ps->FontName);


error C2664: 'lstrcpyW' : cannot convert parameter 1 from 'LPSTR' to 'LPWSTR'
lstrcpy((LPSTR)lf.lfFaceName, (LPCSTR)ps->FontName);


The code I'm trying out is the CPage and CPrinter classes from this website:
http://www.ucancode.net/Visual-C-Print- ... tables.htm

I can accept the fact that there my be issues with this code. I just don't understand why I can compile these files without any errors at all when trying the demo project I downloaded.

Thanks!


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 8:49 am 
Willamette
Willamette
User avatar

Joined: Fri Jul 06, 2007 9:29 am
Posts: 1447
Did you get all the .h files? It looks to me like there's a define somewhere in one of the files you didn't include.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 9:18 am 
8086
8086

Joined: Tue May 09, 2006 9:58 am
Posts: 67
Location: Pittsburgh
Wow...I think I just figured it out. Almost by accident. I was playing with creating new projects with different settings in the AppWizard and adding those source files to compile. After several tries, I discovered that if I unchecked use Unicode support libraries, the project compiles without any of those errors.


Top
  Profile  
 
 Post subject:
PostPosted: Fri Aug 14, 2009 10:44 am 
Team Member Top 500
Team Member Top 500
User avatar

Joined: Mon Jan 08, 2007 1:41 pm
Posts: 2033
JeffV wrote:
Wow...I think I just figured it out. Almost by accident. I was playing with creating new projects with different settings in the AppWizard and adding those source files to compile. After several tries, I discovered that if I unchecked use Unicode support libraries, the project compiles without any of those errors.


That might do it lol...

msdn wrote:
A CString object supports either the char type or the wchar_t type. Which one it supports depends on which one of the symbols, MBCS or UNICODE, is defined at compile time.


I saw that before but I would have thought you'd get errors saying something about unicode... maybe it had something to do with the special CString type. But congrats on fixing it... :wink:


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group