PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

char* into MessageBoxW?

This is surely a really stupid question, but I need to do something (like) :

long my_function(char *str)
{
return MessageBox(str,TEXT("HELLO"),MB_OK);
}

Except MessageBoxW expects str to be a Wide and I can't find a conversion function ... or I'm missing something obvious here...?

Cheers,

Refractor
To answer my own question, I used:

Code:
unsigned short buffer[256];
mbstowcs( buffer, str, 256 );


(if there's a better way of doing that, somebody please let me know) :)

Cheers,

Refractor
BurningSheep · 14 Aug 2002, 16:14 UTC
What you should do is this

Code:

long my_function(TCHAR * str)
{
return MessageBox(str, TEXT("HELLO"), MB_OK);
}


TCHAR is either a wide or ansi character, depends on whether unicode is used. The TEXT() macro converts an ansi string to wide when unicode is used or leaves it an ansi string otherwise.
CStrings are based around the TCHAR as well so when you build functions to accept TCHARs it becomes much easier to use CStrings with them.
BurningSheep wrote:
What you should do is this

Code:

long my_function(TCHAR * str)
{
return MessageBox(str, TEXT("HELLO"), MB_OK);
}


TCHAR is either a wide or ansi character, depends on whether unicode is used. The TEXT() macro converts an ansi string to wide when unicode is used or leaves it an ansi string otherwise.

insteat of TEXT("aoifg") you can simply use _T("aohd")[/code]
hmm.. _T is exactly the same as TEXT.. if you're so concerned about "shortness" not why simply use L"my string"?

call me pedantic ;)
BurningSheep · 16 Aug 2002, 00:49 UTC
L"String" always converts your string to unicode. So it doesn't do the same thing as the _T and TEXT macros do. They leave the string unchanged if unicode isn't used.
Code:
long my_function(TCHAR * str)
{
return MessageBox(str, TEXT("HELLO"), MB_OK);
}


The function prototype is "portable". I can't change it to TCHAR without breaking other things. Thanks anyway though :)

Cheers,

Ref.
Last I heard TCHARs are portable. If they're not it's certainly not difficult to recreate the macros.