CString to LPCTSTR conversion

Ionut Daniel picture Ionut Daniel · Sep 27, 2012 · Viewed 39.1k times · Source

I have a CString variable that i a need to convert to LPCTSTR(const char*) .I need this conversion so that i can use it as an argument in a function .

The CString look like :

CString sqlTemp = _T("INSERT INTO "+ sw1 +" (filename, "+ sw2 +") VALUE ("+ sw7 +","+ sw3 +" ) ");

It contains an query. The prototype of the function is :

int WriteBlob(LPCTSTR szSqlStat, LPCTSTR szFilePath)

So could you show me an exemple of how to convert to LPCTSTR ? It may be trivial but i am a c++ beginner and i still get a hang of it.

Thanks .

Answer

Ionut Hulub picture Ionut Hulub · Sep 27, 2012

One method of conversion is like this:

CString str;

str = "Hello";

LPCSTR szTemp = (LPCSTR)(LPCTSTR)str;