如何转换 CString LPStr

发布于 2024-09-27 14:35:29 字数 428 浏览 0 评论 0原文

我想使用以下方法从注册表读取值:

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

我尝试使用 GetBuffer,m_szDriveName.GetBuffer(0) 进行转换,但这再次显示错误:

错误 C2664:无法将参数 3 从“wchar_t *”转换为“LPSTR”

编辑: 方法和变量的声明如下:

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

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期情话 2024-10-04 14:35:29

您的构建设置看起来像“Unicode”(基于对 wchar_t 的引用) - 您可以在项目配置属性的“常规”页面的“字符集”字段中将其更改为“使用多字节字符集”,如果使用 Unicode 不是您的本意。

要查看项目的属性,请右键单击“解决方案资源管理器”中的项目,然后选择“属性”。

您可能会发现 ATL 类 CRegkey 对于从注册表中正确提取值非常有用根据他们的类型。

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.

烦人精 2024-10-04 14:35:29

这对我有用:

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

This is what worked for me:

char* cDriveStatus=ReadFromRegistry(HKEY_CURRENT_USER,_T(NDSPATH),(LPSTR)m_szDriveName.GetBuffer(m_szDriveName.GetLength()));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文