Click here to Skip to main content
Click here to Skip to main content

.NET - Diving into System Programming - Part 3

, 10 Mar 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
Device configuration using C# (Part 3). Device resources - IRQ, DMA, etc.


In this last part, you will see a Windows Forms application. This application can enumerate device classes, enumerate devices from device classes and show information about device resources. You can download source code for Borland C# Builder and Visual Studio C#.

Device resources

Every device can use some hardware resources for its work. There are four standard types of resources:

  • Memory Resource
  • I/O Port Resource
  • DMA Resource
  • Interrupt Resource

The type of resources used depends on the device. For example, serial port uses I/O Port Resource and Interrupt Resource. Display (Video adapter), as a rule, uses I/O Port Resource, Interrupt Resource and Memory Resource. Device Manager can show information about resources for every device from configuration.

So how to get information about resources.

  • Get class Guid using device class name (SetupDiClassGuidsFromNameA function)
  • Get device info set for device class (SetupDiGetClassDevsA function)
  • Get device info data for every device (SetupDiGetClassDevsA function, second parameter for this function is sequential device index in the device class, so call this function in circle with device index = 0, 1, etc.).
  • Get information about current configuration (CM_Get_First_Log_Conf function)
  • Get resource descriptor from current configuration (CM_Get_Next_Res_Des function, do this and follow steps for every resource till they exist)
  • Get information about size of resource data (CM_Get_Res_Des_Data_Size function)
  • Get resource data (CM_Get_Res_Des_Data function)
  • Marshal resource data in suitable structures (class Marshal, methods PtrToStructure; structure IntPtr, method ToInt32 and vice versa to IntPtr)

You can find details in the source code for the application that you see on the next picture:

Configuration and Device Manager

Configuration Manager includes functions from cfgmgr32.dll and Device Management functions include most functions from setupapi.dll. Using these functions, you can recreate system Device Manager (if you really need it) and a lot other things. You can use it for Windows 98/Me/NT4/2000/XP with unmanaged code as well as managed. You can't use this way for early Windows versions. In Windows 95, Configuration Manager is not a DLL but a VXD driver. And I don't know about using it for Windows Server 2003.

What about WMI

WMI is really a very useful and suitable thing. It was developed for such tasks that I examine in these articles also. But WMI is native beginning from Windows 2000. If you want to use WMI for Windows 98/NT4, you need to install WMI Core. Here there is a problem, at least I had a problem. WMI Core is localized but there is no WMI Core for Russian Windows98, for example. Beside this, WMI is not magus, WMI also uses Win32 API to access device configuration.

Registry, Registry and Registry again

Really, Windows Registry is a Central Windows database for all system information. So even if we use cfgmgr32.dll or/and setupapi.dll, anyway in most cases we work with Registry data. It means if you know where to find configuration data in Registry and how to collect and marshal them, you can access data via Win32 Registry API. Of course, you can find even computer name using this API directly but I suppose that GetComputerName Win32 API function is more suitable.


As you see, some ways exist to get information about device configuration. I examined only one of these. And it is the end of my story about "child language" C#, P/Invoke and device configuration.


Information about Configuration and Device Managers are on Microsoft Library site.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vladimir Afanasyev
Web Developer
Ukraine Ukraine
I am C++ Builder developer.
I am interesting in WMI, Shell, some deep
COM interface. Beside these I am Brainbench
Win32 API Master.
Now I very like Microsoft .NET and C#. I made some firsts OPOS drivers for Ukrainian fiscal printers.

Comments and Discussions

QuestionEnumerating Devices Used by Each Process? PinmemberDarwin Airola31-May-13 7:40 
QuestionHow can I get the drive letter from a logical drive PinmemberMember 919569225-Dec-12 11:33 
GeneralMy vote of 5 PinmemberCoffeeholic27-Dec-10 2:11 
Questiondefault device Pinmemberesovan26-Sep-09 13:06 
QuestionOPOS LineDisplay problem Pinmemberrobercik71326-Jan-09 23:30 
AnswerRe: OPOS LineDisplay problem PinmemberVladimir Afanasyev30-Jan-09 2:38 
QuestionOPOS drivers for fiscal printers PinmemberFabio Campos21-Nov-08 9:55 
AnswerRe: OPOS drivers for fiscal printers PinmemberVladimir Afanasyev23-Nov-08 11:54 
GeneralPort Number Pinmemberserkan197717-Nov-08 18:57 
QuestionTrying to write OPOS Line Display Service Object PinmemberEsko28-May-08 23:23 
GeneralDevice disable just on run time ... PinmemberH.R14-Sep-07 1:48 
Question[Help!] OPOS Service Object Pinmemberwallence11-Jul-07 16:41 
AnswerRe: [Help!] OPOS Service Object PinmemberVladimir Afanasyev4-Oct-07 0:03 
GeneralRe: [Help!] OPOS Service Object Pinmemberwallence16-Oct-07 16:36 
GeneralRe: [Help!] OPOS Service Object PinmemberVladimir Afanasyev16-Oct-07 23:45 
GeneralOPOS Service object source code Pinmemberkarsin20-Apr-07 2:04 
Questionhow to get more device details? Pinmemberpepepaco17-Feb-07 7:17 
AnswerRe: how to get more device details? PinmemberVladimir Afanasyev23-Feb-07 4:59 
GeneralDisable/Re-enable hardware Pinmembergee@factorymaster21-Apr-06 5:57 
GeneralEnumeration PinmemberDizzzzy26-Feb-06 10:02 
QuestionHow to Write Service Object for POS Devices Pinmemberkurella22-Feb-06 19:36 
AnswerRe: How to Write Service Object for POS Devices PinmemberVladimir Afanasyev22-Feb-06 21:55 
GeneralRe: How to Write Service Object for POS Devices Pinmemberkurella22-Feb-06 22:44 
GeneralRe: How to Write Service Object for POS Devices PinmemberVladimir Afanasyev27-Feb-06 23:47 
GeneralRe: How to Write Service Object for POS Devices Pinmemberkurella28-Feb-06 0:00 
GeneralRe: How to Write Service Object for POS Devices Pinmemberostyle7220-May-13 0:16 
QuestionDevelop Driver for Network Interface PinmemberRedaemon11-Jan-06 9:41 
AnswerRe: Develop Driver for Network Interface PinmemberVladimir Afanasyev11-Jan-06 22:15 
GeneralDrivers Pinmemberjonnyboy99991-Sep-05 14:07 
GeneralRe: Drivers PinmemberVladimir Afanasyev2-Sep-05 0:18 
GeneralRe: Drivers Pinmemberjonnyboy99992-Sep-05 8:39 
GeneralRe: Drivers PinmemberVladimir Afanasyev7-Sep-05 1:28 
GeneralRe: Drivers Pinmemberjonnyboy99998-Sep-05 7:27 
QuestionPlug and play device removing ? Pinmemberbuffalo00713-Dec-04 2:42 
AnswerRe: Plug and play device removing ? PinmemberVladimir Afanasyev13-Dec-04 4:15 
GeneralDevice anable/disable Pinmembermrt200324-Nov-04 23:10 
GeneralRe: Device anable/disable PinmemberVladimir Afanasyev24-Nov-04 23:42 
GeneralRe: Device anable/disable Pinmembermrt200325-Nov-04 2:24 
GeneralRe: Device anable/disable PinmemberVladimir Afanasyev25-Nov-04 3:22 
GeneralRe: Device anable/disable Pinsussiberendes6-Jan-05 6:09 
GeneralRe: Device anable/disable PinmemberVladimir Afanasyev10-Jan-05 2:41 
GeneralRe: Device anable/disable Pinmemberkueihung7-Apr-05 2:58 

I serarch this function in MSDN but MSDN's comment is "Do not use this function". Is there any other function can do the same thing?
GeneralRe: Device anable/disable PinmemberIan_00111-Apr-05 4:22 
GeneralRe: Device enable/disable - Parameters wrong PinmemberNigelAston18-Apr-05 23:01 
AnswerRe: Device enable/disable - Parameters wrong PinmemberHiAle3-Dec-05 13:12 
GeneralRe: Device enable/disable - Parameters wrong Pinmembergumigyuri6-Mar-06 23:26 
GeneralRe: Device enable/disable - Parameters wrong PinmemberBalagopal Ambalakkat7-Jan-07 18:47 
GeneralRe: Device enable/disable - Parameters wrong PinmemberJoe Henrich13-Feb-07 23:38 
GeneralRe: Device anable/disable PinmemberCPfx3000se31-May-06 7:27 
GeneralRe: Device anable/disable PinmemberIan_00112-Jul-06 3:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 11 Mar 2004
Article Copyright 2004 by Vladimir Afanasyev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid