Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CString to LPCTSTR conversion

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 .

like image 414
Ionut Daniel Avatar asked Sep 27 '12 11:09

Ionut Daniel


People also ask

How do you convert CString to Lpcstr?

Solution 4. CString p; m_editbox->GetWindowText(p); CWND *c = FindWindow(NULL,p);

How do you convert CString to Lpcwstr?

For example, the macro to convert CString to LPCWSTR is CT2W(s) . Another way is to use the specialized CStringA and CStringW classes. These are the corresponding ascii and wide versions of CString depending on if you're compile with the UNICODE flag.

How do you convert CString to float in MFC?

CString pi = "3.14"; return _ttof(pi); Reading a string value and parse/convert it to float allows you to locate the error when there is one. All you need is a help of a C Run-time function: strtod() or atof().

What is Lpctstr?

An LPCSTR is a 32-bit pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters.


1 Answers

One method of conversion is like this:

CString str;

str = "Hello";

LPCSTR szTemp = (LPCSTR)(LPCTSTR)str;
like image 128
Ionut Hulub Avatar answered Sep 29 '22 02:09

Ionut Hulub