From: tony.yi.zhou on 12 Apr 2006 03:29 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 12 Apr 2006 03:42 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 12 Apr 2006 04:02 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 12 Apr 2006 04:05 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 12 Apr 2006 04:29 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
|
Next
|
Last
Pages: 1 2 3 4 Prev: ERROR_DLL_INIT_FAILED - HELP please Next: VC++ doesn't like sal.h AT ALL! |