Hello Scott,
Thanks for your post. As I understand, you want to call SetupDi functions
to get hardware information from .NET Managed code. Please correct me if
there is any misunderstanding. Now I'd like to share the following
information with you:
1. Since SetupDi are unmanaged APIs, we have to use Platform Invoke to call
these functions in .NET. Please refer to the following MSDN article for
detailed information on P/Invoke:
Consuming Unmanaged DLL Functions
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconconsumingunmanageddllfunctions.asp
One thing difficult is interop marshaling which governs how data is passed
in method arguments and return values between managed and unmanaged memory
during calls. Especially when we pass sophiscated data structures and
arrays. I believe the article below is very helpful:
Marshaling Data with Platform Invoke
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconmarshalingdatawithplatforminvoke.asp?frame=tr ue
As you know, SetupDi functions are documented in DDK, please download
appropriate DDK from Microsoft:
Microsoft Windows Driver Development Kits
http://www.microsoft.com/whdc/ddk/winddk.mspx
Regards,
2. In .NET environment, I strongly recommend you using classes under
System.Management to access WMI. WMI (Windows Management Instrumentation)
is a scalable system management infrastructure that uses a single
consistent, standards-based, extensible, object-oriented interface. WMI
provides you with a standard way to interact with system management
information and the underlying WMI APIs. For example, the following code
snippet demonstrates enumerating PnP registered devices using WMI class
Win32_PnPentity:
//-------------------code snippet--------------------
using System;
using System.Management;
class App {
public static void Main() {
ManagementPath path = new ManagementPath();
ManagementClass devs = null;
path.Server = "."; // local machine
path.NamespacePath = @"root\CIMV2";
path.RelativePath = @"Win32_PnPentity";
using(devs = new ManagementClass(new ManagementScope(path), path, new
ObjectGetOptions(null, new TimeSpan(0,0,0,2), true)))
{
ManagementObjectCollection moc = devs.GetInstances();
foreach(ManagementObject mo in moc) {
PropertyDataCollection devsProperties = mo.Properties;
foreach (PropertyData devProperty in devsProperties ) {
Console.WriteLine("Property = {0}\t Value = {1}",
devProperty.Name, devProperty.Value);
}
}
}
}
}
//-------------------------end of---------------------------
Please refer to the following MSDN articles for detailed information:
System.Management Lets You Take Advantage of WMI APIs within Managed Code
http://msdn.microsoft.com/msdnmag/is...n/default.aspx
Managing Applications Using WMI
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconmanagingapplicationsusingwmi.asp
Computer System Hardware Classes
http://msdn.microsoft.com/library/de...us/wmisdk/wmi/
computer_system_hardware_classes.asp
3. By the way, it would be best to post WMI questions in the following
newsgroup.
microsoft.public.win32.programmer.wmi
Hope this helps.
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! --
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.