www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - wchar* to char[]

reply Heinz <malagana15 yahoo.es> writes:
Hi,

Is there a way to convert a wchar* variable to char[]? I'm trying to use the
Win32 API LoadStringW, wich takes a parameter a wchar*.

Thanx.
Feb 06 2008
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Heinz" <malagana15 yahoo.es> wrote in message 
news:foe0pj$mct$1 digitalmars.com...
 Hi,

 Is there a way to convert a wchar* variable to char[]? I'm trying to use 
 the Win32 API LoadStringW, wich takes a parameter a wchar*.
So, you have a function that takes a wchar*, and you have a wchar*. .. I'm not seeing how char[] comes into this at all.
Feb 06 2008
prev sibling parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Heinz <malagana15 yahoo.es> wrote:
 Is there a way to convert a wchar* variable to char[]? I'm trying to use the
Win32 API LoadStringW, wich takes a parameter a wchar*.
Assuming that `src' is a wchar* string, in Phobos it's like this: import std.utf; extern(C) uint wcslen(in wchar* str); // a C runtime library function char[] str = toUTF8(src[0..wcslen(src)]); In Tango, this would be: import tango.text.convert.Utf; import tango.text.Util; auto len = indexOf(src, '\u0000', uint.max); char[] str = toString(src[0..len]); -- SnakE
Feb 06 2008
parent reply doob <doobnet gmail.com> writes:
Sergey Gromov wrote:
 Heinz <malagana15 yahoo.es> wrote:
 Is there a way to convert a wchar* variable to char[]? I'm trying to use the
Win32 API LoadStringW, wich takes a parameter a wchar*.
Assuming that `src' is a wchar* string, in Phobos it's like this: import std.utf; extern(C) uint wcslen(in wchar* str); // a C runtime library function char[] str = toUTF8(src[0..wcslen(src)]); In Tango, this would be: import tango.text.convert.Utf; import tango.text.Util; auto len = indexOf(src, '\u0000', uint.max); char[] str = toString(src[0..len]);
I would do like this: Phobos: import std.string; import std.utf; // alias for char[] (D 1.x) string str = toUTF8(toString(src)); Tango: import tango.stdc.stringz; import tango.text.convert.Utf; char[] str = toString(fromString16z(str));
Feb 07 2008
parent reply Sergey Gromov <snake.scaly gmail.com> writes:
doob <doobnet gmail.com> wrote:
 Sergey Gromov wrote:
 Heinz <malagana15 yahoo.es> wrote:
 Is there a way to convert a wchar* variable to char[]? I'm trying to use the
Win32 API LoadStringW, wich takes a parameter a wchar*.
Assuming that `src' is a wchar* string, in Phobos it's like this: import std.utf; extern(C) uint wcslen(in wchar* str); // a C runtime library function char[] str = toUTF8(src[0..wcslen(src)]);
I would do like this: Phobos: import std.string; import std.utf; // alias for char[] (D 1.x) string str = toUTF8(toString(src));
In Phobos, there is no function "std.string.toString(wchar*)". -- SnakE
Feb 07 2008
parent doob <doobnet gmail.com> writes:
Sergey Gromov wrote:
 doob <doobnet gmail.com> wrote:
 Sergey Gromov wrote:
 Heinz <malagana15 yahoo.es> wrote:
 Is there a way to convert a wchar* variable to char[]? I'm trying to use the
Win32 API LoadStringW, wich takes a parameter a wchar*.
Assuming that `src' is a wchar* string, in Phobos it's like this: import std.utf; extern(C) uint wcslen(in wchar* str); // a C runtime library function char[] str = toUTF8(src[0..wcslen(src)]);
I would do like this: Phobos: import std.string; import std.utf; // alias for char[] (D 1.x) string str = toUTF8(toString(src));
In Phobos, there is no function "std.string.toString(wchar*)".
My bad, it was only for char*
Feb 08 2008