467,910 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,910 developers. It's quick & easy.

GetprivateProfileString() and WritePrivateProfileString() problem with UTF8 ini files

100+
hi all,
I have a ini file in UTF-8, I am using GetPrivateProfileStringA() for reading and WriteprivateProfileStringA() for writing into the ini file. I am writing multibyte data into the file (using normal char *). so ini file is saved in UTF-8. And ini file is maintained in App data folder in windows systems.

Now the problem is.
if a user has unicode username, then SHgetFolderPath() -- with CSIDL_APPDATA option would return a path with that unicode username as part of it. I am handling all these in utf8. now GetPrivateProfileStringA() is failing with this path since it can only handle ANSI paths.

I am Not using GetprivateProfileStringW() and WritePrivateProfileStringW() since it wont save ini files in unicode! it is saving ini files inj ANSI eventhough I supply unicode data.

Waiting for your Reply,
Xoinki
Sep 14 '07 #1
  • viewed: 15507
Share:
4 Replies
weaknessforcats
Expert Mod 8TB
You do not ever call GetPrivateProfileStringA() or GetProfileStringW().

Instead, you include tchar.h and call GetPrivatePrileString(). Read this.

Notice the arguments s LPCTSTR, which are long pointers to constant TCHAR strings.

Whether ASCII or Unicode is used, is determined by the character set you specify in your project settings. GetPrivateProfileString() will resolve to GetPrivateProfileStringA() or GetProfileStringW() based on that setting. And the argiments will resolve to LPCSTR or LPCWSTR.

Be sure to use a _tmain() and observe all _t and _T functions plus use the TEXT macro. If you don't things won't work.
Sep 14 '07 #2
100+
hi,
Thnx for the reply.
I am compiling My application with UNICODE and _UNICODE defined.
so if i use Getprivateprofilestring() then it would internally use GetPrivateProfileStringW().. My problem is if i use this function to write unicode data into ini.. It should save ini file in Unicode format.. but it doesnt..
http://blogs.msdn.com/michkap/archive/2006/09/15/754992.aspx
So what I am doining is I am using WritePrivateProfileStringA() and writing UTF-8 data so forcing the file to be in UTF-8. but this works in all cases except when the path parameter has some utf-8 characters. It fails this case because WritePrivateProfileStringA() doesnt understand Utf-8 path.

So I am in dilemma of what to do so that ini file is in Utf8.

Is there any way to maintain ini file in utf8 without using WritePrivateProfileStringA() ?

Regards,
Xoinki
Sep 17 '07 #3
100+
hi,
I found out that opening a ini file and writing Unicode BOM explicitly would write unicode data properly when WriteProfileStringW() is used.. but this doesnt help since I want ini to be in Utf-8 any idea how i can maintain ini file in Utf8 and use utf8 paths??

Regards
Xoinki
Sep 18 '07 #4
100+
hi,
I got the problem solved by using a customatized ini-handler. Not using any MS API's, It just creates a separate Linked list for storing section info, key info, value info.. and a simple parser for fetching desired values.. It is funny that we are replacing MS API's coz of one limitation or other.. Earlier it was Codepage detection API's which are flawed(although quick).

Thnx
Xoinki
Nov 20 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by pekka niiranen | last post: by
5 posts views Thread by L | last post: by
1 post views Thread by Domac | last post: by
5 posts views Thread by 海风 | last post: by
4 posts views Thread by Thanh-Nhan Le | last post: by
2 posts views Thread by Nhan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.