Link to home
Start Free TrialLog in
Avatar of Rajkumar Gs
Rajkumar GsFlag for India

asked on

Read App.config values from MFC

Hi,

  I have a doubt that Is it possible to read app.config values from MFC application.If it is possible could you please send the code or any useful links? It is very urgent i need.

Thanks
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Since app.config is just XML of course you can read it... any XML library will cope just fine :)
Avatar of Rajkumar Gs

ASKER

Hi
Thanks for your reply.
How can we read it? What is the code can we use? I know in .Net code to read app.config values. But i m new in MFC application. Hope your's reply.

Like I said, just use any one of the plethora of XML libraries available for C/C++

http://www.xmlsoft.org/
http://xerces.apache.org/xerces-c/
http://www.grinninglizard.com/tinyxml/

Anyone should do the job. Of those three Xerces is probably the best but also probably overkill for your simple needs. I'd probably consider libxml for what you are doing.

You could also code your own XML decoder... it's not (that) hard. I'd stick to a proven library thought.
ASKER CERTIFIED SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi pgnatyuk,
  This code i already done in visual c++ 2008 but in MFC it's something different.
so i am not expecting this one. Also i dont want to use third party tools. I need pure MFC application code to read values from app.config. Hope your's reply.

Thanks
It cannot be pure MFC app. It can be pure Microsoft approach (or a kind of).
Take a look:
#import  raw_interfaces_only
using namespace MSXML2
It's not about MFC. It's more about COM.

MSDN. Program with DOM in C/C++
http://msdn.microsoft.com/en-us/library/ms759192(VS.85).asp

IXMLDOMDocument is here:
http://msdn.microsoft.com/en-us/library/ms756987(VS.85).asp
There is a simple code in the bottom.

In this article you will see more MFC-like samples:
Introduction to Using the XML DOM from Visual C++
http://www.codeguru.com/cpp/misc/misc/article.php/c3707

You can find a code to download here:
CodeProject.C++ XML the easy way!
http://www.codeproject.com/KB/trace/C___XML_wrapper.aspx
If you are in a hurry then use pure C++ based xml binder
http://www.codesynthesis.com/products/xsd/ 
and grab App.config XSD files from say c:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas.
Those should be DotNetConfig.xsd and so on.
Just a tiny point:
Is your app coded in .net (this is a .net area) or MFC.  They are NOT the same.
CXMLParser added in MFC 10.
http://cppdepend.wordpress.com/2010/08/29/

BTW, Parsing XML using a C++ wrapper for SAX2
http://www.codeproject.com/KB/cpp/xml_support.aspx?display=Print
Using this solution, I can achieve in a Windows Form Application. In MFC, I finally choosed INI file to get the data instead of app.config.

Thanks to all
Raj