Developer forums (C::B DEVELOPMENT STRICTLY!) > Contributions to C::B
Convert the char to an wchar_t
Schoppy:
Hi,
I have a Problem. I must convert an Char to an wchar_t.
My Sytem: Code::Blocks 1 RC2 + MinGW + WindowsXP
void DLL_EXPORT * DEMOText(
char Text,
int iTopX, int iTopY, int iBotX, int iBotY,
bool boBorder)
{
// Convert the char(Text) to an wchar_t ???????
return (void *)guienv->addStaticText(
Text, //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< this must a wchar_t
rect<int>(iTopX, iTopY, iBotX+iTopX, iBotY+iTopY),
boBorder);
}
Sorry for my bad English :-)
Can someone help me ?
Thanks
Schoppy
TDragon:
I see you're using Irrlicht; a quick Google for "Irrlicht and wchar_t" turned up the mbstowcs function. Here's a quick question: do you really only want to pass a single character to your DEMOText function (that's what you're doing), rather than a string? Since I doubt you do, following is an improved version that should do what you want.
--- Code: ---#include <cstdio>
#include <cstdlib>
IGUIStaticText* DLL_EXPORT DEMOText(char const* Text,
int iX,
int iY,
int iWidth,
int iHeight,
bool boBorder)
{
size_t alloc_len = strlen(Text) + 1;
wchar_t* wc_out = new wchar_t[alloc_len];
size_t result = mbstowcs(wc_out, Text, alloc_len);
IGUIStaticText* ret_val = 0;
if (result > 0)
{
ret_val = guienv->addStaticText(Text,
rect< int >(iX, iY, iX + iWidth, iY + iHeight),
boBorder);
}
delete[] wc_out;
return ret_val;
}
--- End code ---
kelo81:
The irrclicht string implementation already has support for converting between both formats I think (char* and w_char*), I tried to assign some values between stringw and stringc and it works fine! :) The mbstowcs could be helpful for unique char operations.
TDragon:
--- Quote from: kelo81 on January 19, 2007, 06:26:18 pm ---The irrclicht string implementation already has support for converting between both formats I think (char* and w_char*), I tried to assign some values between stringw and stringc and it works fine! :) The mbstowcs could be helpful for unique char operations.
--- End quote ---
Thanks for jumping in! I've never used Irrlicht on a regular basis, and wasn't aware of its string class.
--- Code: ---IGUIStaticText* DLL_EXPORT DEMOText(char const* Text,
int iX,
int iY,
int iWidth,
int iHeight,
bool boBorder)
{
core::stringw wc_text(Text);
return guienv->addStaticText(wc_text.c_str(),
rect< int >(iX, iY, iX + iWidth, iY + iHeight),
boBorder);
}
--- End code ---
Schoppy:
Thats it. Thank you for your help. :D
Navigation
[0] Message Index
[#] Next page
Go to full version