[SOLVED] C++ Extension Writing: Return UTF-8 Encoding?

S

Sam (Deleted User)

Guest
I'm writing an update for most of my extensions to support UTF-8 encoding on Windows.

So far so good, I got several functions working with UTF-8, because I'm converting the char * arguments to WCHAR before using them.

There is a roadblock however. One of my functions has a return value that needs to support UTF-8. While this normally wouldn't be an issue if I were writing a C++ application to call the DLL, it is a problem in GameMaker Studio, because GameMaker Studio limits me to only 3 return types: void, double, and char *.

char * would be the way to go on Mac and Linux, because on those platforms char * can handle UTF-8 encoding. But on Windows it's not that simple. I need to convert it first to some other type, such as WCHAR.

Since GameMaker Studio cannot use WCHAR nor any of the other types I'd need for this to work, am I pretty much out of options? Is there no way to do this?

Or is there some workaround I'm just not seeing?

Thanks!
 

Tthecreator

Your Creator!
I've been there with converting multiple types of strings and chars. It's terrible.

I thing you might have thought about/tried this and I might simply be stupid for asking but:
what if you just force your UTF-8 bytes in a char array? A wchar is simply just a set of UTF-32 data.
If you don't need the extra special characters, you could just throw away 3/4th of your bytes. You will have to do that since appearently UTF-32 uses /0 bytes, which indicate the end of the string.
If you do want fancy characters you'd just have to make some conversion script.
I found this stackoverflow page which might help you: https://stackoverflow.com/questions/17104962/how-to-cast-a-wchar-t-to-a-byte-in-c
 
S

Sam (Deleted User)

Guest
Hey @Tthecreator, and thanks for your reply. Sadly, that stack overflow link didn't help me much. Until you or someone else can explain a little better how I'm supposed to achieve this, I think in the meantime I'll make a note on the marketplace stating that that one particular function is the only one that won't support UTF-8 on Windows. I'm not very experienced with type conversion, so most code I use for that is either given to me or found somewhere on the web.

Edit:

I figured it out. Turns out I can still use char * as my return type and still support UTF-8 encoding - just like you said - all I needed was a converter script. Topic solved.
 
Last edited by a moderator:
Top