Subj : Re: ansi (char *) to BSTR To : borland.public.cpp.borlandcpp From : maeder Date : Sun Jun 20 2004 10:05 am "Genie" writes: > I don't quite understand what you mean. In C and C++, we use numbers to represent characters. An encoding is a method of associating numbers and characters in a way that no number represents more than one character. > This is as much as I know.... > That some how i have to get char * into a unicode string Unicode is such a method. A very ambitious one, because the goal is to cover every character used on this planet. The function MultiByteToWideChar() from the Windows API seems to be what you want to use for this step. Cf. http://tinyurl.com/24hhv (aka http://msdn.microsoft.com/library/default.asp?url=/library/en-us/intl/unicode_2bj9.asp , but this link might wrap). > and then use SysAllocString on the unicode string to convert it to a BSTR. > I'm in a win32 environ and the string will be for passing to COM objects. Cf. http://tinyurl.com/365vq (aka http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcconStringsAllocatingReleasingMemoryForBSTR.asp , which, again, might wrap). > What I am looking for is a safe way to do that without causing memory > allocation problems, leaks GPFs ect. The first of the above Web pages pretends to discuss this issue but actually does a very poor job at it. I think that you are safe if you pass MultiByteToWideChar() a destination buffer that has at least one more elements than the length of the source string. .