473,804 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GetprivateProfi leString() and WritePrivatePro fileString() problem with UTF8 ini files

110 New Member
hi all,
I have a ini file in UTF-8, I am using GetPrivateProfi leStringA() for reading and WriteprivatePro fileStringA() 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 GetPrivateProfi leStringA() is failing with this path since it can only handle ANSI paths.

I am Not using GetprivateProfi leStringW() and WritePrivatePro fileStringW() 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
4 16991
weaknessforcats
9,208 Recognized Expert Moderator Expert
You do not ever call GetPrivateProfi leStringA() or GetProfileStrin gW().

Instead, you include tchar.h and call GetPrivatePrile String(). 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. GetPrivateProfi leString() will resolve to GetPrivateProfi leStringA() or GetProfileStrin gW() 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
xoinki
110 New Member
hi,
Thnx for the reply.
I am compiling My application with UNICODE and _UNICODE defined.
so if i use Getprivateprofi lestring() then it would internally use GetPrivateProfi leStringW().. 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 WritePrivatePro fileStringA() 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 WritePrivatePro fileStringA() 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 WritePrivatePro fileStringA() ?

Regards,
Xoinki
Sep 17 '07 #3
xoinki
110 New Member
hi,
I found out that opening a ini file and writing Unicode BOM explicitly would write unicode data properly when WriteProfileStr ingW() 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
xoinki
110 New Member
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

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

Similar topics

4
19245
by: Mark Hayworth | last post by:
Randy: I too am having the problem that this other guy/girl had. I put in the proper API declarations and arguments for GetPrivateProfileString yet it doesn't return the correct stuff. It always returns the default value (padded with huge amount of spaces on the right) and the return value (number of characters read) is some crazy huge number like 51298398749084 Your demo doesn't work in .Net - it's for prior versions of VB, and so the...
10
2597
by: pekka niiranen | last post by:
Hi there, I have two files "my.utf8" and "my.utf16" which both contain BOM and two "a" characters. Contents of "my.utf8" in HEX: EFBBBF6161 Contents of "my.utf16" in HEX: FEFF6161
5
19692
by: L | last post by:
static extern uint GetPrivateProfileString( string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, uint nSize, string lpFileName); Interoping GetPrivateProfileString is giving me this Exception in
1
3660
by: Domac | last post by:
I need to read some configuration data from .ini file located at Application.StartupPath location . Here is code snippet : Public Declare Unicode Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringW" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Int32, ByVal lpFileName As String) As Int32
5
7665
by: 海风 | last post by:
A question about GetPrivateProfileString a section in a .ini file , for example ip = 192.168.1.112 .... i want to get the ip value by using GetPrivateProfileString() function. the code is :
4
3402
by: Thanh-Nhan Le | last post by:
Hi, Is there any way to use the API function WritePrivateProfileString in NET framework 2.0? Thanks Nhan
2
3755
by: Nhan | last post by:
Hi, I am trying to use the function GetPrivateProfileString as following: public static extern Int32 GetPrivateProfileString(string lpAppName, string lpKeyName, string lpDefault, string lpReturnedString, short nSize, string lpFileName); ....... String sDatabase = "";
0
1465
by: Bexm | last post by:
Hello Yes I know before you say I know INI files are outdated and xml should be used instead, but I have a very specific reason and an INI file must be used as it is also being used by an old VB app. I have a C# asp.net application which has been running quite happily using WritePrivateProfileString() from KERNEL32 and writing to my INI file, but for some reason this has stopped working, so I now need another method. Does anyone have...
6
3814
by: alag20 | last post by:
Hi Guys, I need some urgent help with this as I am becoming clueless now. I have 2 DllImport as below from Kernel32 private static extern int GetPrivateProfileString(string section, int key, string defaultValue, byte result, int size, string fileName); private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder result, int size, string fileName);
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.