Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

File Resource Management Library (.NET)

, 16 Sep 2009 CPOL
A .NET implementation of a file resource management, with complete support for VS_VERSIONINFO version resources.
vestris.resourcelib.1.2.zip
Vestris.ResourceLib
1.2
ResourceLib.chm
Article
Bin
Release
Vestris.ResourceLib.dll
Source
ResourceLib.proj
Version.proj
Common
ResourceLib
Properties
ResourceLibUnitTests
Properties
Vestris.ResourceLib.zip
1.0
Article
Bin
nunit.framework.dll
Vestris.ResourceLib.dll
Vestris.ResourceLibUnitTests.dll
Source
Common
ResourceLib.proj
ResourceLib
Properties
ResourceLibUnitTests
Properties
using System;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Collections.Generic;

namespace Vestris.ResourceLib
{
    /// <summary>
    /// Dialog template utility functions.
    /// </summary>
    internal abstract class DialogTemplateUtil
    {
        /// <summary>
        /// Read a dialog resource id.       
        /// </summary>
        /// <param name="lpRes">Address in memory.</param>
        /// <param name="rc">Resource read.</param>
        /// <returns></returns>
        internal static IntPtr ReadResourceId(IntPtr lpRes, out ResourceId rc)
        {
            rc = null;

            switch ((UInt16) Marshal.ReadInt16(lpRes))
            {
                case 0x0000: // no predefined resource
                    lpRes = new IntPtr(lpRes.ToInt32() + 2);
                    break;
                case 0xFFFF: // one additional element that specifies the ordinal value of the resource
                    lpRes = new IntPtr(lpRes.ToInt32() + 2);
                    rc = new ResourceId((UInt16)Marshal.ReadInt16(lpRes));
                    lpRes = new IntPtr(lpRes.ToInt32() + 2);
                    break;
                default: // null-terminated Unicode string that specifies the name of the resource
                    rc = new ResourceId(Marshal.PtrToStringUni(lpRes));
                    lpRes = new IntPtr(lpRes.ToInt32() + (rc.Name.Length + 1) * Marshal.SystemDefaultCharSize);
                    break;
            }

            return lpRes;
        }

        internal static void WriteResourceId(BinaryWriter w, ResourceId rc)
        {
            if (rc == null)
            {
                w.Write((UInt16) 0);
            }
            else if (rc.IsIntResource())
            {
                w.Write((UInt16) 0xFFFF);
                w.Write((UInt16) rc.Id);
            }
            else
            {
                ResourceUtil.PadToWORD(w);
                w.Write(Encoding.Unicode.GetBytes(rc.Name));
                w.Write((UInt16)0);
            }
        }

        /// <summary>
        /// String representation of the dialog or control style of two types.
        /// </summary>
        /// <param name="style">Dialog or control style.</param>
        /// <returns>String in the "s1 | s2 | ... | s3" format.</returns>
        internal static string StyleToString<W, D>(UInt32 style)
        {
            List<string> styles = new List<string>();
            styles.AddRange(ResourceUtil.FlagsToList<W>(style));
            styles.AddRange(ResourceUtil.FlagsToList<D>(style));
            return String.Join(" | ", styles.ToArray());
        }

        /// <summary>
        /// String representation of the dialog or control styles of two types.
        /// </summary>
        /// <param name="style">Dialog or control style.</param>
        /// <param name="exstyle">Dialog or control extended style.</param>
        /// <returns>String in the "s1 | s2 | ... | s3" format.</returns>
        internal static string StyleToString<W, D>(UInt32 style, UInt32 exstyle)
        {
            List<string> styles = new List<string>();
            styles.AddRange(ResourceUtil.FlagsToList<W>(style));
            styles.AddRange(ResourceUtil.FlagsToList<D>(exstyle));
            return String.Join(" | ", styles.ToArray());
        }

        /// <summary>
        /// String representation of the dialog or control style of one type.
        /// </summary>
        /// <param name="style">Dialog or control style.</param>
        /// <returns>String in the "s1 | s2 | ... | s3" format.</returns>
        internal static string StyleToString<W>(UInt32 style)
        {
            List<string> styles = new List<string>();
            styles.AddRange(ResourceUtil.FlagsToList<W>(style));
            return String.Join(" | ", styles.ToArray());
        }
    }
}

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

dB.
Team Leader Application Security Inc., www.appsecinc.com
United States United States
Daniel Doubrovkine has been in software engineering for twelve years and is currently development manager at Application Security Inc. in New York City. He has been involved in many software ventures, including Xo3 and Vestris Inc, was a development lead at Microsoft Corp. in Redmond, and director of Engineering at Visible Path Corp. in New York City. Daniel also builds and runs a foodie website, http://www.foodcandy.com.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150129.1 | Last Updated 16 Sep 2009
Article Copyright 2008 by dB.
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid