Get Class ImageList

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
SetupDiGetClassImageList(
OUT PSP_CLASSIMAGELIST_DATA ClassImageListData);

How I can call this API from C# ?

Thanks
Joe
 
| 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
| SetupDiGetClassImageList(
| OUT PSP_CLASSIMAGELIST_DATA ClassImageListData);
|
| 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("setupapi.dll")]
static extern int SetupDiGetClassImageList(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
SetupDiDestroyClassImageList).

Willy.
 
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
 
| 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 SetupDiDrawMiniIcon using
this import definition:

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

Willy.
 
| 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:
SetupDiClassGuidsFromName
to get the list of Guid's corresponding to the device class,
using the right Guid in the list you'll have to call:
SetupDiLoadClassIcon
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 SetupDiLoadClassIcon(ref Guid classGuid, out IntPtr hIcon,
out int index);[DllImport("setupapi.dll")]
....

IntPtr hIcon;
int ix;
// Here the "DiskDrive" deviceClass GUID
//4D36E967-E325-11CE-BFC1-08002BE10318
Guid guid = new Guid("{0x4D36E967, 0xE325, 0x11CE,{0xbf, 0xc1, 0x08, 0x00,
0x2b, 0xe1, 0x03, 0x18}}");
if(SetupDiLoadClassIcon(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top