Reading INI file

Posted on 2015-01-07
Last Modified: 2015-01-08
I am using this code for taking values from INI files,

"int vers = GetPrivateProfileInt(L"VERSION", L"Version", -1, L"E:/KTDaemon/Data/INI/KTDaemon.ini");"

I've tried lot, but this one worked by prefixing 'L' on String.Is there any replacements?????
  • 3
  • 2

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 40537302
Your character is UNICODE. So you have to use L or _T().
If in project setting you are using 'multi byte char set',  instead of 'Unicode Char', then it will work without L
Let us know if you need more information!!!

Author Comment

by:Santhamohan Manivannan
ID: 40537306
So, we need to change settings in Project properties.....
LVL 33

Accepted Solution

sarabande earned 500 total points
ID: 40537341
So, we need to change settings in Project properties.....
if you don't need Unicode support, yes.

if you need Unicode (or better Microsoft UTF16) you have two choices.

either call

"int vers = GetPrivateProfileIntA("VERSION", "Version", -1, "E:\\KTDaemon\\Data\\INI\\KTDaemon.ini");"


you have to write (and create) the inifile using SetPrivateProfileInt with a program or function where also UNICODE was switched on.

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why


Author Closing Comment

by:Santhamohan Manivannan
ID: 40537530
Thank you so much Guys!!!! It really worked out!!!!!!!!!!!!!!!

Author Comment

by:Santhamohan Manivannan
ID: 40537576
Can I do the same thing for the String also????
LVL 33

Expert Comment

ID: 40537676
you should give assist points to subrat for his valid comment. you could reopen the question by using the 'Request Attention' button below your original question.

Can I do the same thing for the String also????
I assume you mean to read strings from ini file:

char szResult[256] = { '\0' };
DWORD ret = GetPrivateProfileStringA(("VERSION", "ProductName", "not provided", szResult, sizeof(szResult),

Open in new window


Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question