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

I am working with Windows Registry "Windows 7". I need to add an .xml file to the

windows registry and i want to access the data of .xml file through window registry

using vc++.

1) How to add an .xml file to the window registry.

2) How to access the .xml file through window registry using vc++.

If anyone having idea of how to work with window registry.

Please Help me out.

Thanks in Advance.
Posted
Comments
Richard MacCutchan 18-Oct-12 5:21am    
You should not be storing files in the registry. You may store the full path name of the file if necessary, or short snippets of XML.

See here[^] for lots of articles and samples for Registry handling. I would also repeat my previous comment that you should not store files in the registry.
 
Share this answer
 
Hello there.
Simple answer is no - you can't add an xml file to the windows registry... at least not in the way you are thinking.
What you can do is add the xml file content to the registry, as a string value. For such a task, using RegSetValueEx is the way to go:
1) Read the content of your xml file into a variable;
2) Use the xml content for the lpData parameter of RegSetValueEx - you may need to perform casting.

But here's the rub: the registry is not designed for large pieces of data. If your xml file content is not Unicode (ANSI), you will have a maximum of about 1MB available (the limit of the REG_SZ value). In addition, MSDN states:
"Long values (more than 2,048 bytes) should be stored in a file, and the location of the file should be stored in the registry. This helps the registry perform efficiently."
 
Share this answer
 
Comments
SoMad 18-Oct-12 16:20pm    
Good answer. We have an old application that stores configuration data in XML format in a single registry value. On some systems this is 400 KB of data! It works fine, but I would not recommend the approach.

-Soren Madsen-
Kumar 09 22-Oct-12 22:26pm    
I added the path of the file in to registry like this RegSetValueEx(HKEY_CURRENT_USER, "", 0, REG_SZ, (const BYTE*)"D:\\facedata.xml", 512); but i am unable to read data from this facedata.xml.
Did i wrote the correct way or anything wrong.
ASM
LONG WINAPI RegSetValueEx(
  _In_        HKEY hKey,
  _In_opt_    LPCTSTR lpValueName,
  _Reserved_  DWORD Reserved,
  _In_        DWORD dwType,
  _In_        const BYTE *lpData,
  _In_        DWORD cbData
);



for d
etails visit:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms724875(v=vs.85).aspx[^]
 
Share this answer
 
Comments
Kumar 09 18-Oct-12 5:20am    
How to retrieve data from .xml through window registry.
You may add the XML file logical content to the registry (since the registry has, like the XML file, a tree structure). However you must use the registry API (see the documentation)[^] to perform the task (storing content as strings).

As Richard correctly noted, you shouldn't add too much info to the registry. That is if the XML file is big then you shouldn't add its content to the registry (as suggested, you should leave the content in the XML file and store in the registry just the file path).
 
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