473,803 Members | 3,518 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Load Resources from Win32 Executables

I am attempting to read all of the resources from a Win32 executable, and
load each of them to display them on a screen. So, please help figure out
why I can't seem to get it right :)

First off, I have my API declarations (will post that at bottom). I make a
call to LoadLibraryEx. Then, if the result is not zero, I make a call to
EnumResourceNam es. EnumResourceNam esDelegate (delegate for
EnumResourceNam es) is called for every found resource, and this part works
fine. The names and types are passed in, but the names don't match the
actual resource names. They are passed as IntPtr's and event if I change
the type in the API declaration and delegate and function to ... say ..
string, I still get the same value...the value for type is correct (for an
Icon, I get the value of 3...which maps to RT_ICON). But the name is always
an indexed value. Or, what I believe, is the index for the Icon in the
resource list. The first one is always 1, the 2nd is 2, et cetera.

From this point, I get stuck. How can I get the actual name that I need to
use to pass to LoadResource in which the result of that call gets passed as
the handle to System.Drawing. Icon.FromHandle (for Icons),
System.Drawing. Bitmap.FromHbit map (for Bitmaps), et cetera?

When I call LoadResource, it returns a handle (non-zero). I pass this to
Icon.FromHandle and no exception is thrown. The Height and Width properties
of the Icon are both 0 and when I save the icon to disk, it is 0 bytes (the
file is).

Any and all help is much appreciated...b een stuck on this for awhile :)

Thanks,
Mythran

API Declarations that i have...

private const uint RT_CURSOR = 0x00000001;
private const uint RT_BITMAP = 0x00000002;
private const uint RT_ICON = 0x00000003;
private const uint RT_MENU = 0x00000004;
private const uint RT_DIALOG = 0x00000005;
private const uint RT_STRING = 0x00000006;
private const uint RT_FONTDIR = 0x00000007;
private const uint RT_FONT = 0x00000008;
private const uint RT_ACCELERATOR = 0x00000009;
private const uint RT_RCDATA = 0x0000000a;
private const uint RT_MESSAGETABLE = 0x0000000b;

private const uint LOAD_LIBRARY_AS _DATAFILE = 0x00000002;

[DllImport("kern el32.dll", SetLastError = true)]
private static extern IntPtr LoadLibraryEx(s tring lpFileName, IntPtr hFile,
uint dwFlags);

[DllImport("kern el32.dll", SetLastError = true)]
private static extern bool FreeLibrary(Int Ptr hModule);

[DllImport("kern el32.dll", EntryPoint = "EnumResourceNa mesW", CharSet =
CharSet.Unicode , SetLastError = true)]
static extern bool EnumResourceNam esWithName(
IntPtr hModule,
string lpszType,
EnumResNameDele gate lpEnumFunc,
IntPtr lParam);

[DllImport("kern el32.dll", EntryPoint = "EnumResourceNa mesW", CharSet =
CharSet.Unicode , SetLastError = true)]
static extern bool EnumResourceNam esWithID(
IntPtr hModule,
uint lpszType,
EnumResNameDele gate lpEnumFunc,
IntPtr lParam);

private delegate bool EnumResNameDele gate(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
IntPtr lParam);

[DllImport("kern el32.dll")]
static extern IntPtr FindResource(
IntPtr hModule,
IntPtr lpName,
IntPtr lpType);

[DllImport("user 32.dll")]
static extern IntPtr LoadIcon(
IntPtr hModule,
string Name
);

[DllImport("kern el32.dll", SetLastError=tr ue)]
static extern IntPtr LoadResource(In tPtr hModule, IntPtr hResInfo);
------------------------------------------------------------------

Dec 23 '05 #1
1 4709
Mythran,

In your EnumResourceNam eDelegate, you get the type and the name of the
resource in a string. From there, you can call the FindResource API method,
which will give you the handle that you can pass to LoadResource, which will
give you the appropriate handle which you can then use.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message
news:ec******** ******@TK2MSFTN GP10.phx.gbl...
I am attempting to read all of the resources from a Win32 executable, and
load each of them to display them on a screen. So, please help figure out
why I can't seem to get it right :)

First off, I have my API declarations (will post that at bottom). I make
a call to LoadLibraryEx. Then, if the result is not zero, I make a call
to EnumResourceNam es. EnumResourceNam esDelegate (delegate for
EnumResourceNam es) is called for every found resource, and this part works
fine. The names and types are passed in, but the names don't match the
actual resource names. They are passed as IntPtr's and event if I change
the type in the API declaration and delegate and function to ... say ..
string, I still get the same value...the value for type is correct (for an
Icon, I get the value of 3...which maps to RT_ICON). But the name is
always an indexed value. Or, what I believe, is the index for the Icon in
the resource list. The first one is always 1, the 2nd is 2, et cetera.

From this point, I get stuck. How can I get the actual name that I need
to use to pass to LoadResource in which the result of that call gets
passed as the handle to System.Drawing. Icon.FromHandle (for Icons),
System.Drawing. Bitmap.FromHbit map (for Bitmaps), et cetera?

When I call LoadResource, it returns a handle (non-zero). I pass this to
Icon.FromHandle and no exception is thrown. The Height and Width
properties of the Icon are both 0 and when I save the icon to disk, it is
0 bytes (the file is).

Any and all help is much appreciated...b een stuck on this for awhile :)

Thanks,
Mythran

API Declarations that i have...

private const uint RT_CURSOR = 0x00000001;
private const uint RT_BITMAP = 0x00000002;
private const uint RT_ICON = 0x00000003;
private const uint RT_MENU = 0x00000004;
private const uint RT_DIALOG = 0x00000005;
private const uint RT_STRING = 0x00000006;
private const uint RT_FONTDIR = 0x00000007;
private const uint RT_FONT = 0x00000008;
private const uint RT_ACCELERATOR = 0x00000009;
private const uint RT_RCDATA = 0x0000000a;
private const uint RT_MESSAGETABLE = 0x0000000b;

private const uint LOAD_LIBRARY_AS _DATAFILE = 0x00000002;

[DllImport("kern el32.dll", SetLastError = true)]
private static extern IntPtr LoadLibraryEx(s tring lpFileName, IntPtr
hFile, uint dwFlags);

[DllImport("kern el32.dll", SetLastError = true)]
private static extern bool FreeLibrary(Int Ptr hModule);

[DllImport("kern el32.dll", EntryPoint = "EnumResourceNa mesW", CharSet =
CharSet.Unicode , SetLastError = true)]
static extern bool EnumResourceNam esWithName(
IntPtr hModule,
string lpszType,
EnumResNameDele gate lpEnumFunc,
IntPtr lParam);

[DllImport("kern el32.dll", EntryPoint = "EnumResourceNa mesW", CharSet =
CharSet.Unicode , SetLastError = true)]
static extern bool EnumResourceNam esWithID(
IntPtr hModule,
uint lpszType,
EnumResNameDele gate lpEnumFunc,
IntPtr lParam);

private delegate bool EnumResNameDele gate(
IntPtr hModule,
IntPtr lpszType,
IntPtr lpszName,
IntPtr lParam);

[DllImport("kern el32.dll")]
static extern IntPtr FindResource(
IntPtr hModule,
IntPtr lpName,
IntPtr lpType);

[DllImport("user 32.dll")]
static extern IntPtr LoadIcon(
IntPtr hModule,
string Name
);

[DllImport("kern el32.dll", SetLastError=tr ue)]
static extern IntPtr LoadResource(In tPtr hModule, IntPtr hResInfo);
------------------------------------------------------------------

Dec 24 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3601
by: Greg | last post by:
Set Up Error - Failed to load resources from resource file Please check your set up. This plesently cordal and verbose error is greeting me in a very random and unpredictable way in a current VB .NET stand alone project I am doing (some times the program runs for 10 minutes, other times, I get the error right away). Has anyone seen this error in a VB.Net program? Any
3
7231
by: Ramani | last post by:
Hi, We are running a ASP .NET application on Win2K server (.NET framework 1.1) I have recently started getting this error - Failed to load resources from resource file. I would like to understand what causes this error. It is a multi-language app and in Application_BeginRequest we do Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(Request.UserLanguages);
0
1754
by: Kevin P | last post by:
Hi News Group, In an application written in C# and VS.Net using Dotnet Framework 1.1.4322 on XP and Win 2000 machines, we randomly get the error "Failed to load resources from resource file. Please check your setup." Although it is a random occurrance, it happens at the exact same location in the progran every time. At the time of this error, the monitor starts flickering white at a high frequency and CPU usage pegs out at 100%. The only...
0
2331
by: Paul | last post by:
I have an existing application that has been installed and running for several months. I recently made a minor change to this application. When the application is installed on the user machine and then run, I get the following error: Setup Error Failed to load resources from resource file. Please check your setup. The application was installed on a Windows XP SP2 machine. I have un-installed the .NET Framework 1.1 and latest hot-fix...
3
7803
by: Preference | last post by:
Hello, I am developing a .NET application in managed C++. Until now we have executed without problems in a lot of different computers. But a few days ago we detect a problem in some laptops. In all cases the system was XP SP2 and ..NET Framework 1.1. The problem appears initializing the application. A message box with the text 'Failed to load resources from resource file. Please check your Setup' appears and the application does not...
0
1186
by: Erald Kulk | last post by:
l.s. i'm using the setup wizard in vs.net for c# to create a setup wizard. since i've made some forms localizable i get some extra folders (en and en-US) in the release folder in my project. Where do i have to place these files in the setup wizard project. Since now all i'm getting when to load the program on a different machine than the development machine the error: "failed to load resources, please check your setup"
0
1958
by: Wal Turner | last post by:
Hi. The following error I seemingly get at random times when my application is loading. ************** Exception Text ************** System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at...
0
1514
by: bleedledeep | last post by:
I have 3 C# applications that run as a group. If I run each of these applications individually, they all start fine. If I have a batch file that starts each of them quickly, on *most* machines all three run fine. BUT! On some older/slower machines (really not all that old or slow and that are configured identically to the newer/faster machines), when I start all 3 with the batch file, one of them will not start and a popup containing:
0
883
by: Markus Wildgruber | last post by:
Hi! On one of our computers we get the following error message over and over again at various locations when running our WinForms app: Failed to load resources from resource file. Please check your setup. Unfortunately we can't reproduce that message on other computers and therefore we can't do any further debugging on this and provide more information at this point in time.
4
2468
by: bclegg | last post by:
Hi, I am getting the above error when start my application which I deployed successfully. The msi was produced using a .net launch project. I can't see how to dig deeper to find out what is failing to load. I have looked at the manifest with ildasm but am none the wiser. Does anybody know how to diagnose this sort of problem?
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.