troubleshooting Question

Loading an image from a library...error 127 (The specified procedure could not be found.)

Avatar of rossryan
rossryan asked on
4 Comments1 Solution2136 ViewsLast Modified:
Aright, I'm trying to load a bitmap from a file (C:\WINDOWS\Resources\Themes\Luna.theme). Unfortunately, I'm receiving an error of 127...any ideas?

Oh yeah, and once I have a handle to the bitmap, can I use Bitmap.fromresource (something like that) to grab it?

Many thanks,

using System;
using System.Runtime.InteropServices;
using System.Drawing;
namespace _4D_Environment
      /// <summary>
      /// Summary description for BitmapsGrab.
      /// </summary>
      public class Resource
            public Resource(string Filename)
                  System.Diagnostics.Debug.WriteLine("Loading Resource...");
                  hModule = Kernel32.LoadLibraryEx(Filename, 0, 0); //Kernel32.LOAD_LIBRARY_AS_DATAFILE);
                  if(hModule == IntPtr.Zero)
                        System.Diagnostics.Debug.WriteLine("Error loading library");

                  System.IntPtr StartButton = Kernel32.LoadImage(hModule, "BLUE_STARTBUTTON_BMP", Kernel32.IMAGE_BITMAP, 0, 0, Kernel32.LR_DEFAULTCOLOR);

                  //Int32 n = Kernel32.EnumResourceTypes(hModule, new Kernel32.EnumResTypeProc(EnumResTypeProc), 0);

                  int nError = Marshal.GetLastWin32Error();

                  hModule = IntPtr.Zero;
                  StartButton = IntPtr.Zero;

            public Bitmap newbit;
            private IntPtr hModule;

            public static Int32 EnumResTypeProc(IntPtr hModule,
                  IntPtr lpszType, long lParam)
                  Kernel32.EnumResourceNames(hModule, lpszType, new Kernel32.EnumResNameProc(EnumResNameProc), lParam);
                  return 1;

            public static Int32 EnumResNameProc(IntPtr hModule, IntPtr lpszType, [MarshalAs(UnmanagedType.LPStr)] string lpszName, long lParam)
                  System.Diagnostics.Debug.WriteLine("Name: " + lpszName);
                  return 1;

      public class Kernel32

            public const long DONT_RESOLVE_DLL_REFERENCES     = 0x00000001;
            public const long LOAD_LIBRARY_AS_DATAFILE          = 0x00000002;
            public const long LOAD_WITH_ALTERED_SEARCH_PATH     = 0x00000008;
            public const long LOAD_IGNORE_CODE_AUTHZ_LEVEL     = 0x00000010;

            //Enum types
            public const long RT_CURSOR  = 1;          
            public const long RT_BITMAP = 2;              
            public const long RT_ICON = 3;              
            public const long RT_MENU = 4;
            public const long RT_DIALOG = 5;
            public const long RT_STRING = 6;
            public const long RT_FONTDIR = 7;
            public const long RT_FONT = 8;
            public const long RT_ACCELERATOR = 9;
            public const long RT_RCDATA = 10;
            public const long RT_MESSAGETABLE = 11;
            public const long RT_VERSION = 16;
            public const long RT_DLGINCLUDE = 17;
            public const long RT_PLUGPLAY = 19;
            public const long RT_VXD = 20;
            public const long RT_ANICURSOR = 21;
            public const long RT_ANIICON = 22;
            public const long RT_HTML = 23;
            public const long RT_MANIFEST = 24;
            public const uint IMAGE_BITMAP = 0;
            public const uint IMAGE_ICON = 1;
            public const uint IMAGE_CURSOR = 2;
            public const uint LR_DEFAULTCOLOR     =0x0000;
            public const uint LR_MONOCHROME       =0x0001;
            public const uint LR_COLOR            =0x0002;
            public const uint LR_COPYRETURNORG    =0x0004;
            public const uint LR_COPYDELETEORG    =0x0008;
            public const uint LR_LOADFROMFILE     =0x0010;
            public const uint LR_LOADTRANSPARENT  =0x0020;
            public const uint LR_DEFAULTSIZE      =0x0040;
            public const uint LR_VGACOLOR         =0x0080;
            public const uint LR_LOADMAP3DCOLORS  =0x1000;
            public const uint LR_CREATEDIBSECTION =0x2000;
            public const uint LR_COPYFROMRESOURCE =0x4000;
            public const uint LR_SHARED           =0x8000;

            public const long LANG_NEUTRAL = 0x00;

            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern IntPtr LoadLibraryEx(string lpfFileName,
                  long hFile, long dwFlags);

            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern Int32 EnumResourceTypes(IntPtr hModule, EnumResTypeProc callback, long lParam);

            public delegate Int32 EnumResTypeProc(IntPtr hModule, IntPtr lpszType, long lParam);
            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern bool FreeLibrary(IntPtr hModule);

            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern Int32 EnumResourceNames(IntPtr hModule, IntPtr lpszType, EnumResNameProc callback, long lParam);
            public delegate Int32 EnumResNameProc(IntPtr hModule, IntPtr lpszType, [MarshalAs(UnmanagedType.LPStr)] string lpszName, long lParam);
            [DllImport("user32.dll", SetLastError=true)]
            public static extern IntPtr LoadImage(IntPtr hinst, [MarshalAs(UnmanagedType.LPStr)] string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad);
            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern IntPtr FindResourceEx(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string lpType, [MarshalAs(UnmanagedType.LPStr)] string lpName, long wLanguage);
            [DllImport("kernel32.dll", SetLastError=true)]
            public static extern void LockResource(IntPtr hResData);



Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros