Convert wxString URL's to char*
Nusret Taşçı
nusi at sofha.de
Sat Apr 21 10:21:35 PDT 2007
> I compiled in Unicode mode.
I'm not sure how this is handled on Linux. In your case 'wxChar' is
either identical to 'wchar_t' or 'int'. It's definitly not 'char'.
sizeof(wxChar) will be unequal to sizeof(char). Thus, a wxChar* is not
castable to a char* with the results you were expecting.
I think this will change with the next major release of wxWidgets, but
this is a different story.
> Ah, I didn't realise that ToAscii() returns a wxCharBuffer in unicode
> mode. The following works:
> const wxCharBuffer test1 = wxStringUrl.ToAscii();
> printf("URL1: %s\n", test1.data());
>
> I'm not sure that compiles in ANSI-mode though.
> However, why do the others don't work?
>>> const char* test1 = (const char*)wxStringUrl.ToAscii();
>>> printf("URL1: %s\n", test1);
pointer to dead object
>>> const char* test2 = (const char*)wxStringUrl.c_str();
>>> printf("URL2: %s\n", test2);
wrong pointer type
>>> const char* test3 = (const char*)wxStringUrl.mb_str(wxConvUTF8);
>>> printf("URL3: %s\n", test3);
pointer to dead object
>>> const char* test4 = (const char*)wxStringUrl.fn_str();
>>> printf("URL4: %s\n", test4);
The output was missing in your original mail.
According to the documentation this could be either "pointer to dead
object" or "wrong pointer type".
There are several tutorials to Unicode available on the net. Following
is a good read about that:
http://www.joelonsoftware.com/articles/Unicode.html
Please allow me to quote one line of given link:
> All that stuff about "plain text = ascii = characters are 8 bits" is not only wrong, it's hopelessly wrong
If you're just about to learn wxWidgets and you're not familiar with
Unicode, the best you can do is avoid Unicode builds and work with ASCII.
Best regards,
Nusi
More information about the wx-users
mailing list