944,058 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2085
  • C++ RSS
Oct 25th, 2009
0

Problem with TCHAR/CHAR

Expand Post »
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
Similar Threads
Reputation Points: 94
Solved Threads: 26
Posting Whiz
Excizted is offline Offline
309 posts
since Oct 2009
Oct 25th, 2009
-7
Re: Problem with TCHAR/CHAR
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
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,954 posts
since Aug 2005
Oct 25th, 2009
0
Re: Problem with TCHAR/CHAR
Try
c++ Syntax (Toggle Plain Text)
  1. // wcstombs(char *mbstr,const wchar_t *wcstr, size_t count)
  2. //
  3. ...
  4. CHAR *mbBuf= new CHAR[100];
  5. TCHAR *wcBuf=_T("hello");
  6. #ifdef _UNICODE
  7. wcstombs(mbBuf,wcBuf,100);
  8. #else
  9. strcpy(mbBuf,wcBuf);
  10. #endif
  11. ...
  12. delete[]mbBuf;
  13. ...
wcstombs, strcpy are deprecated..
More secure versions are available..
Take care..
Last edited by cikara21; Oct 25th, 2009 at 6:22 pm.
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Oct 25th, 2009
0
Re: Problem with TCHAR/CHAR
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.

Click to Expand / Collapse  Quote originally posted by cikara21 ...
Try
c++ Syntax (Toggle Plain Text)
  1. // wcstombs(char *mbstr,const wchar_t *wcstr, size_t count)
  2. //
  3. ...
  4. CHAR *mbBuf= new CHAR[100];
  5. TCHAR *wcBuf=_T("hello");
  6. #ifdef _UNICODE
  7. wcstombs(mbBuf,wcBuf,100);
  8. #else
  9. strcpy(mbBuf,wcBuf);
  10. #endif
  11. ...
  12. delete[]mbBuf;
  13. ...
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.
Reputation Points: 94
Solved Threads: 26
Posting Whiz
Excizted is offline Offline
309 posts
since Oct 2009
Oct 25th, 2009
0
Re: Problem with TCHAR/CHAR
Upss sorry..
C++ Syntax (Toggle Plain Text)
  1. mbstowcs(...)
that will help you..
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Oct 25th, 2009
0
Re: Problem with TCHAR/CHAR
Click to Expand / Collapse  Quote originally posted by Excizted ...



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..
C++ Syntax (Toggle Plain Text)
  1. /*
  2.  * mbstowcs(wchar_t *wcString,char *mbString,size_t nCount);
  3.  */
  4. ...
  5. TCHAR *wcBuf=new TCHAR[100];
  6. CHAR *mbBuf="MB STRING";
  7. #ifdef _UNICODE
  8. mbstowcs(wcBuf,mbBuf,100);
  9. #else
  10. strcpy(wcBuf,mbBuf);
  11. #endif
  12. ...
  13. delete[]wcBuf;
  14. ...
Reputation Points: 47
Solved Threads: 69
Posting Whiz
cikara21 is offline Offline
340 posts
since Jul 2008
Oct 28th, 2009
0
Re: Problem with TCHAR/CHAR
Sorry I have been offline for a while.. Ty your sonution worked!
Reputation Points: 94
Solved Threads: 26
Posting Whiz
Excizted is offline Offline
309 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: complicated while loop
Next Thread in C++ Forum Timeline: Need help with a function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC