469,916 Members | 2,432 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

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

How I can call this API from C# ?

Thanks
Joe
Sep 3 '06 #1
6 4767

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.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
| 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.
Sep 3 '06 #2
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]" <Jo*@discussions.microsoft.comwrote in message
news:15**********************************@microsof t.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
| 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.
Sep 4 '06 #3

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:9E**********************************@microsof t.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 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.


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

"Willy Denoyette [MVP]" wrote:
>
"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:9E**********************************@microsof t.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 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.


Sep 4 '06 #5

"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.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:
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.



Sep 4 '06 #6
Thanks a lot .

"Willy Denoyette [MVP]" wrote:
>
"[Joe]" <Jo*@discussions.microsoft.comwrote in message
news:F5**********************************@microsof t.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:
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.



Sep 5 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by A. Solomon | last post: by
2 posts views Thread by Bob C. | last post: by
7 posts views Thread by Andrew Christiansen | last post: by
4 posts views Thread by Just Me | last post: by
2 posts views Thread by =?Utf-8?B?S2VuTg==?= | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.