1

I'm using ADO and I retrieve a string data from mysql database.

CString         cstrPrivilege;
char*           charPrivilege;
//assume that I have done the database connection
//let said the data is "Admin"
cstrPrivilege = (LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("Privilege");
wcout << cstrPrivilege.GetString() <<endl; // no problem, show "Admin"

The problem now is I want to assign convert the cstrPrivilege to charPrivilege for strcmp() purpose. But I have no idea and I have try a lot of method like:

charPrivilege = (LPSTR)(LPCTSTR)cstrPrivilege; 
cout << charPrivilege; // only show the first character, show "A" only 

and

charPrivilege = (LPSTR)(LPCTSTR)cstrPrivilege.GetBuffer(cstrPrivilege.GetLength());
// show "A" only too

I had found that my cstrPrivilege is in LPCWSTR type, but I still have no idea how to convert it. Anyone have idea to solve it?

Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
Owl
  • 243
  • 1
  • 2
  • 9

0 Answers0