转载自: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. YII2框架表单-model(验证)-HTML_help部件 URL_help部件 以注册页面为实例
  2. c 语言字符串转二进制,在C ++中将字符串转换为二进制序列
  3. 今天开始学OpenWRT - 21/03/8
  4. 2019年信息安全工程师备考技巧
  5. 数据结构之基于Java的最优二叉树实现
  6. pacs系统服务器配置,pacs系统服务器配置
  7. VS2010上连接SQLite数据库
  8. 美团笔试题——正则序列
  9. Chapter 1: 使用引用类型
  10. Spring之IOC容器
  11. 控制台接收信息转发_微信多群转播能够起到什么作用?微信群聊录制课程语音转发多群怎么操作?...
  12. java元组_Java中元组的使用
  13. python 乡镇轮廓 高德_Python爬虫终极解决方案-以获取高德地图小区边界为例
  14. 网络配置中rc.d-rc6.d的说明
  15. matlab画图常见问题,matlab常见问题集
  16. 计算错误可以用计算机ac,计算器AC是什么键?
  17. SDN之NOS概述——云原生
  18. 【物联网】14.物联网设备控制器选择 - 单片机(MCU)
  19. Oracle获取上一年的时间
  20. 【android】gradle的applicationId的思考,历史遗留问题,千万要在项目构建前就确定好id名,避免后续的迭代导致问题

热门文章

  1. Delphi10 安装Graphics32
  2. unity3d 随机生成地形之随机山脉
  3. 关于EXCEL数据导入到SQLServer中字段存在NULL的问题
  4. 提高C#编程水平的50个技巧
  5. 2018年中国C++大会详细日程+报名
  6. CentOS7 0安装jdk + tomcat
  7. 详细透彻的分析DM9000网卡驱动程序(3)
  8. windows 路由设置问题
  9. Wigner-Ville分布算法的C++实现
  10. Eclipse 中 按 Ctrl+Shift+F 格式化代码时每行容纳的字符数