|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace Vestris.ResourceLib
{
/// <summary>
/// A generic resource.
/// </summary>
public class GenericResource : Resource
{
/// <summary>
/// Raw resource data.
/// </summary>
protected byte[] _data = null;
/// <summary>
/// Raw resource data.
/// </summary>
public byte[] Data
{
get
{
return _data;
}
set
{
_data = value;
}
}
/// <summary>
/// An unstructured generic resource embedded in an executable module.
/// </summary>
/// <param name="hModule">Module handle.</param>
/// <param name="hResource">Resource handle.</param>
/// <param name="type">Type of resource.</param>
/// <param name="name">Resource name.</param>
/// <param name="language">Language id.</param>
/// <param name="size">Resource size.</param>
public GenericResource(IntPtr hModule, IntPtr hResource, ResourceId type, ResourceId name, UInt16 language, int size)
: base(hModule, hResource, type, name, language, size)
{
}
/// <summary>
/// A generic resource.
/// </summary>
/// <param name="name">Resource name.</param>
/// <param name="type">Resource type.</param>
/// <param name="language">Resource language.</param>
public GenericResource(ResourceId type, ResourceId name, UInt16 language)
{
_type = type;
_name = name;
_language = language;
}
/// <summary>
/// Read a generic resource.
/// </summary>
/// <param name="hModule">Module handle.</param>
/// <param name="lpRes">Pointer to the beginning of a resource.</param>
/// <returns>Pointer to the end of the resource.</returns>
internal override IntPtr Read(IntPtr hModule, IntPtr lpRes)
{
if (_size > 0)
{
_data = new byte[_size];
Marshal.Copy(lpRes, _data, 0, _data.Length);
}
return new IntPtr(lpRes.ToInt32() + _size);
}
/// <summary>
/// Write the resource to a binary stream.
/// </summary>
/// <param name="w">Binary stream.</param>
internal override void Write(BinaryWriter w)
{
w.Write(_data);
}
}
}
|
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.
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.