ATL how to Convert BSTR* str to registry key.SetValue(LPCTSTR str type

空扰寡人 提交于 2019-12-13 03:49:03

问题


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

I have this method that needs surgical help :(

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

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;
}

回答1:


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

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.



来源:https://stackoverflow.com/questions/7654998/atl-how-to-convert-bstr-str-to-registry-key-setvaluelpctstr-str-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!