Jump to content
  • Advertisement
User134

C++ Getting unicode from an ini file

This topic is 368 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;
GetPrivateProfileSectionNames(buffer,Lsize,".//Test.txt");
TCHAR *Get = buffer;
while (*Get){
length = strlen(Get);
Get += length;
Get++;
}

 

Share this post


Link to post
Share on other sites
Advertisement

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);
MessageBox::Show(GetResult);
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!