ATL如何将BSTR * str转换为注册表项.SetValue(LPCTSTR str类型 [英] ATL how to Convert BSTR* str to registry key.SetValue(LPCTSTR str type

查看:113
本文介绍了ATL如何将BSTR * str转换为注册表项.SetValue(LPCTSTR str类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了C ++多年了,更不用说ATL代码了

It's been years since I have done C++ let alone ATL code

我有这种方法需要手术帮助:(

I have this method that needs surgical help :(

这是针对移动应用程序的,因此我不想使用CString和MFC

This is for a mobile app so I don't want to use CString and MFC

我需要将BSTR * str转换为正确的类型LPCTSTR在注册表中使用Set.Value方法

I need to convert the BSTR* str to the correct type LPCTSTR for use in the registry Set.Value method

STDMETHODIMP CAXSampleCtl::SendMSG(BSTR* str)
{
    CRegKey key;

    key.Create(HKEY_LOCAL_MACHINE, _T("MyKeyName"));

    key.SetValue( str <<<--- nope, _T("MyValueName"));

    key.Flush();

    key.Close();

    return S_OK;
}


推荐答案

COLE2T 宏只适合您,请参见字符串转换类和宏

COLE2T macro is just for you, see String Conversion Classes and Macros


要转换为BSTR,请将现有字符串传递给constructo
CComBSTR的r。要从BSTR进行转换,请使用COLE2 [C] DestinationType [EX],
(例如COLE2T)。

To convert to a BSTR, pass the existing string to the constructor of CComBSTR. To convert from a BSTR, use COLE2[C]DestinationType[EX], such as COLE2T.

这篇关于ATL如何将BSTR * str转换为注册表项.SetValue(LPCTSTR str类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆