Click here to Skip to main content
15,902,832 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Threads in Windows service Pin
RoyceF1-May-08 15:38
RoyceF1-May-08 15:38 
GeneralRe: Threads in Windows service Pin
Blake Miller2-May-08 4:34
Blake Miller2-May-08 4:34 
Question"MSDN Library for Visual Studio 2008 - ENU" update problem Pin
followait1-May-08 11:06
followait1-May-08 11:06 
QuestionRe: "MSDN Library for Visual Studio 2008 - ENU" update problem Pin
Hamid_RT2-May-08 5:04
Hamid_RT2-May-08 5:04 
AnswerRe: "MSDN Library for Visual Studio 2008 - ENU" update problem Pin
Mark Salsbery2-May-08 5:42
Mark Salsbery2-May-08 5:42 
QuestionHow to Convert CString to TChAR Pin
Larry Mills Sr1-May-08 10:06
Larry Mills Sr1-May-08 10:06 
AnswerRe: How to Convert CString to TChAR Pin
David Crow1-May-08 10:27
David Crow1-May-08 10:27 
AnswerRe: How to Convert CString to TChAR Pin
Randor 1-May-08 16:57
professional Randor 1-May-08 16:57 
You can use the ATL and MFC String Conversion Macros[^] to convert from wide string to LPCTSTR. Note that it is normally not recommended to use CStringA directly. In addition it is also not recommended to call the GetBuffer() member when there are better alternatives. However with those disclaimers out of the way lets continue to hammer a square peg into a round hole.

An ugly dirty method would be:

//Assuming CStringW in Unicode build
CString str = _T("C:\\Wells\\Program\\DataBases\\Drivers\\R and S\\OurDrivers.ddb");
USES_CONVERSION;
myFile.Open((LPCTSTR)CStringA(T2A(str)).GetBuffer(),0,0);


A better way of doing this would be:

//Assuming CStringW in Unicode build
CString str = _T("C:\\Wells\\Program\\DataBases\\Drivers\\R and S\\OurDrivers.ddb");
char szPath[MAX_PATH + 1] = {0};
USES_CONVERSION;
strcpy(szPath,T2A(str));
myFile.Open((LPCTSTR)szPath,0,0);


An even better way of doing this might be:

#ifdef _UNICODE
	char szPath2[MAX_PATH + 1] = {0};
	WideCharToMultiByte(CP_ACP, 0, str, -1, szPath2, MAX_PATH, NULL, NULL);
	myFile.Open((LPCTSTR)szPath,0,0);
#endif


Best Wishes,
-David Delaune
AnswerRe: How to Convert CString to TChAR Pin
Rajkumar R1-May-08 20:30
Rajkumar R1-May-08 20:30 
Questionvs2008 problem, about F1 and type mismatch Pin
followait1-May-08 8:44
followait1-May-08 8:44 
Questionhow can i do this with C++ Pin
reteset1-May-08 4:22
reteset1-May-08 4:22 
AnswerRe: how can i do this with C++ Pin
led mike1-May-08 6:21
led mike1-May-08 6:21 
AnswerRe: how can i do this with C++ Pin
Maximilien1-May-08 7:03
Maximilien1-May-08 7:03 
AnswerRe: how can i do this with C++ [modified] PinPopular
Rajkumar R1-May-08 7:10
Rajkumar R1-May-08 7:10 
GeneralRe: how can i do this with C++ Pin
Randor 1-May-08 9:14
professional Randor 1-May-08 9:14 
GeneralRe: how can i do this with C++ Pin
Maximilien1-May-08 9:24
Maximilien1-May-08 9:24 
GeneralRe: how can i do this with C++ Pin
JudyL_MD1-May-08 10:27
JudyL_MD1-May-08 10:27 
GeneralRe: how can i do this with C++ Pin
Maximilien1-May-08 10:47
Maximilien1-May-08 10:47 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 18:49
professionalRajesh R Subramanian1-May-08 18:49 
GeneralRe: how can i do this with C++ Pin
JudyL_MD2-May-08 2:12
JudyL_MD2-May-08 2:12 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 19:19
professionalRajesh R Subramanian1-May-08 19:19 
QuestionRe: how can i do this with C++ Pin
Rajkumar R1-May-08 19:28
Rajkumar R1-May-08 19:28 
GeneralRe: how can i do this with C++ Pin
Rajesh R Subramanian1-May-08 19:29
professionalRajesh R Subramanian1-May-08 19:29 
GeneralRe: how can i do this with C++ [modified] Pin
Rajkumar R1-May-08 19:24
Rajkumar R1-May-08 19:24 
GeneralRe: how can i do this with C++ Pin
Randor 2-May-08 5:36
professional Randor 2-May-08 5:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.