如何将 char * 转换为 const OLECHAR * 以便在 SYSALLOCSTRING() 中使用?

Har*_*hvi 5 c++ visual-c++

请告诉我如何在 SysAllocString() 中使用 char *xyz 等字符串,该字符串以 OLECHAR const * 作为参数

小智 1

要将 a 转换char*const OLECHAR*您可以使用宏A2COLE

所以,如果你有一个 'char* pChar' 应该可以这样做:

const OLECHAR* pOleChar = A2COLE( pChar );
BSTR str = SysAllocString( pOleChar );
// do something with the 'str'
SysFreeString( str ); // need to cleanup the allocated BSTR
Run Code Online (Sandbox Code Playgroud)