CString to TCHAR
-
Hi everyone! I have a CString variable and it must be passed in a function as TCHAR. I don't know how could I convert it. Does anybody knows? Thank you in advance! :)
SomeFunction( TCHAR ch )
{
...
}CString str;
SomeFunction(str[0]);will work.
A rich person is not the one who has the most, but the one that needs the least.
-
Hi everyone! I have a CString variable and it must be passed in a function as TCHAR. I don't know how could I convert it. Does anybody knows? Thank you in advance! :)
TCHAR is simple "char" type. If you want to pass CString data into a function, you should use "TCHAR*" instead of "TCHAR". Example as below.
void f(TCHAR* prm) { do something } void main(void) { CString szPrm; f(szPrm.GetBuffer(szPrm.GetLength())); return(0); }
Otherwise, you can pass only one character into function. Ahmet Orkun GEDiK System & Software Support Specialist (SAP R/3) ASTRON -
TCHAR is simple "char" type. If you want to pass CString data into a function, you should use "TCHAR*" instead of "TCHAR". Example as below.
void f(TCHAR* prm) { do something } void main(void) { CString szPrm; f(szPrm.GetBuffer(szPrm.GetLength())); return(0); }
Otherwise, you can pass only one character into function. Ahmet Orkun GEDiK System & Software Support Specialist (SAP R/3) ASTRON -
If you do this you should also call szPrm.ReleaseBuffer(). The MSDN doc says the following: If you use the pointer returned by GetBuffer to change the string contents, you must call ReleaseBuffer before using any other CString member functions. If you are not going to change the string the following should work (LPTSTR)(LPCTSTR)szPrm John