Figure 9: A simple C# console application

class Console
{
    unsafe static void Main()
    {
        try
        {
            // For brevity we assume Notepad is located here. To  
            // run this code yourself adjust this value accordingly.

            string strFileName = @"C:\Windows\Notepad.exe";

            // Load the library.

            using (Library library =
                new Library(strFileName, 
                            WindowsAPI.LOAD_LIBRARY_AS_DATAFILE))
            {
                // Notepad's icon resource identifier: 2

                IntPtr hGroupInfo =
                    library.FindResource(new IntPtr(2), 
                                         WindowsAPI.RT_GROUP_ICON);

                // Load the icon resource.

                IntPtr hGroupRes = library.LoadResource(hGroupInfo);

                // Get a pointer to the resource data.

                WindowsAPI.MEMICONDIR* pDirectory =
                    (WindowsAPI.MEMICONDIR*) Library.LockResource
                        (hGroupRes);

                if (0 != pDirectory->wCount)
                {
                    // pEntry points to the first entry in the array.
                    WindowsAPI.MEMICONDIRENTRY* pEntry =
                        &(pDirectory->arEntries);

                    // Adjust the pEntry to point to the last entry.
                    pEntry += pDirectory->wCount - 1;

                    // use the directory entry.
                }                
            }
        }
        catch (Exception e)
        {
            Console.WriteLine
                ("Console application failed: " + e.Message);
        }
    }
}
— End of Figure —