转载自:http://www.codeproject.com/KB/system/divingsysprog3.aspx

/Files/kk1230/.net Diving into System Programming/SDManExe.zip

/Files/kk1230/.net Diving into System Programming/SDManSource.zip

Introduction

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.

Summary

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.

References

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

  • Device Installation
  • Configuration Manager
  • Device Management

License

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

转载于:https://www.cnblogs.com/kk1230/archive/2009/11/25/1610762.html

.net 深入系统编程(三)相关推荐

  1. Linux系统编程三:使用man查看帮助文档

    目录 一.概述 二.使用方法 三.手册分页 四.总结 一.概述 在前两篇延时时间和LED控制中,都用到了系统函数.随着学习深入,用到的函数越来越多,如何记住每个函数的原型和头文件?一些常用的函数随着印 ...

  2. Linux系统编程(三) --进程间通信

    文章目录 1 进程间通信总览 1.1 进程间如何通信 1.2 Linux IPC 分类 1.3 Linux IPC常用手段 2 无名管道 2.1 pipe 函数 2.2 用pipe进行进程间通信 3 ...

  3. IA-32系统编程指南 - 第三章 保护模式的内存管理【1】

    第三章 保护模式的内存管理[1] [作者:lion3875 原创文章 参考文献<Intel 64 and IA-32 system programming guide>] IA-32保护模 ...

  4. Linux/Unix系统编程手册 第三章:系统编程概念

    本章介绍系统编程的基础概念和一些后续章节用到的函数及头文件,并说明了可移植性问题. 系统调用是受控的内核入口,通过系统调用,进程可以请求内核以自己的名义去执行某些动作,比如创建子进程,执行I/O操作, ...

  5. Linux系统编程(三)进程间的通信

    Linux系统编程(三)进程间的通信 一.为什么需要进程之间的通信(IPC)? 二.管道 1.概念 2.特质 3.原理 4.局限性 5.代码 2.读入数据 三.共享存储映射 注意事项 父子进程通信 一 ...

  6. alin的学习之路(Linux系统编程:三)(vim,gcc,库,gdb)

    alin的学习之路(Linux系统编程:三)(vim,gcc,库,gdb) 1.vim的使用 vim有三种模式:命令模式,末行模式,编辑模式 光标的移动[命令模式] h 向左 ,j 向下,k 向上,l ...

  7. linux系统发送信号的系统调用是,linux系统编程之信号:信号发送函数sigqueue和信号安装函数sigaction...

    信号发送函数sigqueue和信号安装函数sigaction sigaction函数用于改变进程接收到特定信号后的行为. sigqueue()是比较新的发送信号系统调用,主要是针对实时信号提出的(当然 ...

  8. C语言嵌入式系统编程修炼之道——性能优化篇

    C语言嵌入式系统编程修炼之道--性能优化篇 作者:宋宝华  e-mail:[email]21cnbao@21cn.com[/email] 1.使用宏定义 在C语言中,宏是产生内嵌代码的唯一方法.对于嵌 ...

  9. Linux系统编程——进程基础知识

    Linux系统编程--进程基础知识 1.程序和进程 程序,是指编译好的二进制文件,在磁盘上,不占用系统资源(cpu.内存.打开的文件.设备.锁-) 进程,是一个抽象的概念,与操作系统原理联系紧密.进程 ...

最新文章

  1. c#_限制TextBox输入类型仅可为“-” “.” 数字
  2. python的函数式编程玩法+年末小感
  3. php未正确拼写字 css,前端Bug解决方案
  4. 【ThinkPHP系列篇】ThinkPHP框架使网页能够在浏览器中访问(二)
  5. Maven私服搭建(Nexus Repository Manager 3)
  6. 计算机组成原理 第三章【存储系统】课后作业解析【MOOC答案】
  7. Qt中QTableWidget用法总结
  8. 步步为营 SharePoint 开发学习笔记系列 七、SharePoint Timer Job 开发
  9. 【Cadence】制作AD630焊盘SOIC_20
  10. 中小学教师计算机培训心得,小学教师信息技术培训心得体会2篇
  11. 在繁杂的网页中揪出email地址
  12. 订单信息表和订单明细表
  13. python实验心得_Python实训周总结
  14. calcite parser
  15. 南方电网电费充值源码文档
  16. sfsdfsdffsdf
  17. C#,JAVA人民币小写转大写
  18. 《Python程序设计》实验四 Python综合实践实验报告
  19. java-堆里面的分区:Eden,survival(from) to,老年代,各自的特点。
  20. 创世纪元java游戏,创世纪元

热门文章

  1. zoj 3809 枚举水题 (2014牡丹江网赛 A题)
  2. 使用secure CRT的SFTP在LINUX与WINDOWS下交换文件
  3. 技术帖:砖混、砖木、钢混、板楼、塔楼、框架、框架剪力墙等概念之区别优劣...
  4. 浅析 public static void main(String[] args)
  5. ThinikPHP 前端URL模式
  6. 甲骨文正式宣布将Java EE移交给Eclipse基金会
  7. 摩尔定律会死亡吗 芯片到底可以变得有多小
  8. Java web.xml 配置详解
  9. keytool 错误:java.to.FileNotFoundException:
  10. 如何从技术牛人升阶为管理牛人