开发者

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

开发者 https://www.devze.com 2023-04-10 23:29 出处:网络
It\'s been years since I have done C++ let alone ATL code I have this method that needs surgical help :(

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::Send开发者_C百科MSG(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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消