Search code examples
c++windowscstring

How to Convert CString LPStr


I want to read a value from registry using the following method:

char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),m_szDriveName);

I tried converting using GetBuffer,m_szDriveName.GetBuffer(0) but this again shows error:

error C2664: cannot convert parameter 3 from 'wchar_t *' to 'LPSTR'

Edit: Declaration of Method and variable is below:

char*   ReadFromRegistry(HKEY,LPCTSTR,LPSTR);
CString     m_szDriveName;

Solution

  • This is what worked for me:

    char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),(LPSTR)m_szDriveName.GetBuffer(m_szDriveName.GetLength()));