Proposed soultions are good ,however the proposed solutions doesn't work properly if the byte array taken for chinese characters or other languages as each language has different code point and encoding style to interpret the characters .Please refer to this page
[
^]
My solution is to use WideCharToMultiByte which works for all the unicode characters like chineese or others as well english as we have different code pages for each language . In below sample ,cp is set as UTF-8 encoding is the default standard used to convert to byte array
BSTR bstr=L"Arun";
// The same works if the same thing is written as arun in chinese
BSTR bstr=L"阿伦";
int res = WideCharToMultiByte(cp, 0, bstr, -1, NULL, 0, NULL, NULL);
if (res > 0)
{
BYTE * bytArray = new BYTE[res ];
WideCharToMultiByte(cp, 0, bstr, -1, &bytArray [0], res, NULL, NULL);
}