Archived

This topic is now archived and is closed to further replies.

problem with strcpy

This topic is 5132 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i dunno but i always seem to have trouble with this and can never figure it out. LPCTSTR *ClassName; void WinMainF::SetClassName(LPCTSTR *Name) { strcpy(ClassName, Name); } error C2664: ''strcpy'' : cannot convert parameter 1 from ''const char ** '' to ''char *'' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Share this post


Link to post
Share on other sites
The secret is in the macro/typedef name.

LPCTSTR is already a pointer, so the correct definition is:

LPCTSTR ClassName;

(same for the other definition)

The error does actually say that, but it might not be obvious.


[edited by - JuNC on November 30, 2003 2:52:31 PM]

Share this post


Link to post
Share on other sites
still get this error

error C2664: 'strcpy' : cannot convert parameter 1 from 'const char *' to 'char *'


[edited by - Rydis on November 30, 2003 3:35:24 PM]

Share this post


Link to post
Share on other sites

From MAPINLS.H in visual studio:

...
typedef const TCHAR FAR * LPCTSTR;
...

From MSDN:
The const keyword modifies the type of a type declaration or the type of a function parameter, preventing the value from varying.

Perhaps you could try:
LPTSTR ?

Floru

Share this post


Link to post
Share on other sites
Yes, you can happily do a char* -> const char* conversion, you don''t lose any of the qualifiers (in fact you gain). A const char* -> char* is invalid because it implies that you change an immutable string into a mutable string (well array really but lets not quibble). So if you do this you need to be explicit and add a cast.

Share this post


Link to post
Share on other sites