Click here to Skip to main content
15,913,055 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

GetPrivateProfileString() API returns the default value if the corresponding entry is not found in INI file. I want to get that as an error case (section missing). Is there any way to detect section or entry missing case using GetPrivateProfileString() API?

Thanks in advance...
Posted
Updated 7-Dec-11 18:09pm
v2
Comments
[no name] 8-Dec-11 0:11am    
EDIT: added code block
sanoopdas 8-Dec-11 0:12am    
what is this comment?
Albert Holguin 8-Dec-11 1:07am    
He just added html tags to your question to make it easier to read. Don't worry much about it.
sanoopdas 8-Dec-11 1:11am    
ok. :)

Well, if you set the default to NULL, it will return "", the empty string if the section isn't found. "" is rarely a good section name and you can check for that on the return.

Or, you could set the default to something you'll recognize, like "ThisIsTheDefault" and check for that coming back.

Other than testing for specific values, I can't think of a way to detect it since the API goes out of its way to have a default to hide the "missing" case from you.

Alternatively, you could use the other form of the API to get the enumeration of all the sections and explicitly look for the one you care about and detect that it is missing when you don't find it in the enumeration.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724353(v=vs.85).aspx[^]
 
Share this answer
 
You should probably note the comment at the top of the function description in MSDN.
Quote MSDN:
Note: This function is provided only for compatibility with 16-bit Windows-based applications. Applications should store initialization information in the registry.

So you probably shouldn't be using this for any new development... as it may not be supported in the future.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724353%28v=vs.85%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900