﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-edog</title><link>http://www.cppblog.com/edog/</link><description>冰冻热狗</description><language>zh-cn</language><lastBuildDate>Fri, 10 Apr 2026 07:10:38 GMT</lastBuildDate><pubDate>Fri, 10 Apr 2026 07:10:38 GMT</pubDate><ttl>60</ttl><item><title>一个简单的Linux驱动程序和Makefile</title><link>http://www.cppblog.com/edog/archive/2013/10/18/203810.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Fri, 18 Oct 2013 14:18:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2013/10/18/203810.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/203810.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2013/10/18/203810.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/203810.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/203810.html</trackback:ping><description><![CDATA[<div><p><strong><span style="color:blue">1</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、源程序</span></strong></p>  <p>//hello.c</p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:gray;">#include&nbsp;&lt;linux/init.h&gt;&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:gray;">#include&nbsp;&lt;linux/module.h&gt;&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">MODULE_LICENSE(</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:blue;">"Dual&nbsp;BSD/GPL"</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">);&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:#006699;">static</span></strong>&nbsp;<strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:seagreen;">int</span></strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;hello_init(</span><strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:#006699;">void</span></strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black;border:none windowtext 1.0pt;padding:0cm;background:white;">)&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">7.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">{&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">8.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;&nbsp;&nbsp;printk(KERN_ALERT&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:blue;">"hello&nbsp;module!\n"</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">);&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">9.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;&nbsp;&nbsp;</span><strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:#006699;">return</span></strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black;border:none windowtext 1.0pt;padding:0cm;background:white;">&nbsp;0;&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">10.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">}&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">11.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">12.&nbsp;</span><strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:#006699;">static</span></strong>&nbsp;<strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:#006699;">void</span></strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;hello_exit(</span><strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:#006699;">void</span></strong><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black;border:none windowtext 1.0pt;padding:0cm;background:white;">)&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">13.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">{&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">14.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;&nbsp;&nbsp;printk(KERN_ALERT&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:blue;">"bye&nbsp;module!\n"</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">);&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">15.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">}&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">16.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">17.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">module_init(hello_init);&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">18.&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">module_exit(hello_exit);&nbsp;&nbsp;</span></p>  </div>  <p>&nbsp;</p>  <p><strong><span style="color:blue">2</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、驱动程序介绍</span></strong></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一个</span>linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">内核模块主要由如下几个部分组成：</span></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>1<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加载函数。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">当通过</span>insmod<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">或</span>modprobe<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">命令加载内核</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时，</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的加载函数会自动被内核运行，完成本</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的相关初始化工作。</span></p>  <p>&nbsp;</p>  <p>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加载函数通过</span>module_init()<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">函数向内核注册。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">卸载函数。</span></p>  <p>&nbsp;</p>  <p>rmmod<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">命令卸载某个模块时，模块的卸载函数会自动被内核执行，完成本模块初始化的相反功能。</span></p>  <p>&nbsp;</p>  <p>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">卸载函数通过</span>module_exit()<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">函数向内核注册。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>3<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">许可声明（必须）</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">许可证</span>license<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">声明描述内核模块的许可权限，如果不声明</span>license<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，模块被加载时，将，收到内核被污染（</span>kernel tainted<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）的警告。</span>linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中可接受的</span>license<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">包括&#8220;</span>GPL<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;，&#8220;</span>GPL v2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;，&#8220;</span>Dual BSD/GPL<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;，&#8220;</span>Dual MPL/GPL<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">&#8221;等。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">多数情况下，内核模块应遵循</span>GPL<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">兼容许可权，</span>2.6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">内核模块最常见的是以</span><span>MODULE_LICENSE("Dual BSD/GPL"</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）语句声明模块采用</span><span>BSD/GPL </span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">双</span>LICENSE<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>4<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）模块参数（可选）</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>5<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）模块到处符号（可选）</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（</span>6<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）模块作者等信息声明（可选），如</span>MODULE_AUTHOR<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（），</span>MODULE_DESCRIPTION<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（），</span>MODULE_ALIAS<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">（）等。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">编译得到</span><strong><span style="color:red">hello.ko</span></strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后</span><strong><span style="color:red">insmod hello.ko</span></strong><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">加载模块，</span><strong><span style="color:red">rmmod hello.ko</span></strong> <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">卸载模块。</span></p>  <p>&nbsp;</p>  <p>&nbsp;</p>  <p>linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">内核的整体结构已经非常庞大，而其包含的组件也非常多，有两种方法把需要的部分都包含在内核中</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一，把所有功能都编译进内核，但这回导致两个问题，生成的内核会特别打，假如要把现在的内核增加或删除功能，将不得不重新编译整个内核。</span></p>  <p>&nbsp;</p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">二，使用模块</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，上述我们写的最简单驱动，就是一个模块</span>module<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，可以随意的增加或删除。</span></p>  <p>&nbsp;</p>  <p><strong><span style="color:blue">3</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、</span><span style="color:blue">Makefile</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">文件</span></strong></p>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">怎样把</span>hello.c<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">源文件编译成</span>helo.ko<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">内核模块呢，同样使用</span>make<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，但这里的</span>Makefile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">与一般的应用程序</span>Makefile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有所不同，驱动</span>Makfile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">要指定内核源代码位置，先看一个简单的驱动</span>Makefile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">：</span></p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">obj-m&nbsp;:=&nbsp;hello.o&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">KERNEL_DIR&nbsp;:=&nbsp;/lib/modules/$(shell&nbsp;uname&nbsp;-r)/build&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">PWD&nbsp;:=&nbsp;$(shell&nbsp;pwd)&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">all:&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;&nbsp;&nbsp;make&nbsp;-C&nbsp;$(KERNEL_DIR)&nbsp;SUBDIRS=$(PWD)&nbsp;modules&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">clean:&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">7.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;&nbsp;&nbsp;rm&nbsp;*.o&nbsp;*.ko&nbsp;*.mod.c&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">8.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">9.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">.PHONY:clean&nbsp;&nbsp;</span></p>  </div>  <p>KERNEL_DIR<span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">为内核源代码</span>build<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录，我们知道，内核存放在</span>/usr/src<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中，</span>/lib/modules<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">其实是连接到这个地方，在</span>shell<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中执行</span>uname -r<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">会得到正在使用的完整内核版本号，这样就选择了适当的内核源码。</span></p>  <p>PWD<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">为源文件</span>hello.c<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">所在目录。</span></p>  <p>make -C <span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;">（大写</span>C<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">）</span> make<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">会进入</span>KERNEL_DIR<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录执行此目录下的</span>Makefile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，然后在返回</span>PWD<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录执行自己写的</span>Makefile<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></p>  <p><strong><span style="color:blue">4</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、在终端中</span><span style="color:blue">make</span></strong></p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">[root@localhost&nbsp;driver]#&nbsp;make&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">make&nbsp;-C&nbsp;/lib/modules/2.6.9-89.ELsmp/build&nbsp;SUBDIRS=/root/linux/driver&nbsp;modules&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">3.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">make[1]:&nbsp;Entering&nbsp;directory&nbsp;`/usr/src/kernels/2.6.9-89.EL-smp-i686'&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">4.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;CC&nbsp;[M]&nbsp;&nbsp;/root/linux/driver/hello.o&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">5.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;Building&nbsp;modules,&nbsp;stage&nbsp;2.&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">6.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;MODPOST&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">7.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;CC&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/root/linux/driver/hello.mod.o&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">8.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;&nbsp;LD&nbsp;[M]&nbsp;&nbsp;/root/linux/driver/hello.ko&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">9.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">make[1]:&nbsp;Leaving&nbsp;directory&nbsp;`/usr/src/kernels/2.6.9-89.EL-smp-i686'</span></p>  </div>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">这样</span>hello.ko<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">驱动模块就产生好了。</span></p>  <p>&nbsp;</p>  <p><strong><span style="color:blue">5</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、</span><span style="color:blue">insmod</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">加载</span></strong></p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&nbsp;[root@localhost&nbsp;driver]#&nbsp;insmod&nbsp;hello.ko</span></p>  </div>  <p><strong><span style="color:blue">6</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、</span><span style="color:blue">lsmod</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">查看模块</span></strong></p>  <p>lsmod<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">一下就会看到</span>hello<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">模块的存在了，并且在系统的日志</span>/var/log/messages<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中会记录模块的输出，也就是</span></p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">printk(KERN_ALERT&nbsp;</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;; color:blue;">"hello&nbsp;module!\n"</span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">);&nbsp;&nbsp;</span></p>  </div>  <p><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">输出的</span><span>hello module</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">！</span></p>  <div style="border:none;border-left:solid #6CE26C 2.25pt; padding:0cm 0cm 0cm 0cm;background:white;margin-left:18.0pt;margin-right:0cm">  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">1.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">&lt;pre&nbsp;name="code"&nbsp;class="plain"&gt;[root@localhost&nbsp;driver]#tail&nbsp;-1&nbsp;/var/log/messages&nbsp;&nbsp;</span></p>  <p align="left" style="margin-left:18.0pt;text-align:left;text-indent:-18.0pt;line-height:13.5pt; background:white;border:none; padding:0cm;"><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;Courier New&quot;;color:#5C5C5C;">2.<span style="font:7.0pt &quot;Times New Roman&quot;">&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size:9.0pt;font-family:&quot;Courier New&quot;;color:black; border:none windowtext 1.0pt;padding:0cm; background:white;">Oct&nbsp;13&nbsp;11:27:07&nbsp;localhost&nbsp;kernel:&nbsp;hello&nbsp;module!&nbsp;</span></p>  </div>  <p><strong><span style="color:blue">7</span></strong><strong><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;;color:blue">、</span><span style="color:blue">rmmod helle </span></strong><strong><span style="font-family: 宋体;Times New Roman&quot;;Times New Roman&quot;; color:blue">卸载</span><span style="color:blue">hello.ko</span></strong></p>  <p>&nbsp;</p></div><img src ="http://www.cppblog.com/edog/aggbug/203810.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2013-10-18 22:18 <a href="http://www.cppblog.com/edog/archive/2013/10/18/203810.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>字符设备驱动基本框架</title><link>http://www.cppblog.com/edog/archive/2010/03/02/108725.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Tue, 02 Mar 2010 06:38:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2010/03/02/108725.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/108725.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2010/03/02/108725.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/108725.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/108725.html</trackback:ping><description><![CDATA[<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">linux</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">init.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">linux</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">module.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">asm</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">gpio.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">linux</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">moduleparam.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">linux</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">mm.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>#include&nbsp;</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">asm</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">io.h</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;DEVICE_NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"LEDS"</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">#define</span><span style="COLOR: #000000">&nbsp;NUM_MAJOR&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;240</span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>MODULE_LICENSE(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Dual&nbsp;BSD/GPL</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;leds_ioctl(</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;inode&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">inode,&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;file&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">file,&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;cmd,&nbsp;unsigned&nbsp;</span><span style="COLOR: #0000ff">long</span><span style="COLOR: #000000">&nbsp;arg)<br><img id=Codehighlighter1_334_347_Open_Image onclick="this.style.display='none'; Codehighlighter1_334_347_Open_Text.style.display='none'; Codehighlighter1_334_347_Closed_Image.style.display='inline'; Codehighlighter1_334_347_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_334_347_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_334_347_Closed_Text.style.display='none'; Codehighlighter1_334_347_Open_Image.style.display='inline'; Codehighlighter1_334_347_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_334_347_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_334_347_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">struct</span><span style="COLOR: #000000">&nbsp;file_operations&nbsp;fops&nbsp;</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&nbsp;<br><img id=Codehighlighter1_388_431_Open_Image onclick="this.style.display='none'; Codehighlighter1_388_431_Open_Text.style.display='none'; Codehighlighter1_388_431_Closed_Image.style.display='inline'; Codehighlighter1_388_431_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_388_431_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_388_431_Closed_Text.style.display='none'; Codehighlighter1_388_431_Open_Image.style.display='inline'; Codehighlighter1_388_431_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_388_431_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_388_431_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;owner:&nbsp;THIS_MODULE,<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;ioctl:&nbsp;leds_ioctl,<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;leds_init(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)&nbsp;<br><img id=Codehighlighter1_463_537_Open_Image onclick="this.style.display='none'; Codehighlighter1_463_537_Open_Text.style.display='none'; Codehighlighter1_463_537_Closed_Image.style.display='inline'; Codehighlighter1_463_537_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_463_537_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_463_537_Closed_Text.style.display='none'; Codehighlighter1_463_537_Open_Image.style.display='inline'; Codehighlighter1_463_537_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_463_537_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_463_537_Open_Text><span style="COLOR: #000000">{&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;注册设备</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;register_chrdev(NUM_MAJOR,&nbsp;DEVICE_NAME,&nbsp;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">fops);&nbsp;&nbsp;&nbsp;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;leds_exit(</span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">)&nbsp;<br><img id=Codehighlighter1_570_624_Open_Image onclick="this.style.display='none'; Codehighlighter1_570_624_Open_Text.style.display='none'; Codehighlighter1_570_624_Closed_Image.style.display='inline'; Codehighlighter1_570_624_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_570_624_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_570_624_Closed_Text.style.display='none'; Codehighlighter1_570_624_Open_Image.style.display='inline'; Codehighlighter1_570_624_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top></span><span id=Codehighlighter1_570_624_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_570_624_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">&nbsp;注销设备</span><span style="COLOR: #008000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top></span><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;unregister_chrdev(NUM_MAJOR,DEVICE_NAME);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</span></span><span style="COLOR: #000000">&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>module_init(leds_init);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>module_exit(leds_exit);&nbsp;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top></span></div>
<img src ="http://www.cppblog.com/edog/aggbug/108725.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2010-03-02 14:38 <a href="http://www.cppblog.com/edog/archive/2010/03/02/108725.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一个串口通讯的类</title><link>http://www.cppblog.com/edog/archive/2007/11/21/37062.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Wed, 21 Nov 2007 02:28:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2007/11/21/37062.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/37062.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2007/11/21/37062.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/37062.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/37062.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: /**//*&nbsp;CommUtils.h&nbsp;*/#ifndef&nbsp;_CommUtils_H__#define&nbsp;_CommUtils_H__class&nbsp;CommUtils&nbsp;&nbsp;{public:&nbsp;&nbsp;&nbsp;&nbsp;bool&nbsp;ReadCom(unsigned&nbsp;char&nbsp;*&nbsp;Re...&nbsp;&nbsp;<a href='http://www.cppblog.com/edog/archive/2007/11/21/37062.html'>阅读全文</a><img src ="http://www.cppblog.com/edog/aggbug/37062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2007-11-21 10:28 <a href="http://www.cppblog.com/edog/archive/2007/11/21/37062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>一些常用函数</title><link>http://www.cppblog.com/edog/archive/2007/11/21/37060.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Wed, 21 Nov 2007 02:12:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2007/11/21/37060.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/37060.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2007/11/21/37060.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/37060.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/37060.html</trackback:ping><description><![CDATA[1、取当前路径<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top><span style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;szCurPath[</span><span style="COLOR: #000000">256</span><span style="COLOR: #000000">];<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;GetModuleFileName(NULL,&nbsp;szCurPath,&nbsp;</span><span style="COLOR: #000000">256</span><span style="COLOR: #000000">);<br><img src="http://www.cppblog.com/Images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">strlen(szCurPath)</span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&gt;=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">--</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_108_179_Open_Image onclick="this.style.display='none'; Codehighlighter1_108_179_Open_Text.style.display='none'; Codehighlighter1_108_179_Closed_Image.style.display='inline'; Codehighlighter1_108_179_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif" align=top><img id=Codehighlighter1_108_179_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_179_Closed_Text.style.display='none'; Codehighlighter1_108_179_Open_Image.style.display='inline'; Codehighlighter1_108_179_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_108_179_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_108_179_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000">(szCurPath[i]&nbsp;</span><span style="COLOR: #000000">==</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">\\</span><span style="COLOR: #000000">'</span><span style="COLOR: #000000">)<br><img id=Codehighlighter1_141_176_Open_Image onclick="this.style.display='none'; Codehighlighter1_141_176_Open_Text.style.display='none'; Codehighlighter1_141_176_Closed_Image.style.display='inline'; Codehighlighter1_141_176_Closed_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><img id=Codehighlighter1_141_176_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_141_176_Closed_Text.style.display='none'; Codehighlighter1_141_176_Open_Image.style.display='inline'; Codehighlighter1_141_176_Open_Text.style.display='inline';" src="http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span id=Codehighlighter1_141_176_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.cppblog.com/Images/dot.gif"></span><span id=Codehighlighter1_141_176_Open_Text><span style="COLOR: #000000">{<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;szCurPath[i</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">break</span><span style="COLOR: #000000">;<br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</span></span><span style="COLOR: #000000"><br><img src="http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</span></span></div>
<br>2、设置CListCtrl风格<br>m_List1.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);<br><br>3、INI文件操作<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;ss[</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">];<br>GetPrivateProfileString(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">COMM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">BaudRate</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">""</span><span style="COLOR: #000000">,&nbsp;ss,&nbsp;</span><span style="COLOR: #000000">20</span><span style="COLOR: #000000">,&nbsp;szCurPath);<br>WritePrivateProfileString(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">COMM</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">BaudRate</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;ss,&nbsp;szCurPath);</span></div>
<br>4、字符串转为16进制<br>
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000">&nbsp;CommUtils::HexToChar(unsigned&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">hex,&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;dwLength,&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">buf)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000">&nbsp;i;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">char</span><span style="COLOR: #000000">&nbsp;s[</span><span style="COLOR: #000000">10</span><span style="COLOR: #000000">];<br>&nbsp;&nbsp;&nbsp;&nbsp;buf[</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">]</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;<br>&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000">(i</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">;&nbsp;i</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">dwLength;&nbsp;i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sprintf(s,&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">%02X&nbsp;</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,&nbsp;hex[i]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strcat(buf,&nbsp;s);<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}</span></div>
<img src ="http://www.cppblog.com/edog/aggbug/37060.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2007-11-21 10:12 <a href="http://www.cppblog.com/edog/archive/2007/11/21/37060.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WIN2000无人值守安装</title><link>http://www.cppblog.com/edog/archive/2006/09/24/12882.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Sun, 24 Sep 2006 08:37:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/09/24/12882.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/12882.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/09/24/12882.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/12882.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/12882.html</trackback:ping><description><![CDATA[
		<p>1：消除WINDOWS2000安装过程中提示输入注册号的过程 <br />　　把WINDOWS2000安装文件拷贝到硬盘，打开i386目录下的setupp.ini，将PID后面的数字改成51873270，那么在整个安装过程中就不会有输入序列号的过程了。 </p>
		<p>2：实现WIN2000的无人值守安装 <br />　　在WINDOWS2000的安装盘上有一个SUPPORTTOOLS的目录，将其中的DEPLOY.CAB拷贝到硬盘，用WINZIP进行解压缩。然后运行其中的setupmgr.exe，WINDOWS2000会根据你的需要建立一个自动批处理文件。以后再安装WINDOWS2000，只需要在DOS下键入winnt［/s:安装文件目录］［/u:自动安装文件名称］例如： <br />　　<font color="#ff0000"><strong>d:i386winnt /B /u:d:setup.txt /s:d:i386</strong></font><br />　　表示使用D:下创建的setup.txt文件对WIN2000进行自动安装。</p>
<img src ="http://www.cppblog.com/edog/aggbug/12882.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-09-24 16:37 <a href="http://www.cppblog.com/edog/archive/2006/09/24/12882.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC6书签管理插件</title><link>http://www.cppblog.com/edog/archive/2006/06/14/8529.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Wed, 14 Jun 2006 01:12:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/06/14/8529.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/8529.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/06/14/8529.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/8529.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/8529.html</trackback:ping><description><![CDATA[原文链接：<a href="http://www.codeproject.com/useritems/BookMarkMgr.asp">http://www.codeproject.com/useritems/BookMarkMgr.asp</a><br /><br /><br />本程序为VC6.0的插件，在IDE中以工具条ToolBar的形式出现，接合Edit工具条使用，实现书签管理的功能（VC本身的书签在关闭文件后会丢失）。<br /><br />此插件有三个按钮，提供打开/保存/编辑书签的功能：<br />1、保存和恢复书签，就算文件关闭了，下次打开时可以恢复书签。<br />2、编辑已存在的书签<br />3、重新打开一个已经关闭的文件时，自动查找原来已经保存的书签并重新设置书签。<br /><br />此插件为DLL，下载链接为：<br />安装如下：<br />1、复制到硬盘某一位置<br />2、打开VC6.0的菜单“Tools-&gt;Customize”，选择“Add-Ins and macro Files”页<br />3、选择“Browse”按钮，选择本插件文件<br /><br />至此，就可以使用了。<img src ="http://www.cppblog.com/edog/aggbug/8529.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-06-14 09:12 <a href="http://www.cppblog.com/edog/archive/2006/06/14/8529.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Asp的时间格式问题</title><link>http://www.cppblog.com/edog/archive/2006/06/11/8411.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Sun, 11 Jun 2006 05:39:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/06/11/8411.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/8411.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/06/11/8411.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/8411.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/8411.html</trackback:ping><description><![CDATA[
		<p>现象：使用ASP取当前时间NOW，返回的时间带有上下午字样，导致无法写入datetime字段。<br />原因：安装了WIN2000番茄乐园版，该版本把系统时间修改为带上下午格式。</p>
		<p>方法1：<br />1、控制面板－－区域和语言选项－－把时间设置为24小时格式。<br />2、打开注册表建立HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\OLEAUT\VarConversionLocaleSetting = 2 (DWORD) <br />备注：OLEAUT 项可能不存在。如果它不存在，则必须先创建该项。<br />3、重新启动IIS。</p>
		<p>问题解决，原理是强制使asp时间使用区域格式。</p>
		<p>
				<br />方法2：<br />查找注册表，全部匹配，把iTime的值全部改成1 。 <br />然后修改服务器系统时间，重起机器完全正常了～<br />（此方法试过好像不行）<br /></p>
<img src ="http://www.cppblog.com/edog/aggbug/8411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-06-11 13:39 <a href="http://www.cppblog.com/edog/archive/2006/06/11/8411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>函数的多参量处理</title><link>http://www.cppblog.com/edog/archive/2006/05/03/6581.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Tue, 02 May 2006 16:29:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/05/03/6581.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/6581.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/05/03/6581.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/6581.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/6581.html</trackback:ping><description><![CDATA[
		<p>函数需要输入多个参数时，象sprintf的用法一样：<br /></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> WriteLog2(</span>
				<span style="COLOR: #0000ff">bool</span>
				<span style="COLOR: #000000"> bNeedTime, </span>
				<span style="COLOR: #0000ff">const</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">char</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #000000">fmt, <img src="http://www.cppblog.com/images/dot.gif" />)<br /><img id="Codehighlighter1_53_353_Open_Image" onclick="this.style.display='none'; Codehighlighter1_53_353_Open_Text.style.display='none'; Codehighlighter1_53_353_Closed_Image.style.display='inline'; Codehighlighter1_53_353_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_53_353_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_53_353_Closed_Text.style.display='none'; Codehighlighter1_53_353_Open_Image.style.display='inline'; Codehighlighter1_53_353_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_53_353_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_53_353_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (fpLog </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> NULL)    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    SYSTEMTIME tm;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    GetLocalTime(</span>
						<span style="COLOR: #000000">&amp;</span>
						<span style="COLOR: #000000">tm);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">if</span>
						<span style="COLOR: #000000"> (bNeedTime)<br /><img id="Codehighlighter1_136_235_Open_Image" onclick="this.style.display='none'; Codehighlighter1_136_235_Open_Text.style.display='none'; Codehighlighter1_136_235_Closed_Image.style.display='inline'; Codehighlighter1_136_235_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_136_235_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_136_235_Closed_Text.style.display='none'; Codehighlighter1_136_235_Open_Image.style.display='inline'; Codehighlighter1_136_235_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_136_235_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.cppblog.com/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_136_235_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        fprintf(fpLog, </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">%02d:%02d:%02d.%03d\t</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">, tm.wHour, tm.wMinute, tm.wSecond, tm.wMilliseconds);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    va_list pArg;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    va_start(pArg, fmt);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    fprintf(fpLog, fmt, pArg);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    va_end(pArg);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    fputs(</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">\n</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">, fpLog);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
		<p> </p>
<img src ="http://www.cppblog.com/edog/aggbug/6581.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-05-03 00:29 <a href="http://www.cppblog.com/edog/archive/2006/05/03/6581.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用VS2003调试ASP的方法和体会</title><link>http://www.cppblog.com/edog/archive/2006/03/15/4157.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Tue, 14 Mar 2006 16:08:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/03/15/4157.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/4157.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/03/15/4157.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/4157.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/4157.html</trackback:ping><description><![CDATA[<P>一直以来，和很多朋友一样，我调试ASP一般都是用editplus，当然，界面部分还是要用用什么frontpage之类的啦。 前段时间写.net项目，装了一个VS.net2003，最近要写一个asp的项目，后来想想用vs20003来试试吧。 <BR>1、打开VS2003，先新建立一个项目，选Visual Basic项目--空WEB项目，名字就叫webproject1，然后可以在资源管理器（是VS的不是windows的）里看到解决方案。 <BR></P>
<P align=center><IMG alt="" hspace=0 src="E:\SMB\ahhge\sample\1.gif" align=baseline border=0></P>
<P><BR>2、点项文件栏上的"项目"，然后点"webproject1属性"--"配置属性"--"调试"里，把"ASP.NET调试"去掉，把"ASP"调试打开。&nbsp;</P>
<P align=center><IMG alt="" hspace=0 src="E:\SMB\ahhge\sample\3.gif" align=baseline border=0></P>
<P><BR>3、右键webproject1，添加新项---WEB窗体，名称叫index.asp（注意名称不是aspx，是asp）。然后可以看到index.asp的HTML处理编辑状态。 <BR>4、把现成的代码全部删除，因为这个是VS自动生成的，当中有些代码是用于asp.net的。然后你就可以自由编写你的ASP页面了。在编写代码的时候，VS会提供一些自动完成功能，很方便的。<BR>&nbsp;<BR>5、现在准备调试。在资源管理器中index.asp，右键，设置为起始页。 <BR>6、然后点工具栏上的"三角"（哈哈，就是播放键）啦，这个就是debug的调试。 <BR>7、然后会跳出一个窗口让你输入本机密码，你就输入你登录用户的密码好了。 IE跳出来了，页面中显示出"VS下调试ASP项目"，哈，调试成功了！ <BR>&nbsp;<BR>结束调试的话你可以在VS里点工具栏上的那个"方块"（就是停止调试），也可以直接把IE关掉，也会自动停止调试的。 </P>
<P>好了，下面来谈谈我的一点经验和体会吧。 <BR>1、VS调试ASP程序比较慢，这个慢是体现在打开IE页面时，所以我建议一般的写代码和编程就在VS里，调试的时候就像以前那样，直接开个IE进行调试。但是，对于复杂的问题，涉及到流程错误的，我还是喜欢在VS里用单步调试，用F9在某个地方设个断点，然后用F10进行跟踪，这样对于程序的流程，变量值都可以很好的看出来（这些调试技巧大家可以参考一些asp.net方面的书，或是以前的VS6的书也行），解决复杂问题也就快了许多。 </P>
<P>2、建立新页面文件时，我建议还是直接进到目录中，然后建立好，再到VS的资源管理器中，用添加现有项进行导入，这样建立的文件没有垃圾代码。 </P>
<P>3、VS2003可以提供很好的自动完成功能，大家可以充分的利用。 </P>
<P>4、VS.net可以实现控件拖放加载，你可以在左边的"工具箱"--"HTML"里可以看到，直接点了，按住MOUSE左键直接拖到你想添加的地方。由于VS.net是针对.net的，所以一些HTML控件的属性中也体现了这些，比如"runat"这样的属性，在asp中是根本用不起来的。不过大多数控件的属性都是可以的，而且可以在"设计"视图下进行方便的设置属性好啦就说这么多吧. 大家可以慢慢体会：）有人说DW不错，我没有用过，不知道怎么样，也有人说DW有不少垃圾代码，呵呵：P </P>
<P>本文摘录自：<A href="http://www.81819.com/Article/2004-3-1/news2004-6-2535008925.html">http://www.81819.com/Article/2004-3-1/news2004-6-2535008925.html</A></P>
<P>&nbsp;</P><img src ="http://www.cppblog.com/edog/aggbug/4157.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-03-15 00:08 <a href="http://www.cppblog.com/edog/archive/2006/03/15/4157.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C/C++程序内存泄漏检测</title><link>http://www.cppblog.com/edog/archive/2006/02/15/3268.html</link><dc:creator>冰冻热狗</dc:creator><author>冰冻热狗</author><pubDate>Wed, 15 Feb 2006 06:36:00 GMT</pubDate><guid>http://www.cppblog.com/edog/archive/2006/02/15/3268.html</guid><wfw:comment>http://www.cppblog.com/edog/comments/3268.html</wfw:comment><comments>http://www.cppblog.com/edog/archive/2006/02/15/3268.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/edog/comments/commentRss/3268.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/edog/services/trackbacks/3268.html</trackback:ping><description><![CDATA[<P><STRONG>1. 包含头文件和定义：<BR></STRONG>#define _CRTDBG_MAP_ALLOC<BR>#include &lt;stdlib.h&gt;<BR>#include &lt;crtdbg.h&gt;<BR>如果定义了_CRTDBG_MAP_ALLOC，打印出来的是文件名和行数等更加直观的信息。<BR><STRONG><BR>2. 方法一<BR></STRONG>在程序入口写几个语句：<BR>&nbsp;int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );<BR>&nbsp;tmpFlag |= _CRTDBG_LEAK_CHECK_DF;<BR>&nbsp;_CrtSetDbgFlag( tmpFlag );<BR>程序退出时，如果发现有内存泄漏，会自动在DEBUG OUTPUT窗口和DebugView中输出内存泄漏信息。<BR><BR><STRONG>3. 方法二<BR></STRONG>在程序任何地方用以下语句：<BR>_CrtDumpMemoryLeaks();<BR>随时检测打印内存泄漏信息，如果有的话。不过此用法有个局限，对于一些全局函数，如果初始化时申请了内存，到程序结束时候才释放，此函数会一直把新申请的内存当作泄漏来对待。<BR><BR><STRONG>4. 方法三</STRONG><BR>使用_CrtMemCheckpoint方法，在某段程序中统计泄漏信息。如下：<BR>&nbsp;_CrtMemState s1, s2, s3;<BR>&nbsp;_CrtMemCheckpoint( &amp;s1 );<BR>&nbsp;<BR>&nbsp;// 程序段1：DO SOMETHING</P>
<P>&nbsp;_CrtMemCheckpoint( &amp;s2 );<BR>&nbsp;if ( _CrtMemDifference( &amp;s3, &amp;s1, &amp;s2) ) <BR>&nbsp;&nbsp;_CrtMemDumpStatistics( &amp;s3 );</P>
<P>可以统计程序段1中是否发生了内存泄漏。</P><img src ="http://www.cppblog.com/edog/aggbug/3268.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/edog/" target="_blank">冰冻热狗</a> 2006-02-15 14:36 <a href="http://www.cppblog.com/edog/archive/2006/02/15/3268.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>