Robert_Zenz
Well-known member
Hello.
I've tried to extract icons from exe files, though this works well with ExtractAssociatedIcon(filePath), but it extracts only the 32 pixel-sized icons (16 pixel-sized are needed).
Now, clever as I am, I found another method called ExtractAssociatedIcon(filePath, index) which I could use to go through every icon in the exe file and find a fitting one...well, I could manage to overcome the burden that this is a private method using reflection:
But, this does return an icon object with a (valid, at least it seems so) handle and height/width set to 0. Means, no icon. Though, I don't understand why, since when it's called from ExtractAssociatedIcon(filePath) it works:
If I call it like this:
It does return *some* icon (most likely 32 pixel-sized) from the file, but that's always returned, no matter to what I change the index.
Maybe the problem is that I invoked it...but still I don't see why this should be a problem.
Anyone every did something like this?
Best Regards and thanks in advance,
Bobby
P.s.: No, I'd like to stick with the Framework and don't wanna include an API-Call...
I've tried to extract icons from exe files, though this works well with ExtractAssociatedIcon(filePath), but it extracts only the 32 pixel-sized icons (16 pixel-sized are needed).
Now, clever as I am, I found another method called ExtractAssociatedIcon(filePath, index) which I could use to go through every icon in the exe file and find a fitting one...well, I could manage to overcome the burden that this is a private method using reflection:
VB.NET:
Dim iconGetCall As Reflection.MethodInfo = GetType(Icon).GetMethod("ExtractAssociatedIcon", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Static)
foundIcon = DirectCast(iconGetCall.Invoke(Nothing, New Object() {fromFile, index}), Icon)
But, this does return an icon object with a (valid, at least it seems so) handle and height/width set to 0. Means, no icon. Though, I don't understand why, since when it's called from ExtractAssociatedIcon(filePath) it works:
VB.NET:
Return Icon.ExtractAssociatedIcon(filePath, 0)
If I call it like this:
VB.NET:
DirectCast(iconGetCall.Invoke(Nothing, Reflection.BindingFlags.Static Or Reflection.BindingFlags.NonPublic, Nothing, New Object() {filePath, index}, Nothing), Icon)
Maybe the problem is that I invoked it...but still I don't see why this should be a problem.
Anyone every did something like this?
Best Regards and thanks in advance,
Bobby
P.s.: No, I'd like to stick with the Framework and don't wanna include an API-Call...