Problem with TCHAR/CHAR

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 24
Reputation: Excizted is an unknown quantity at this point 
Solved Threads: 0
Excizted Excizted is offline Offline
Newbie Poster

Problem with TCHAR/CHAR

 
0
  #1
33 Days Ago
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,378
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning
 
-7
  #2
33 Days Ago
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
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz
 
0
  #3
33 Days Ago
Try
  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; 33 Days Ago at 6:22 pm.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 24
Reputation: Excizted is an unknown quantity at this point 
Solved Threads: 0
Excizted Excizted is offline Offline
Newbie Poster
 
0
  #4
33 Days Ago
Originally Posted by Ancient Dragon View Post
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.

Originally Posted by cikara21 View Post
Try
  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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz
 
0
  #5
33 Days Ago
Upss sorry..
  1. mbstowcs(...)
that will help you..
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz
 
0
  #6
33 Days Ago
Originally Posted by Excizted View Post



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..
  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. ...
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 24
Reputation: Excizted is an unknown quantity at this point 
Solved Threads: 0
Excizted Excizted is offline Offline
Newbie Poster
 
0
  #7
31 Days Ago
Sorry I have been offline for a while.. Ty your sonution worked!
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC