Home > Back-end >  How to know how many icons a .dll file contains (by importing the file from the computer) C#
How to know how many icons a .dll file contains (by importing the file from the computer) C#

Time:03-25

I want to know if it is possible to find out how many icons a .dll file stores by importing a file from the user's computer. I will explain in detail what I want to do. I need to know how many icons the .dll file contains because I'm using a listview where it's going to put the icons that this .dll file contains because when this form starts, it's going to display the icons to the user, and the number of icons that are going to be displayed in the listview is what I'm going to need to display those icons.

What I want to do is that the user can import his own .dll file from his computer. My program can read a .dll file or icon. But I have to tell it the path to the .dll file and when I add a .dll file, I use a program, not just any program, it is GConvert 5. It's great for saving icons from the .dll file in any format but I use it to know how many icons are in this .dll file I opened with. After I know this, I add one line of code per icon (from starting with 0 to (the number of icons in the .dll file)). But how can I know how many icons a .dll file contains when I am not behind the user's computer? I did this:

  • Adding an OpenFileDialog from the ToolBox

  • Adding the extensions: dll and ico

  • In the code, I add that:

    if (MyOpenFileDialog.ShowDialog() == DialogResult.Ok)
    {
        string dllFile = MyOpenFileDialog.FileName; // Ok, now I have the .dll file but I still can't find out how many icons this dll file contains.
    
        //... (Some code that is necessary and will not destroy the counting of icons)
    }
    

But I can't find any solutions on Google, tried some code but if I come to stackoverflow, my code doesn't works.

Thanks for helping me!

I tried to use a loop to display the icons in the listview but it doesn't work, I expect the user to open the .dll file, and in the listview it will simply show the number of icons in that listview.

CodePudding user response:

You can get the icons and count of icons using enter image description here

Please pay attention to the point which is highlighted in the comments by Jimi as per documentations to destroy icon handles as soon as you don't need them: When they are no longer needed, you must destroy all icons extracted by ExtractIconEx by calling the DestroyIcon function.

  • Related