Craig
Craig

Reputation: 1225

Strcpy parameters are not correct

I am updating an older visual studio project to VS2013 and keep running into an issue where it does not like the parameters that I pass into strcpy functions.
This is a Unicode application.
I get the error -

cannot convert argument 2 from 'CString' to 'const char *'

strcpy(szFileName, m_strFileName);

m_strFileName is defined as a CString.

Upvotes: 1

Views: 191

Answers (1)

Cody Gray
Cody Gray

Reputation: 244752

The strcpy function accepts only parameters of type char*. That's what the compiler error is telling you—you have a type mismatch error. In a Windows environment, char* means narrow (i.e., ANSI) strings. Which no one uses anymore and hasn't for well over a decade.

You know this already; you say that you're building a Unicode application, which is what you should be doing. But that means you can't call the narrow string functions (str*) anymore. You have two options. Either:

  • Explicitly call the "wide" (i.e., Unicode) variants of the C string library functions, which are prefixed with wcs instead of str. In this case, then, you'd be calling wcscpy.

  • Use the macros that map automatically to the correct variant of the C string library functions. If the _UNICODE symbol is defined (as it would be for you), they will map to the wide-string variants; otherwise, they map to the narrow-string variants. These functions (actually macros) are all prefixed with _tcs. In this case, then, you'd call _tcscpy.

Upvotes: 2

Related Questions