1

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;
Simsons
  • 12,295
  • 42
  • 153
  • 269
  • Note that from the compiler error your Cstring seems to be CStringW (based on wchar_t) while your ReadFromRegistry expects a LPTSR based on char and not a LPWSTR based on wchar_t. – anno Oct 14 '10 at 13:22

2 Answers2

1

Your build settings look like 'Unicode' (based on reference to wchar_t) - you can change this to 'Use Multibyte Character Set' in the General page, Character Set field, of your project's Configuration Properties, if using Unicode is not your intention.

To see your project's properties right-click the project in Solution Explorer and select Properties.

You may find the ATL class CRegkey useful in correctly extracting values from the registry based on their type.

Steve Townsend
  • 53,498
  • 9
  • 91
  • 140
0

This is what worked for me:

char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),(LPSTR)m_szDriveName.GetBuffer(m_szDriveName.GetLength()));
Simsons
  • 12,295
  • 42
  • 153
  • 269