views:

57

answers:

2

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;
+1  A: 

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
@Steve Townsend, Tried but this dint help as I am using static const wchar_t few places and it shows the error
Subhen
A: 

This is what worked for me:

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