Click here to Skip to main content
12,626,813 members (35,991 online)
Click here to Skip to main content

Stats

87.2K views
635 downloads
62 bookmarked
Posted

Internet Explorer Favorites, deconstructed

, 24 Dec 2007 CPOL
Description of the binary format used to store internet explorer favorites, includes Favorites-to-XBEL example project.
Favorites2XBEL
Favorites2XBEL.suo
Favorites2XBEL
bin
Debug
xbel2xhtml.xsl
Release
xbel2xhtml.xsl
obj
Properties
xbel2xhtml.xsl
Favorites2XBEL.suo
xbel2xhtml.xsl
xbel2xhtml.xsl
xbel2xhtml.xsl
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CodeProject.IEFavDecon
{
    /// <summary>
    /// Interop wrapper for the legacy "PrivateProfileString" API.
    /// </summary>
    public class IniFile
    {
        [DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringA", CharSet = CharSet.Ansi, SetLastError = true)]
        private static extern int WritePrivateProfileString(string section, string key, string value, string filename);

        [DllImport("KERNEL32.DLL", EntryPoint = "GetPrivateProfileStringA", CharSet = CharSet.Ansi, SetLastError=true)]
        private static extern int GetPrivateProfileString(string section, string key, string defaultValue, StringBuilder returnString, int returnSize, string filename);

        private string filename;

        public IniFile(string filename)
        {
            this.filename = filename;
        }

        public string GetValue(string section,string key,string defaultValue)
        {
			StringBuilder sb = new StringBuilder(32768);
            GetPrivateProfileString(section, key, defaultValue, sb, sb.Capacity, filename);
			return sb.ToString();
        }

        public void WriteValue(string section, string key, string value)
        {
            if (WritePrivateProfileString(section, key, value, filename) == 0)
            {
                throw new Exception("WritePrivateProfileString failed: code " + Marshal.GetLastWin32Error().ToString());
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

jpmik
Architect
Netherlands Netherlands
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161205.3 | Last Updated 24 Dec 2007
Article Copyright 2007 by jpmik
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid