Hello DaniWeb. ;)

I have a problem with char->tchar conversion, that i cant seem to solve. I want to launch another program, anh the relative path to that program is fetched from MYSQL.

updateBox = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), hWnd, updateDiag);
hThread = (HANDLE)_beginthreadex(NULL, 0, Blah::Start, NULL, NULL, NULL);
_stprintf(patcherLoc, _T("%s/Patcher %s.exe"), UPDATE_DIR, row[2]);
strcpy(patcherUrl, row[3]);

I have tried like anything i could find on google, fx MultiByteToWideChar() - i even gone as far as to write it to a char, write the char to a file, read, and then in tchar format, from the file.

The TCHAR just contains some chineese symbols, and the only readable being "/Patcher" and ".exe".

It really just needs to be LPCTSTR-readable, so my ShellExecute will work.

MessageBox(hWnd, patcherLoc, _T("Error"), MB_OK | MB_ICONEXCLAMATION);
ShellExecute(NULL, NULL, patcherLoc, NULL, NULL, SW_SHOWNORMAL);

I use the messagebox to monitor how my TCHAR is doing.


I hope anyone can help me solve this problem.

Cheers :)

1) Are you compiling for UNICODE?

2) what compiler

3) how is UPDATE_DIR declared

4) note that %s and %S are not the same thing. See this

Try

// wcstombs(char *mbstr,const wchar_t *wcstr, size_t count)
//
...
CHAR *mbBuf= new CHAR[100];
TCHAR *wcBuf=_T("hello");
#ifdef _UNICODE
wcstombs(mbBuf,wcBuf,100);
#else
strcpy(mbBuf,wcBuf);
#endif
...
delete[]mbBuf;
...

wcstombs, strcpy are deprecated..
More secure versions are available..
Take care..

1) Are you compiling for UNICODE?

2) what compiler

3) how is UPDATE_DIR declared

4) note that %s and %S are not the same thing. See this

1) I am compiling UNICODE.
2) VC++
3) #define UPDATE_DIR "updateContent"
4) I'll read that, thanks.

Try

// wcstombs(char *mbstr,const wchar_t *wcstr, size_t count)
//
...
CHAR *mbBuf= new CHAR[100];
TCHAR *wcBuf=_T("hello");
#ifdef _UNICODE
wcstombs(mbBuf,wcBuf,100);
#else
strcpy(mbBuf,wcBuf);
#endif
...
delete[]mbBuf;
...

wcstombs, strcpy are deprecated..
More secure versions are available..
Take care..

Thank you for the answer.
- But I cant figure out where, in this code, my own stuff is to be placed.

Upss sorry..

mbstowcs(...)

that will help you..


Thank you for the answer.
- But I cant figure out where, in this code, my own stuff is to be placed.

Well..
Why dont you try it first..
There is another example for you..

/* 
 * mbstowcs(wchar_t *wcString,char *mbString,size_t nCount);
 */
... 
TCHAR *wcBuf=new TCHAR[100];
CHAR *mbBuf="MB STRING";
#ifdef _UNICODE
mbstowcs(wcBuf,mbBuf,100);
#else
strcpy(wcBuf,mbBuf);
#endif
...
delete[]wcBuf;
...

Sorry I have been offline for a while.. Ty your sonution worked! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.