'wchar_t *' a 'TCHAR [260]' conversion error

May 7, 2014 at 6:19pm
Hi :)

Someone could explain me why this conversion is not correct?

1
2
3
4
5
6
7
8
9
10
int FileSystemExplore(TCHAR *dir,TCHAR* goalstring){
.
.


  TCHAR current_file[MAX_PATH];
.
.

  current_file=_tcsdup(dir);


The error is impossible cast from 'wchar_t *' to 'TCHAR [260]'

Thanks in advance
Last edited on May 7, 2014 at 6:19pm
May 7, 2014 at 6:31pm
_tcsdup returns a pointer. You're trying to assign that pointer to an array.
TCHAR is a simple type (char or wchar_t). It is not a class like std::string and does not support assigning a pointer.
May 7, 2014 at 6:42pm
Thanks for the answer.
How can i do that? There is a way different from declare current_file as a pointer?
May 7, 2014 at 7:14pm
closed account (N36fSL3A)
Check out the strcpy wcscpy function.
Last edited on May 7, 2014 at 7:20pm
May 7, 2014 at 7:34pm
Thanks :)
May 8, 2014 at 6:54am
to clarify....
strcpy copies chars
wcscpy copies wchar_ts
_tcscpy copies TCHARs.

Since you are using TCHARs, you will need to use _tcscpy.


Or... better yet... don't use TCHARs. Ever. They're retarded. The "normal" WinAPI functions take TCHAR strings... but you can take normal chars or wchar_ts by adding an 'A' or 'W' to the end of the function name.

IE:
MessageBox <- takes TCHAR strings
MessageBoxA <- takes char strings
MessageBoxW <- takes wchar_t strings
May 8, 2014 at 8:11pm
Thanks for the exhaustive response ,it's very useful :)
Topic archived. No new replies allowed.