简体   繁体   English

如何转换CString LPStr

[英]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: 我尝试使用GetBuffer, m_szDriveName.GetBuffer(0)转换,但这再次显示错误:

error C2664: cannot convert parameter 3 from 'wchar_t *' to 'LPSTR' 错误C2664:无法将参数3从'wchar_t *'转换为'LPSTR'

Edit: Declaration of Method and variable is below: 编辑:方法和变量的声明如下:

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

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. 构建设置看起来像“ Unicode”(基于对wchar_t引用)-如果您不打算使用Unicode,则可以在项目的“配置属性”的“常规”页面的“字符集”字段中将其更改为“使用多字节字符集”。

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. 您可能会发现ATL类CRegkey可用于根据注册表类型正确地从注册表中提取值。

这对我有用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM