Click here to Skip to main content
12,813,626 members (33,448 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# PInvoke
Hi, I tried using Resource Hacker to open exlorer.exe and I can see there are some resource types such as MUI, IMAGE, ICON ...

But trying enumerating resource types using some Win32 API functions didn't succeed, It enumerated only 1 resource type called MUI (the first one in the resource types list), here is my code:

public Form1()
            //obtain the handle of the Explorer.exe, just a copy of it)
            IntPtr hExplorer = LoadLibrary("C:\\explorer.exe");
            //Start enumerating resource types
            EnumResourceTypes(hExplorer, new EnumResTypeProc(EnumResTypeProcInstance), 0);
        private static extern IntPtr LoadLibrary(string filename);
        private static extern int EnumResourceTypes(IntPtr hModule, EnumResTypeProc enumResTypeProc, int param);
        private delegate bool EnumResTypeProc(IntPtr hModule, string type, int param);
        private bool EnumResTypeProcInstance(IntPtr hModule, string type, int param)
            return true;//As I read from some source, this is for continuing enumerating.

The code works without exception but the MessageBox pops up only 1 time showing "MUI", I think it should pops up many times enough to show all the resouce types in explorer.exe (as I can see with Resource Hacker).

Could you please show me some thing wrong in my code making it not work as I expected?

Your help would be highly appreciated!
Posted 6-Feb-13 23:27pm
supernorb 7-Feb-13 5:48am
After hours waiting, not just a comment??? This life is so boring, at least to me...
CHill60 7-Feb-13 10:11am
Try replacing <pre>string type</pre> with <pre>int type</pre>. It's an LPTSTR that's required

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

private delegate bool EnumResTypeProc(IntPtr hModule, string type, int param);
private bool EnumResTypeProcInstance(IntPtr hModule, string type, int param)

private delegate bool EnumResTypeProc(IntPtr hModule, int type, int param);
private bool EnumResTypeProcInstance(IntPtr hModule, int type, int param)

and you'll have to show type.ToString()

I've seen comments elsewhere that suggest use of a MessageBox.Show() can "upset" callback methods. Hasn't impacted in this case, but you might be better off with
using System.Diagnostics;

Instead of type.ToString() try this Debug.Print(type.ToString() + " " + EnumResTypeName(type));
where the new function is
private string EnumResTypeName(int Type)
    string ret;
    switch (Type)
        case RT_ACCELERATOR:
            ret = "RT_ACCELERATOR";
        case RT_ANICURSOR:
            ret = "RT_ANICURSOR";
        case RT_ANIICON:
            ret = "RT_ANIICON";
        case RT_BITMAP:
            ret = "RT_BITMAP";
        case RT_CURSOR:
            ret = "RT_CURSOR";
        case RT_DIALOG:
            ret = "RT_DIALOG";
        case RT_DLGINCLUDE:
            ret = "RT_DLGINCLUDE";
        case RT_FONT:
            ret = "RT_FONT";
        case RT_FONTDIR:
            ret = "RT_FONTDIR";
        case RT_GROUP_CURSOR:
            ret = "RT_GROUP_CURSOR";
        case RT_GROUP_ICON:
            ret = "RT_GROUP_ICON";
        case RT_HTML:
            ret = "RT_HTML";
        case RT_ICON:
            ret = "RT_ICON";
        case RT_MANIFEST:
            ret = "RT_MANIFEST";
        case RT_MENU:
            ret = "RT_MENU";
        case RT_MESSAGETABLE:
            ret = "RT_MESSAGETABLE";
        case RT_PLUGPLAY:
            ret = "RT_PLUGPLAY";
        case RT_RCDATA:
            ret = "RT_RCDATA";
        case RT_STRING:
            ret = "RT_STRING";
        case RT_VERSION:
            ret = "RT_VERSION";
        case RT_VXD:
            ret = "RT_VXD";
        case RT_DLGINIT:
            ret = "RT_DLGINIT";
        case RT_TOOLBAR:
            ret = "RT_TOOLBAR";
            ret = "Unknown Type";
    return ret;

which uses the constants
const int RT_ACCELERATOR = 9; //Accelerator table.
const int RT_ANICURSOR = 21; //Animated cursor.
const int RT_ANIICON = 22; //Animated icon.
const int RT_BITMAP = 2; //Bitmap resource.
const int RT_CURSOR = 1; //Hardware-dependent cursor resource.
const int RT_DIALOG = 5; //Dialog box.
const int RT_DLGINCLUDE = 17; //Allows
const int RT_FONT = 8; //Font resource.
const int RT_FONTDIR = 7; //Font directory resource.
const int RT_GROUP_CURSOR = ((RT_CURSOR) + 11); //Hardware-independent cursor resource.
const int RT_GROUP_ICON = ((RT_ICON) + 11); //Hardware-independent icon resource.
const int RT_HTML = 23; //HTML resource.
const int RT_ICON = 3; //Hardware-dependent icon resource.
const int RT_MANIFEST = 24; //Side-by-Side Assembly Manifest.
const int RT_MENU = 4; //Menu resource.
const int RT_MESSAGETABLE = 11; //Message-table entry.
const int RT_PLUGPLAY = 19; //Plug and Play resource.
const int RT_RCDATA = 10; //Application-defined resource (raw data).
const int RT_STRING = 6; //String-table entry.
const int RT_VERSION = 16; //Version resource.
const int RT_VXD = 20; //
const int RT_DLGINIT = 240;
const int RT_TOOLBAR = 241;

I know there's a tidier way of doing this but can't think of it at the moment.
If you actually want the names of the resources themsselves (e.g. icon names) then you need to feed the type into EnumResourceNames - have a look at this blog[^]
supernorb 8-Feb-13 21:13pm
It seems that you tested the code and it worked well? But I did replace those lines of code as you suggested and the result is 16 shown instead of 'MUI', only 16 shown, (hahaa), why is this? I think the param type is type of string, not int, Could you please review your code to find any other things different from my code (except what you suggested to be modified). Thanks! =)
CHill60 9-Feb-13 16:34pm
I checked the API here But also found this article In the meantime I'm adding some stuff to the solution ... not the tidiest but it's a bit late here at the moment!
supernorb 11-Feb-13 12:04pm
Thank you for your update, however I still have some things unclear here, first If you open any exe file using Resource Hacker, you can see there is a Resource type MUI right at the first position of the resource types list, I can't see any MUI type in the types collection in the code above, this MUI type is achieved only by declaring 'type' as string, if declaring it as int (you suggested this), it showed 16 and matching this value to all resource type constants of int (in your updated code), the corresponding resource type is RT_VERSION, secondly, even when I use your 'converter' function between integer numbers and the corresponding Resouce type strings, the result will be only 1 resource type shown (by using your updated code, it is RT_VERSION instead of MUI or 16, and this is the hardest one I can't understand??? It should show me at least some resource types like resource hacker can extracts, I have even tried using a List<string> to add all the resource types found and show the types later, but the result is still only 1 type. I hope you would continue helping me by focusing on the second. Thank you so much for your effort!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170308.1 | Last Updated 9 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100