From: tony.yi.zhou on
Greetings!

I'm converting programs written on Visual C++.NET 2003 to Visual C++
2005. While building them with Visual Studio 2005, I got hundreds of
errors like: "cannot convert parameter 1 from 'LPCTSTR' to 'const char
*'" or "cannot convert parameter 1 from 'const char *' to 'LPCTSTR'".
I wrote a simple application to duplicate it (see below):

#include "stdafx.h"
#include "windows.h"

int Work(LPCTSTR s)
{
return strlen(s);
}

int _tmain(int argc, _TCHAR* argv[])
{
Work("ABCDE");
return 0;
}

Does anyone know how to solve it? I don't want to add explicit
conversion because there are too many places in too many files.

Thanks in advance!

Tony

From: lallous on
Hello Tony,

Maybe you're compiling as unicode?

Since you are declaring your function's parameter as LPCTSTR you have to
make sure you're passing correctly as ASCII or as UNICODE depending on your
build.

Replace all your string literals with _T("my string") this macro will ensure
proper declaration of strings.

Work(_T("ABCDE"));

Also include "tchar.h"

HTH
Elias
<tony.yi.zhou(a)gmail.com> wrote in message
news:1144826944.679250.19380(a)g10g2000cwb.googlegroups.com...
> Greetings!
>
> I'm converting programs written on Visual C++.NET 2003 to Visual C++
> 2005. While building them with Visual Studio 2005, I got hundreds of
> errors like: "cannot convert parameter 1 from 'LPCTSTR' to 'const char
> *'" or "cannot convert parameter 1 from 'const char *' to 'LPCTSTR'".
> I wrote a simple application to duplicate it (see below):
>
> #include "stdafx.h"
> #include "windows.h"
>
> int Work(LPCTSTR s)
> {
> return strlen(s);
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> Work("ABCDE");
> return 0;
> }
>
> Does anyone know how to solve it? I don't want to add explicit
> conversion because there are too many places in too many files.
>
> Thanks in advance!
>
> Tony
>


From: Tony on
Thank you, Elias!

My programs are all ANSI. To use LPCTSTR is because it looks better
than const char* :-)

Should I define a macro to tell the compiler to work in ANSI mode?

Best Regards,
Tony

From: JoeB on
Or add a capital 'L' in front of the string:
"my string" ->> L"my String"

Although _T("my string") is better practice.

Now all you need is someone to come up with a regex find/replace to do
it for you!



J




lallous wrote:
> Hello Tony,
>
> Maybe you're compiling as unicode?
>
> Since you are declaring your function's parameter as LPCTSTR you have to
> make sure you're passing correctly as ASCII or as UNICODE depending on your
> build.
>
> Replace all your string literals with _T("my string") this macro will ensure
> proper declaration of strings.
>
> Work(_T("ABCDE"));
>
> Also include "tchar.h"
>
> HTH
> Elias
> <tony.yi.zhou(a)gmail.com> wrote in message
> news:1144826944.679250.19380(a)g10g2000cwb.googlegroups.com...
>> Greetings!
>>
>> I'm converting programs written on Visual C++.NET 2003 to Visual C++
>> 2005. While building them with Visual Studio 2005, I got hundreds of
>> errors like: "cannot convert parameter 1 from 'LPCTSTR' to 'const char
>> *'" or "cannot convert parameter 1 from 'const char *' to 'LPCTSTR'".
>> I wrote a simple application to duplicate it (see below):
>>
>> #include "stdafx.h"
>> #include "windows.h"
>>
>> int Work(LPCTSTR s)
>> {
>> return strlen(s);
>> }
>>
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>> Work("ABCDE");
>> return 0;
>> }
>>
>> Does anyone know how to solve it? I don't want to add explicit
>> conversion because there are too many places in too many files.
>>
>> Thanks in advance!
>>
>> Tony
>>
>
>
From: David Wilkinson on
tony.yi.zhou(a)gmail.com wrote:

> Greetings!
>
> I'm converting programs written on Visual C++.NET 2003 to Visual C++
> 2005. While building them with Visual Studio 2005, I got hundreds of
> errors like: "cannot convert parameter 1 from 'LPCTSTR' to 'const char
> *'" or "cannot convert parameter 1 from 'const char *' to 'LPCTSTR'".
> I wrote a simple application to duplicate it (see below):
>
> #include "stdafx.h"
> #include "windows.h"
>
> int Work(LPCTSTR s)
> {
> return strlen(s);
> }
>
> int _tmain(int argc, _TCHAR* argv[])
> {
> Work("ABCDE");
> return 0;
> }
>
> Does anyone know how to solve it? I don't want to add explicit
> conversion because there are too many places in too many files.
>
> Thanks in advance!
>
> Tony
>

Tony:

VS2005 enables Unicode build by default. While generally this is a good
idea, it seems kind of crazy to do it when converting a project from an
older version. You have to change your project settings to get back ANSI
build.

On the other hand, it really would be "better" to convert your code to
Unicode. This should be just a matter of inserting _T("") macro on all
strings. If you get it to compile in Unicode build, you can still go
back and make ANSI build in the short term.

David Wilkinson