|
-
August 14th, 2007, 01:49 PM
#1
VS7.1 to VS8: Convert Project vs. New Project
I'm having some frustrations using VS8. Simple code that compiles cleanly in VS7 is generating errors in VS8.
If I convert a project from VS7 to VS8 it compiles cleanly, but if I create a new project using the same code, it doesn't compile.
Example:
Code:
// ConvertTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include "ConvertTest.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
CString text = "180";
WORD value = atoi(text);
cout << "Value=" << value << endl;
}
return nRetCode;
}
The above will compile and run in VS7. If I then open in VS8, it converts -- and still runs. But if I generate a new project in VS8 with the same code, I get errors.
The compiler doesn't like how the CString is initialized, and while you can fix it by doing CString text = _T("180"); the MSDN entry for CString basic operations states:
You can assign C-style literal strings to a CString just as you can assign one CString object to another:
Assign the value of a C literal string to a CString object:
Copy Code
CString myString = "This is a test";
Next, the compiler is not happy with passing a CString to atoi. It says, "cannot convert parameter 1 from 'CString' to 'const char *'. Has the basic operator overload been lost with VS8? Or is this another case of standards being enforced? Do I have to access the buffer to pass a CString to an LPCSTR where I used to just pass the CString?
Thanks
-
August 14th, 2007, 02:33 PM
#2
Re: VS7.1 to VS8: Convert Project vs. New Project
The problem you're having is probably because when you convert a project, it keeps the setting for the character set in use - it was probably ANSI (MBCS).
A new project in VS2005 defaults to UNICODE character set. You can change that in the Properties/Configuration Properties/General/Character Set for your newly created project.
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
August 15th, 2007, 06:48 AM
#3
Re: VS7.1 to VS8: Convert Project vs. New Project
Awesome! Such a simple solution!
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|