Get Class ImageList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • [Joe]

    Get Class ImageList

    Hi,
    How can I get the System class ImageList from C# application, I want to
    receive this image list used in device manager ?
    I find a C API :

    WINSETUPAPI BOOL WINAPI
    SetupDiGetClass ImageList(
    OUT PSP_CLASSIMAGEL IST_DATA ClassImageListD ata);

    How I can call this API from C# ?

    Thanks
    Joe
  • Willy Denoyette [MVP]

    #2
    Re: Get Class ImageList


    "[Joe]" <Joe@discussion s.microsoft.com wrote in message
    news:158F3917-9C35-487F-8910-059C413331C4@mi crosoft.com...
    | Hi,
    | How can I get the System class ImageList from C# application, I want to
    | receive this image list used in device manager ?
    | I find a C API :
    |
    | WINSETUPAPI BOOL WINAPI
    | SetupDiGetClass ImageList(
    | OUT PSP_CLASSIMAGEL IST_DATA ClassImageListD ata);
    |
    | How I can call this API from C# ?
    |
    | Thanks
    | Joe

    Not sure why you ever wanna use this from C# but here it goes:

    [DllImport("setu papi.dll")]
    static extern int SetupDiGetClass ImageList(out PSP_CLASSIMAGE_ DATA
    ClassImageList) ;

    public struct PSP_CLASSIMAGE_ DATA {
    public uint cbSize; // size of this struct
    public IntPtr ImageList; // Handle
    public uint Reserved;
    }

    don't forget to destroy the list when done (see
    SetupDiDestroyC lassImageList).

    Willy.


    Comment

    • [Joe]

      #3
      Re: Get Class ImageList

      Hello Willy,
      Thanks this was very helpful , I still don't know how to convert this
      handle to System.Windows. Forms.ImageList ?? , I watch in the Marshal class
      but didn't figure how to do that. I will be so happy if you can help me also
      in this issue .

      Regards,
      Joe

      "Willy Denoyette [MVP]" wrote:
      >
      "[Joe]" <Joe@discussion s.microsoft.com wrote in message
      news:158F3917-9C35-487F-8910-059C413331C4@mi crosoft.com...
      | Hi,
      | How can I get the System class ImageList from C# application, I want to
      | receive this image list used in device manager ?
      | I find a C API :
      |
      | WINSETUPAPI BOOL WINAPI
      | SetupDiGetClass ImageList(
      | OUT PSP_CLASSIMAGEL IST_DATA ClassImageListD ata);
      |
      | How I can call this API from C# ?
      |
      | Thanks
      | Joe
      >
      Not sure why you ever wanna use this from C# but here it goes:
      >
      [DllImport("setu papi.dll")]
      static extern int SetupDiGetClass ImageList(out PSP_CLASSIMAGE_ DATA
      ClassImageList) ;
      >
      public struct PSP_CLASSIMAGE_ DATA {
      public uint cbSize; // size of this struct
      public IntPtr ImageList; // Handle
      public uint Reserved;
      }
      >
      don't forget to destroy the list when done (see
      SetupDiDestroyC lassImageList).
      >
      Willy.
      >
      >
      >

      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Get Class ImageList


        "[Joe]" <Joe@discussion s.microsoft.com wrote in message
        news:9E0FD75E-5CDD-401C-A9F8-BDBAFE7E7F18@mi crosoft.com...
        | Hello Willy,
        | Thanks this was very helpful , I still don't know how to convert
        this
        | handle to System.Windows. Forms.ImageList ?? , I watch in the Marshal class
        | but didn't figure how to do that. I will be so happy if you can help me
        also
        | in this issue .
        |

        That's what I was affraid of, Forms.ImageList is a class while the
        setupapi.dll API returns a Handle, there is no way to convert this to an
        ImageList nor to contruct an ImageList from a Handle. The setup library is
        not meant for general consumption, it is meant to be used to build your own
        device setup applications (using C++) using your own image lists. If you are
        trying to implement device installers using C# you will have a hard time as
        you'll have to use all API's in the set. If you are only trying to use the
        images in the setupapi.dll ,you only have to call SetupDiDrawMini Icon using
        this import definition:

        [DllImport("setu papi.dll")]
        static extern int SetupDiDrawMini Icon(IntPtr hDC, Rectangle rec, int index,
        uint flags);
        but honestly I don't see why you ever wanna do this.

        Willy.








        Comment

        • [Joe]

          #5
          Re: Get Class ImageList

          what I'm tring to display my devices in treeview and set the image depending
          on the Class type .

          "Willy Denoyette [MVP]" wrote:
          >
          "[Joe]" <Joe@discussion s.microsoft.com wrote in message
          news:9E0FD75E-5CDD-401C-A9F8-BDBAFE7E7F18@mi crosoft.com...
          | Hello Willy,
          | Thanks this was very helpful , I still don't know how to convert
          this
          | handle to System.Windows. Forms.ImageList ?? , I watch in the Marshal class
          | but didn't figure how to do that. I will be so happy if you can help me
          also
          | in this issue .
          |
          >
          That's what I was affraid of, Forms.ImageList is a class while the
          setupapi.dll API returns a Handle, there is no way to convert this to an
          ImageList nor to contruct an ImageList from a Handle. The setup library is
          not meant for general consumption, it is meant to be used to build your own
          device setup applications (using C++) using your own image lists. If you are
          trying to implement device installers using C# you will have a hard time as
          you'll have to use all API's in the set. If you are only trying to use the
          images in the setupapi.dll ,you only have to call SetupDiDrawMini Icon using
          this import definition:
          >
          [DllImport("setu papi.dll")]
          static extern int SetupDiDrawMini Icon(IntPtr hDC, Rectangle rec, int index,
          uint flags);
          but honestly I don't see why you ever wanna do this.
          >
          Willy.
          >
          >
          >
          >
          >
          >
          >
          >
          >

          Comment

          • Willy Denoyette [MVP]

            #6
            Re: Get Class ImageList


            "[Joe]" <Joe@discussion s.microsoft.com wrote in message
            news:F5B3D3F0-EDE2-4325-B84F-00A4B86FD528@mi crosoft.com...
            | what I'm tring to display my devices in treeview and set the image
            depending
            | on the Class type .
            |
            |
            Well as I said, you need to call some more API's.
            First you'll have to call:
            SetupDiClassGui dsFromName
            to get the list of Guid's corresponding to the device class,
            using the right Guid in the list you'll have to call:
            SetupDiLoadClas sIcon
            the returned HICON can then be used to construct an Icon instance which can
            be used in your treeview.
            To get you started here is a code snip that shows you how to get at the
            device icon using the classGuid....

            static extern int SetupDiLoadClas sIcon(ref Guid classGuid, out IntPtr hIcon,
            out int index);[DllImport("setu papi.dll")]
            ....

            IntPtr hIcon;
            int ix;
            // Here the "DiskDrive" deviceClass GUID
            //4D36E967-E325-11CE-BFC1-08002BE10318
            Guid guid = new Guid("{0x4D36E9 67, 0xE325, 0x11CE,{0xbf, 0xc1, 0x08, 0x00,
            0x2b, 0xe1, 0x03, 0x18}}");
            if(SetupDiLoadC lassIcon(ref guid, out hIcon, out ix) != 0)
            {
            // Ok, Icon found
            // Create graphics object for alteration.
            // Create a new icon from the handle.
            Icon devIcon = Icon.FromHandle (hIcon);
            ...

            }

            Willy.







            Comment

            • [Joe]

              #7
              Re: Get Class ImageList

              Thanks a lot .

              "Willy Denoyette [MVP]" wrote:
              >
              "[Joe]" <Joe@discussion s.microsoft.com wrote in message
              news:F5B3D3F0-EDE2-4325-B84F-00A4B86FD528@mi crosoft.com...
              | what I'm tring to display my devices in treeview and set the image
              depending
              | on the Class type .
              |
              |
              Well as I said, you need to call some more API's.
              First you'll have to call:
              SetupDiClassGui dsFromName
              to get the list of Guid's corresponding to the device class,
              using the right Guid in the list you'll have to call:
              SetupDiLoadClas sIcon
              the returned HICON can then be used to construct an Icon instance which can
              be used in your treeview.
              To get you started here is a code snip that shows you how to get at the
              device icon using the classGuid....
              >
              static extern int SetupDiLoadClas sIcon(ref Guid classGuid, out IntPtr hIcon,
              out int index);[DllImport("setu papi.dll")]
              ....
              >
              IntPtr hIcon;
              int ix;
              // Here the "DiskDrive" deviceClass GUID
              //4D36E967-E325-11CE-BFC1-08002BE10318
              Guid guid = new Guid("{0x4D36E9 67, 0xE325, 0x11CE,{0xbf, 0xc1, 0x08, 0x00,
              0x2b, 0xe1, 0x03, 0x18}}");
              if(SetupDiLoadC lassIcon(ref guid, out hIcon, out ix) != 0)
              {
              // Ok, Icon found
              // Create graphics object for alteration.
              // Create a new icon from the handle.
              Icon devIcon = Icon.FromHandle (hIcon);
              ...
              >
              }
              >
              Willy.
              >
              >
              >
              >
              >
              >
              >
              >

              Comment

              Working...