Jump to content
  • Advertisement

C++ Getting unicode from an ini file

This topic is 516 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, this is my first post here and i hope to get an answer :)
My question is i am reading the section names from an file Unfortunately these section name contains unicode chars so when i read them i just get ???? 
here's my code ...

TCHAR buffer[4096];
int Lsize = sizeof(buffer),length;
TCHAR *Get = buffer;
while (*Get){
length = strlen(Get);
Get += length;


Share this post

Link to post
Share on other sites

I'm pretty sure that strlen() doesn't work on unicode characters, You probably need wcslen() instead (assuming that actually is a multi-byte string)

Share this post

Link to post
Share on other sites

Okay guys the problem was that the ini file was UTF-8 and not unicode hhhhhhhh 
Anway i wanted to ask another question ...
Since the Get and buffer are not char and TCHAR 
So when i use MessageBox::Show(Get);
It will give me error so i have tried this :
String ^GetResult = gcnew String(Get);
This one works but i don't know how this line works String ^GetResult = gcnew String(Get);
Can you please explain it ?

Share this post

Link to post
Share on other sites

Ouch, you're using managed C++. That's one ugly beast and usually only used for interfacing :)

It's combining C++ with .NET, and therefore has a few warts to transfer data between runtimes. Any reason why you're using this?


^ is a managed reference (somewhat like a * pointer in C/C++).
gcnew is the new of C++, creating a managed reference.
String( Get) is the constructor of the .NET String class which lets you pass in a char array.

So all you do in that line is creating a new managed instance of String, initialised with your char array.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!