473,549 Members | 2,635 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 4685
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
3568
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...
3
7212
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 =...
0
1726
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...
0
2294
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...
3
7775
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...
0
1170
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...
0
1945
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...
0
1504
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...
0
875
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...
4
2448
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
7532
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...
0
7462
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...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7492
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...
0
6059
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...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3510
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
777
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...

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.