Jump to content
Sign in to follow this  

[Resolved] EnumResourceNames and EnumResNameProc ?

Recommended Posts



After poking around at MSDN I recently worked out how to use windows api to extract an icon group from an exe or dll to an *.ico file by using LoadLibraryEX(), FindResource()

(This sounds easy huh.. must admit it took me a while to work out writing the header for the extracted icon , but a bit of byte play saw me clear to getting it working successfully.)

But the problem I'm having is I need to know RT_GROUP_ICON Resource Type name that's in the exe or dll before I can extract the icon.

So in my efforts I thought if I can list the RT_GROUP_ICON Resource Type names that's contained in the exe or dll I can extract the icon I require without error.

I'm having trouble understanding the way to use EnumResourceNames and EnumResNameProc to list the RT_GROUP_ICON names.

I sort of got lost when the EnumResourceNames function required a callback function using EnumResNameProc function.

If anyone could guide me a little in how to use use/translate these functions in autoit then feel free to do so.

(siao your expert knowledge in this type of thing would be greatly appreciated)

Links to the functions:

MSDN: EnumResourceNames Function

MSDN: EnumResNameProc Function


Edited by smashly

Share this post

Link to post
Share on other sites

In its most basic form:

#include <WinAPI.au3>

ConsoleWrite('Enumerating - user32.dll, type=3 (RT_ICON):' & @CRLF)
_ResourceEnumNames(_WinAPI_GetModuleHandle('user32.dll'), 3)
ConsoleWrite('Enumerating - ntbackup.exe, type=10 (RT_RCDATA):' & @CRLF)
_ResourceEnumNames('ntbackup.exe', 10)

Func _ResourceEnumNames($vModule, $iType)
    Local $hModule = $vModule, $aRet, $fLoad = IsString($vModule), $xCB = DllCallbackRegister('___EnumResNameProc','int','int_ptr;int_ptr;int_ptr;int_ptr')
    If $fLoad Then $hModule = _WinAPI_LoadLibrary($vModule)
    $aRet = DllCall('kernel32.dll','int','EnumResourceNamesW', 'ptr',$hModule, 'int',$iType, 'ptr',DllCallbackGetPtr($xCB), 'ptr',0)
    If $fLoad Then _WinAPI_FreeLibrary($hModule)
Func ___EnumResNameProc($vModule, $pType, $pName, $lParam)
    Local $aSize = DllCall('kernel32.dll','int','GlobalSize','ptr',$pName), $tBuf
    If $aSize[0] Then
        $tBuf = DllStructCreate('wchar[' & $aSize[0] & ']', $pName)
        ConsoleWrite(DllStructGetData($tBuf, 1) & @CRLF) ;string ID
        ConsoleWrite($pName & @CRLF) ;integer ID
    Return 1 ;continue enumeration
Edited by Siao

"be smart, drink your wine"

Share this post

Link to post
Share on other sites

A big THANK YOU Siao. :):P

You make it look so simple once you put it like that.

Damn I tried doing the same thing for hours on end and I didn't even come close to getting it right when I look at your example.

Thanks again


Edit: your example should be part of the WinAPI udf.

Edited by smashly

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this