﻿<?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++博客-wizardjk-随笔分类-Visual C++</title><link>http://www.cppblog.com/wizardjk/category/18275.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 02 Dec 2011 13:06:14 GMT</lastBuildDate><pubDate>Fri, 02 Dec 2011 13:06:14 GMT</pubDate><ttl>60</ttl><item><title>将自己写的经常复用的类封装成dll/lib的方法</title><link>http://www.cppblog.com/wizardjk/archive/2011/08/06/152678.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Sat, 06 Aug 2011 14:17:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/08/06/152678.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/152678.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/08/06/152678.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/152678.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/152678.html</trackback:ping><description><![CDATA[<div>如果你的工作长期与某个领域相关，比如说长期做直接体绘制(DVR)方面的开发，那么你可能经常使用自己的传递函数类，如果每一个工程你都把传递函数类的.h和.cpp文 <p>件添加进去会比较麻烦，其实，我们可以像使用opengl的库那样来用你自己的类，做法就是把你写好的类封装成dll，具体做法如下：&nbsp;</p> <p>第一步：制作dll</p> <p>&nbsp;&nbsp; &nbsp; 利用VC6新建工程时选择win32 dynamic-Link Library(空的工程)，然后添加头文件和cpp文件。假设你要封装的类的名成是TransferFunction，添加头文件</p> <p>TransferFunction.h和TransferFunction.cpp到工程中。并将TransferFunction.h修改成：&nbsp;</p> class __declspec(dllexport) TransferFunction<br /> {<br /> &nbsp;&nbsp; &nbsp; &nbsp;...<br /> <p>}</p> <p>从而说明以后从dll要被导出的类是哪一个。这样编译完就会产生TransferFunction.dll和TransferFunction.lib两个文件。</p> 第二步：如何使用这个dll<br /> <p>&nbsp;&nbsp; &nbsp; &nbsp;当已经生成dll后，有两种方法可以在其它程序中调用dll中的类和成员函数：</p> <p>方法一：</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;1)把TransferFunction.dll和TransferFunction.lib复制到调用程序的执行路径下，注意不是debug路径下。</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;2)在project-&gt;setting-&gt;link里添加TransferFunction.lib（或者用#pragma comment(lib, "TransferFunction.lib") ）</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;3)把TransferFunction.h中的__declspec(dllexport)改成__declspec(dllimport)</p> <p>然后复制到调用程序的执行路径下。</p> &nbsp;&nbsp; &nbsp; &nbsp;4)最后在主程序中就可以通过包含TransferFunction.h来使用TransferFunction类和它的成员函数。&nbsp;<br /> 方法二（推荐）：<br /> &nbsp;&nbsp; &nbsp; &nbsp;  在方法一中，你每次建立一个工程都需要把 TransferFunction.dll,TransferFunction.lib,TransferFunction.h三个文件拷贝到工程里面 去，事实上这只发挥了dll对类的代码保护的功能，并没有多大的减轻编程人员的工作量，下面的方法可以减少编程人员的工作量，具体步骤：<br /> 1：将TransferFunction.dll扔到windows/system32下<br /> 2：将.TransferFunctionlib扔到VC的lib目录里<br /> 3：将方法一中的TransferFunction.h扔到VC的include目录里<br /> 4：同方法一的最后一步。<br /> &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; 以后你就可以像使用Opengl的glut、glui等库一样使用你自己封装的一个经常复用的类了。  </div><img src ="http://www.cppblog.com/wizardjk/aggbug/152678.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-08-06 22:17 <a href="http://www.cppblog.com/wizardjk/archive/2011/08/06/152678.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MFC  TIMER</title><link>http://www.cppblog.com/wizardjk/archive/2011/07/06/150276.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Wed, 06 Jul 2011 01:49:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/07/06/150276.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/150276.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/07/06/150276.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/150276.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/150276.html</trackback:ping><description><![CDATA[<div><u><strong>1.1使用系统提供的OnTimerSet函数</strong></u><br />Timer(m_hWnd,1,1000,NULL); //一个1秒触发一次的定时器<br />在MFC程序中SetTimer被封装在CWnd类中，调用就不用指定窗口句柄了<br /> <p style="color: #000080">于是SetTimer函数的原型变为： <br /> </p><p style="color: #000080">UINT SetTimer(UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT *lpfnTimer)(HWND,UINT ,YINT ,DWORD)) <br /> </p><p style="color: #000080">当使用SetTimer函数的时候，就会生成一个计时器。函数中nIDEvent指的是计 时器的标识，也就是名字。nElapse指的是时间间隔，也就是每隔多长时间触发一次事件。第三个参数是一个回调函数，在这个函数里，放入你想要做的事情 的代码，你可以将它设定为NULL，也就是使用系统默认的回调函数，系统默认认的是onTime函数。这个函数怎么生成的呢？你需要在需要计时器的类的生 成onTime函数：在ClassWizard里，选择需要计时器的类，添加WM_TIME消息映射，就自动生成onTime函数了。然后在函数里添加代 码，让代码实现功能。每隔一段时间就会自动执行一次。 <br /> </p><p style="color: #000080">例： <br /> </p><p style="color: #000080">SetTimer(1,1000,NULL); <br /> </p><p style="color: #000080">1:计时器的名称； <br /> </p><p style="color: #000080">1000：时间间隔，单位是毫秒； <br /> </p><p style="color: #000080">NULL:使用onTime函数。 <br /> </p><p style="color: #000080">当不需要计时器的时候调用KillTimer(nIDEvent); <br /> </p>例如：KillTimer(1);<br /><div><p style="color: #000080"><u><strong>1.2 调用回调函数</strong></u><br /> </p><p style="color: #000080">此方法首先写一个如下格式的回调函数<br /> </p><p style="color: #000080">void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime);<br />然后再用SetTimer(1,100,TimerProc)函数来建一个定时器，第三个参数就是回调函数地址。<br /> </p><p style="color: #000080">二. 或许你会问，如果我要加入两个或者两个以上的 timer怎么办？ <br /> </p><p style="color: #000080">继续用SetTimer函数吧，上次的timer的ID是1，这次可以是2，3，4。。。。 <br /> </p><p style="color: #000080">SetTimer(2,1000,NULL); <br /> </p><p style="color: #000080">SetTimer(3,500,NULL); <br /> </p><p style="color: #000080">嗯，WINDOWS会协调他们的。当然onTimer函数体也要发生变化，要在函数体内添加每一个timer的处理代码： <br /> </p><p style="color: #000080">onTimer(nIDEvent) <br /> </p><p style="color: #000080">{ <br /> </p><p style="color: #000080">switch(nIDEvent) <br /> </p><p style="color: #000080">{ <br /> </p><p style="color: #000080">case 1:........; <br /> </p><p style="color: #000080">break; <br /> </p><p style="color: #000080">case 2:.......; <br /> </p><p style="color: #000080">break; <br /> </p><p style="color: #000080">case 3:......; <br /> </p><p style="color: #000080">break; <br /> </p><p style="color: #000080">} <br /> </p>}</div></div><img src ="http://www.cppblog.com/wizardjk/aggbug/150276.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-07-06 09:49 <a href="http://www.cppblog.com/wizardjk/archive/2011/07/06/150276.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC对话框禁止关闭按钮和禁止任务管理中关闭进程</title><link>http://www.cppblog.com/wizardjk/archive/2011/07/04/150154.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Mon, 04 Jul 2011 14:19:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/07/04/150154.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/150154.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/07/04/150154.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/150154.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/150154.html</trackback:ping><description><![CDATA[<div><div>     <p>1.BOOL C***Dlg::OnInitDialog()</p> <p>{</p> <p>&nbsp;&nbsp;&nbsp; //禁止关闭对话框<br />&nbsp;CMenu* pMenu = this-&gt;GetSystemMenu(FALSE);<br />&nbsp;pMenu-&gt;ModifyMenu(SC_CLOSE,MF_BYCOMMAND | MF_GRAYED );<br />&nbsp;&nbsp;&nbsp; //禁止在任务管理器中关闭进程<br />&nbsp;SetTimer(1,m_nTimer,NULL);//设置1号定时器，循环调用stopKillProcess()函数，禁止任务管理器中关闭进程</p> <p>}</p> <p>&nbsp;</p> <p>2.void CClientTracerDlg::stopKillProcess()//禁止任务管理器中关闭进程<br />{<br />&nbsp;HWND&nbsp;hwnd;<br />&nbsp;int&nbsp;&nbsp;iItem=0;<br />&nbsp;LVITEM&nbsp;lvitem, *plvitem;<br />&nbsp;char&nbsp;ItemBuf[512],*pItem;<br />&nbsp;DWORD&nbsp;PID;<br />&nbsp;HANDLE&nbsp;hProcess;<br />&nbsp;<br />&nbsp;// 查找任务管理器ListView窗口句柄<br />&nbsp;hwnd=::FindWindow("#32770",_T("Windows 任务管理器"));<br />&nbsp;hwnd=::FindWindowEx(hwnd,0,"#32770",0);<br />&nbsp;hwnd=::FindWindowEx(hwnd,0,"SysListView32",0);<br />&nbsp;<br />&nbsp;// Windows任务管理器尚未启动则返回<br />&nbsp;if (!hwnd)&nbsp;<br />&nbsp;&nbsp;return;<br />&nbsp;else<br />&nbsp;{<br />&nbsp;&nbsp;// 没有指定目标进程则返回<br />&nbsp;&nbsp;iItem=::SendMessage(hwnd,LVM_GETNEXTITEM,-1,LVNI_SELECTED);<br />&nbsp;&nbsp;if (iItem==-1)&nbsp;<br />&nbsp;&nbsp;&nbsp;return;<br />&nbsp;&nbsp;else<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;// 获取进程句柄操作失败则返回<br />&nbsp;&nbsp;&nbsp;GetWindowThreadProcessId(hwnd, &amp;PID);<br />&nbsp;&nbsp;&nbsp;hProcess=OpenProcess(PROCESS_ALL_ACCESS,false,PID);<br />&nbsp;&nbsp;&nbsp;if (!hProcess)<br />&nbsp;&nbsp;&nbsp;&nbsp;return;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;plvitem=(LVITEM*)VirtualAllocEx(hProcess, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE);<br />&nbsp;&nbsp;&nbsp;&nbsp;pItem=(char*)VirtualAllocEx(hProcess, NULL, 512, MEM_COMMIT, PAGE_READWRITE);<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;// 无法分配内存则返回<br />&nbsp;&nbsp;&nbsp;&nbsp;if ((!plvitem)||(!pItem))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvitem.cchTextMax=512;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvitem.iSubItem=0;&nbsp; //ProcessName<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvitem.pszText=pItem;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;WriteProcessMemory(hProcess, plvitem, &amp;lvitem, sizeof(LVITEM), NULL);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hwnd, LVM_GETITEMTEXT, (WPARAM)iItem, (LPARAM)plvitem);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ReadProcessMemory(hProcess, pItem, ItemBuf, 512, NULL);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// 比较字符串,匹配进程映像名<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString str = (CString)ItemBuf;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(str.CompareNoCase(_T("ClientTracer.exe")) == 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HWND hWnd=::FindWindow(NULL,_T("Windows 任务管理器"));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hWnd,WM_DESTROY,0,0);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sleep(100);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;::MessageBox(NULL,_T("禁止关闭系统关键进程!"),_T("提示"),MB_ICONERROR | MB_OK);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;}<br />&nbsp;}<br />&nbsp;<br />&nbsp;//释放内存<br />&nbsp;CloseHandle(hwnd);<br />&nbsp;CloseHandle(hProcess);<br />&nbsp;VirtualFreeEx(hProcess, plvitem, 0, MEM_RELEASE);<br />&nbsp;VirtualFreeEx(hProcess, pItem, 0, MEM_RELEASE);<br />}</p> <p>3.定时器设置调用stopKillProcess()，也可以多线程调用stopKillProcess()</p> <p>void C***Dlg::OnTimer(UINT nIDEvent) <br />{<br />&nbsp;// TODO: Add your message handler code here and/or call default<br />&nbsp;if(nIDEvent == 1)<br />&nbsp;{<br />&nbsp;&nbsp;stopKillProcess();<br />&nbsp;}<br />&nbsp;CDialog::OnTimer(nIDEvent);<br />}</p> </div></div><img src ="http://www.cppblog.com/wizardjk/aggbug/150154.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-07-04 22:19 <a href="http://www.cppblog.com/wizardjk/archive/2011/07/04/150154.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于创建新进程</title><link>http://www.cppblog.com/wizardjk/archive/2011/07/04/150076.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Mon, 04 Jul 2011 01:08:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/07/04/150076.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/150076.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/07/04/150076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/150076.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/150076.html</trackback:ping><description><![CDATA[使用CreateProcess函数时，有一组参照代码如下<br /><div>PROCESS_INFORMATION pi;<br />&nbsp;&nbsp; &nbsp;STARTUPINFO si={sizeof(si)};<br />&nbsp;&nbsp; &nbsp;DWORD dwExitCode;<br />&nbsp;&nbsp; &nbsp;BOOL fsuccess=CreateProcess(_T("C:\\Users\\Administrator\\Desktop\\explorer\\Debug\\explorer.exe"),NULL,NULL,NULL,FALSE,0,NULL,NULL,&amp;si,&amp;pi);<br />&nbsp;&nbsp; &nbsp;if (fsuccess)<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CloseHandle(pi.hThread);<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;CloseHandle(pi.hProcess);<br />&nbsp;&nbsp; &nbsp; }<br />si参数必须制定，在创建进程时需要是使用这个结构体的成员 &nbsp; <br />&nbsp;&nbsp;&nbsp;</div><img src ="http://www.cppblog.com/wizardjk/aggbug/150076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-07-04 09:08 <a href="http://www.cppblog.com/wizardjk/archive/2011/07/04/150076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于自定义消息发送与处理</title><link>http://www.cppblog.com/wizardjk/archive/2011/07/03/150052.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Sun, 03 Jul 2011 11:23:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/07/03/150052.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/150052.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/07/03/150052.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/150052.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/150052.html</trackback:ping><description><![CDATA[<div>::SendMessage<strong>(</strong> <strong>   HWND </strong>hWnd<strong>,</strong> <strong>   UINT </strong>message<strong>,</strong> <strong>   WPARAM </strong>wParam<strong>,</strong> <strong>   LPARAM </strong>lParam  <strong>)</strong>;</div>参数1：目的窗口的句柄<br />参数2：系定义消息类型<br />参数3：消息参数<br />参数4：消息参数<br />在接受该消息的窗口函数中添加消息处理函数即可<img src ="http://www.cppblog.com/wizardjk/aggbug/150052.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-07-03 19:23 <a href="http://www.cppblog.com/wizardjk/archive/2011/07/03/150052.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>路径拼接与分解</title><link>http://www.cppblog.com/wizardjk/archive/2011/07/01/149875.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Fri, 01 Jul 2011 01:55:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/07/01/149875.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/149875.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/07/01/149875.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/149875.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/149875.html</trackback:ping><description><![CDATA[<div><div>#include &lt;iostream&gt;<br />#include &lt;fstream&gt;<br />#include &lt;afx.h&gt;<br />using namespace std;<br /><br />int main()<br />{<br />&nbsp;&nbsp; &nbsp;char path_buffer[_MAX_PATH];<br />&nbsp;&nbsp; &nbsp;char drive[_MAX_DRIVE];<br />&nbsp;&nbsp; &nbsp;char dir[_MAX_DIR];<br />&nbsp;&nbsp; &nbsp;char fname[_MAX_FNAME];<br />&nbsp;&nbsp; &nbsp;char ext[_MAX_EXT];<br />&nbsp;&nbsp; &nbsp;GetModuleFileName(NULL,path_buffer,MAX_PATH);//得到当前路径<br />&nbsp;&nbsp; &nbsp;_splitpath( path_buffer, drive, dir, fname, ext );//拆分当前路径<br />&nbsp;&nbsp; &nbsp;cout&lt;&lt;path_buffer&lt;&lt;endl;<br />&nbsp;&nbsp; &nbsp;CString cStr,temp;<br />&nbsp;&nbsp; &nbsp;temp.Format("%s",drive);<br />&nbsp;&nbsp; &nbsp;cStr+=temp;<br />&nbsp;&nbsp; &nbsp;temp.Empty();<br />&nbsp;&nbsp; &nbsp;temp.Format("%s",dir);<br />&nbsp;&nbsp; &nbsp;cStr+=temp;<br />&nbsp;&nbsp; &nbsp;temp.Empty();<br />&nbsp;&nbsp;&nbsp; temp.Format("%s","\\aa.jpg");//将路径拼接成想要的文件路径<br />&nbsp;&nbsp; &nbsp;<span style="color: red;">cStr.Delete(cStr.GetLength()-1,1);//去掉不包含文件名的路径的最后一个\，否则编译器会误会有转义字符</span><br />&nbsp;&nbsp; &nbsp;cStr+=temp;<br />&nbsp;&nbsp; &nbsp;temp.Empty();<br />&nbsp;&nbsp; &nbsp;cStr.Replace("\\","\\\\");<br />&nbsp;&nbsp; &nbsp;cStr.TrimRight();<br />&nbsp;&nbsp; &nbsp;//cout&lt;&lt;cStr&lt;&lt;endl;<br />&nbsp;&nbsp; &nbsp;<span style="color: red;">const char* filename =cStr.GetBuffer(sizeof(cStr));//将路径赋值给一个const char* 的常量</span><br />&nbsp;&nbsp; &nbsp;//cout&lt;&lt;filename&lt;&lt;endl;<br />&nbsp;&nbsp; &nbsp;ifstream ifile(filename,iostream::binary);//使用<br />&nbsp;&nbsp; &nbsp;ofstream ofile("D:\\aa.jpg",iostream::binary);<br />&nbsp;&nbsp; &nbsp;try<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (ifile==NULL)<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;throw -1;<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ofile&lt;&lt;(ifile.rdbuf()); <br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;catch (int e)<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;"error"&lt;&lt;endl;<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;ifile.close();<br />&nbsp;&nbsp; &nbsp;ofile.close();<br />&nbsp;&nbsp; &nbsp;system("pause");<br />&nbsp;&nbsp;&nbsp; &nbsp;return 0;<br />}</div></div><img src ="http://www.cppblog.com/wizardjk/aggbug/149875.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-07-01 09:55 <a href="http://www.cppblog.com/wizardjk/archive/2011/07/01/149875.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于CString</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/30/149863.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 30 Jun 2011 15:53:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/30/149863.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/149863.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/30/149863.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/149863.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/149863.html</trackback:ping><description><![CDATA[CString的GetBuffer：它的作用是返回一个可写的缓冲指针。<br />example：<div>CString s(_T("File.ext")); 　　LPTSTR p = s.GetBuffer(); </div>CString的ReleaseBuffer：<div>不给它传递参数，它使用默认值 0，意思是："给我这个字符串的指针，我保证不加长它"。<br />当调用 ReleaseBuffer 时，字符串的实际长度会被重新计算，然后存入 CString 对象中。 </div><img src ="http://www.cppblog.com/wizardjk/aggbug/149863.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-30 23:53 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/30/149863.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BOOL和bool的区别</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/30/149855.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 30 Jun 2011 13:59:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/30/149855.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/149855.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/30/149855.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/149855.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/149855.html</trackback:ping><description><![CDATA[<div>一、 <br />1、类型不同 <br />BOOL为int型 <br />bool为布尔型 <br />2、长度不同 <br />bool只有一个字节 <br />BOOL长度视实际环境来定，一般可认为是4个字节 <br />3、取值不同 <br /><div>bool取值false和true，是0和非0的区别  <br />BOOL取值FALSE和TRUE，是0和1的区别  </div><br />二： <br />bool是标准C++数据类型，可取值true和false。单独占一个字节， <br />如果数个bool对象列在一起，可能会各占一个bit，这取决于编译器。 <br /><br />BOOL是微软定义的typedef int BOOL。与bool不同，它是一个三值逻辑， <br />TRUE/FALSE/ERROR，返回值为&gt;0的整数为TRUE，0为FALSE，-1为ERROR。 <br />Win32 API中很多返回值为BOOL的函数都是三值逻辑。比如GetMessage(). <br />三： <br />大BOOL和小bool之间的区别： <br />1、类型不同 <br />BOOL为int型 <br />bool为布尔型 <br />2、长度不同 <br />bool只有一个字节 <br />BOOL长度视实际环境来定，一般可认为是4个字节 <br />3、取值不同 <br />bool取值false和true，是0和1的区别 <br />BOOL取值FALSE和TRUE，是0和非0的区别 <br />4、例子 <br />bool x=3;&nbsp; //告警 <br />bool x=1;&nbsp; //正确 <br />BOOL x=3;&nbsp; //正确 <br />BOOL x=3.3;&nbsp; //告警 <br />注：windows为了兼容问题定义的基础变量。 <br />typedef unsigned long&nbsp; &nbsp; &nbsp; &nbsp; DWORD; <br />typedef int&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BOOL; <br />typedef unsigned char&nbsp; &nbsp; &nbsp; &nbsp; BYTE; <br />typedef unsigned short&nbsp; &nbsp; &nbsp; WORD; <br />typedef float&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FLOAT; <br />typedef FLOAT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *PFLOAT; <br />typedef BOOL near&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *PBOOL; <br />typedef BOOL far&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *LPBOOL; <br />typedef BYTE near&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *PBYTE; <br />typedef BYTE far&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *LPBYTE; <br />typedef int near&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *PINT; <br />typedef int far&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *LPINT;   		</div><img src ="http://www.cppblog.com/wizardjk/aggbug/149855.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-30 21:59 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/30/149855.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>转 C++注册表操作汇总</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/30/149806.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 30 Jun 2011 03:13:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/30/149806.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/149806.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/30/149806.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/149806.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/149806.html</trackback:ping><description><![CDATA[<div><div>  C++ 注册表操作总结</div>  <div>2008-01-11  20:45</div>     <div><strong>1、RegCloseKey()</strong><br /> 　　原型：RegCloseKey(HKEY hKey)<br /> <br /> 　　解释：关闭指定的注册表键，释放句柄。当对一个或多个键或值操作完成以后，需要关闭其键来进行保存操作结果，关闭一个键后，句柄变为非法，此时应释放句柄。</div> <div> </div> <div><strong>2、RegCreateKeyEx()</strong><br /> 　　原型：LONG RegCreateKeyEx( HKEY hKey, LPCTSTR lpSubKey, DWORD Reserved,<br /> LPTSTR lpClass, DWORD dwOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes,<br /> PHKEY phkResult, LPDWORD lpdwDisposition );<br /> <br /> 　　解释：打开指定的键或子键。如果要打开的键不存在的话，本函数会试图建立它。提供该函数是为了向后兼容。所有的WIN32应用程序应使用函数RegCreateKeyEx（）。　各参数及返回值的含义如下：</div> <div><br /> &#183;hKey为主键值，可以取下面的一些数值：HKEY_CLASSES_ROOT、HKEY_CURRENT_CONFIG、　　 HKEY_CURRENT_USER、HKEY_LOCAL_MACHINE、HKEY_USER、 HKEY_PERFORMANCE_DATA(WINNT操作系统)、HKEY_DYN_DATA（WIN9X操作系统）；</div> <div>&#183;参数lpSubKey为一个指向以零结尾的字符串的指针，其中包含将要创建或打开的子键的名称。子键不可以用反斜线（\）开始。该参数可以为NULL；<br /> <br /> &#183;参数Reserved为保留值，必须设置为0；<br /> <br /> &#183;参数lpClass为一个指向包含键类型的字符串。如果该键已经存在，则忽略该参数；<br /> <br /> &#183;参数dwOptions为新创建的键设置一定的属性。可以取下面的一些数值：　　REG_OPTION_NON_VOLATILE  ，表示新创建的键为一个非短暂性的键（数据信息保存在文件中，当系统重新启动时，数据信息恢复）；REG_OPTION_VOLATILE，表示新创建的 键为一个短暂性的键（数据信息保存在内存中），Windows95忽略该数值；REG_OPTION_BACKUP_RESTORE  仅在WINNT中支持，可以提供优先级支持；<br /> <br /> &#183;参数dwOptions为新创建的键设置一定的属性。可以取下面的一些数值：　　REG_OPTION_NON_VOLATILE  ，表示新创建的键为一个非短暂性的键（数据信息保存在文件中，当系统重新启动时，数据信息恢复）；REG_OPTION_VOLATILE，表示新创建的 键为一个短暂性的键（数据信息保存在内存中），Windows95忽略该数值；REG_OPTION_BACKUP_RESTORE  仅在WINNT中支持，可以提供优先级支持；<br /> <br /> 　　&#183;参数samDesired用来设置对键访问的权限，可以取下面的一些数值：KEY_CREATE_LINK，表示准许生成符号 键；KEY_CREATE_SUB_KEY 表示准许生成子键；KEY_ENUMERATE_SUB_KEYS  表示准许生成枚举子键；KEY_EXECUTE 表示准许进行读操作；KEY_NOTIFY表示准许更换通告；　　KEY_QUERY_VALUE  表示准许查询子键；KEY_ALL_ACCESS 提供完全访问，是上面数值的组合；<br /> <br /> 　　KEY_READ  是下面数值的组合：KEY_QUERY_VALUE、KEY_ENUMERATE_SUB_KEYS、KEY_NOTIFY；　　 KEY_SET_VALUE 表示准许设置子键的数值；KEY_WRITE  是下面数值的组合：KEY_SET_VALUE、KEY_CREATE_SUB_KEY；<br /> &#183;参数lpSecurityAttributes为一个指向SECURITY_ATTRIBUTES结构的指针，确定返回的句柄是否被子处理过程继承。如果该参数为NULL，则句柄不可以被继承。在WINNT中，该参数可以为新创建的键增加安全的描述；<br /> <br /> 　　&#183;参数phkResult为一个指向新创建或打开的键的句柄的指针；<br /> <br /> 　　&#183;参数lpdwDispition指明键是被创建还是被打开的，可以是下面的一些数值：　　REG_CREATE_NEW_KEY 表示键先前不存在，现在被创建；REG_OPENED_EXISTING_KEY 表示键先前已存在，现在被打开。<br /> <br /> 　　如果该函数调用成功，则返回ERROR_SUCCESS。否则，返回值为文件WINERROR.h中定义的一个非零的错误代码，可以通过设置 FORMAT_MESSAGE_FROM_SYSTEM标识调用FormatMessage（）函数来获取一个对错误的总体描述。</div> <div><strong>3、RegOpenKeyEx（）</strong><br /> 　　原型：LONG RegOpenKeyEx(HKEY hKey, LPCTSTR lpSubKey, DWORD ulOptions,<br /> REGSAM samDesired, PHKEY phkResult );<br /> <br /> 　　解释：打开一个指定的键，并返回打开键的句柄。<br /> <br /> 各参数及返回值的含义如下：<br /> &#183;参数hKey的含义同RegCreateKeyEx函数中的hKey参数；<br /> <br /> &#183;参数lpSubKey为一个指向以零结尾的字符串的指针，其中包含子键的名称，可以利用反斜线（\）分隔不同的子键名。如果字符串为空，则根据hKey参数创建一个新的句柄。在这种情况下，并不关闭先前打开的句柄；</div> <div>&#183;参数ulOption保留，通常必须设置为0；<br /> <br /> &#183;参数samDesired的含义同RegCreateKeyEx函数中的samDesired参数；<br /> <br /> &#183;参数phkResult为一个指针，用来指向打开的键的句柄。可以通过RegCloseKey函数关闭这个句柄；<br /> <br /> &#183;函数的返回值同RegCreateKeyEx函数的返回值。</div> <div><strong>4、查询某一个键值：RegQueryValueEx（）<br /> </strong><br /> 　　原型：LONG RegQueryValueEx(HKEY hKey, LPCTSTR lpValueName, LPDWORD pReserved, LPDWORD lpType,<br /> LPBYTE lpData, LPDWORD lpcbData );<br /> <br /> 　　解释：根据要查询的键的句柄，要返回的查询的数据。<br /> <br /> 　　各个参数及返回值的含义如下：<br /> <br /> 　　&#183;参数hKey为当前的一个打开的键的句柄，具体数值同RegCreateKeyEx函数的hKey参数；<br /> <br /> 　　&#183;参数lpVauleName为一个指向非空的包含查询值的名称的字符串指针；<br /> <br /> 　　&#183;参数lpReserved保留，必须为NULL；<br /> <br /> 　　&#183;参数lpType为一个指向数据类型的指针，数据类型为下列类型之一：REG_BINARY 二进制数据、REG_DWORD  32位整数、REG_DWORD_LITTLE_ENDIAN little－endian格式的数据，例如0X12345678以（0X78 0X56  0X34 0X12）方式保存、REG_DWORD_BIG_ENDIAN big－endian格式的数据，例如0X12345678以（0X12  0X34 0X56 0X78）方式保存、REG_EXPAND_SZ 一个包含未扩展环境变量的字符串、REG_LINK  一个Unicode类型的链接、REG_MULIT_SZ 以两个零结尾的字符串、REG_NONE 无类型数值、REG_RESOURCE_LIST  设备驱动资源列表、REG_SZ 一个以零结尾的字符串根据函数使用的字符集类型的不同而设置为Unicode或ANSI类型的字符串；<br /> <br /> 　　&#183;参数lpData为一个指向保存返回值的变量的指针。如果不需要返回值，该参数可以为NULL；<br /> <br /> 　　&#183;参数lpcbData为一个指向保存返回值长度的变量的指针。其中长度以字节为单位。如果数据类型为REG_SZ、REG_MULTI_SZ或 REG_EXPAND_SZ，那么长度也包括结尾的零字符，只有在参数lpData为NULL时，参数lpcbData才可以为NULL；返回值同 RegCreateKeyEx函数的返回值；</div> <div><strong>　5、RegSetValueEx（）</strong><br /> <br /> 　　原型：LONG RegSetValueEx(HKEY hKey, LPCTSTR lpValueName, LPDWORD lpReserved, DWORD dwType,<br /> const BYTE *lpData, DWORD cbData);<br /> <br /> 　　解释：设置注册表中的一个键值。<br /> <br /> 　　各个参数及返回值的含义如下：<br /> <br /> 　　&#183;参数hKey的含义同RegCreateKeyEx函数中的hKey参数；<br /> <br /> 　　&#183;参数lpValueName为一个指向包含值名的字符串指针；Reserved保留，通常必须设置为0；<br /> <br /> 　　&#183;参数dwType确定了设置的值的类型同RegQueryValueKeyEx的lyType参数；<br /> <br /> 　　&#183;参数lpData为一个指向包含数据的缓冲区的指针；<br /> <br /> 　　&#183;参数cbData以字节为单位，指定数据的长度；<br /> <br /> 　　返回值同RegCreateKeyEx函数的返回值。</div> <strong>6、RegDeleteKey（）</strong><br /> <br /> 　　原型：LONG RegDeleteKey（HKEY hKey，LPCTSTR lpSubKEY）；<br /> <br /> 　　解释：函数RegDeleteKey删除一个键及所有的子键。<br /> <br /> 　　各个参数及返回值的含义如下：<br /> <br /> 　　&#183;参数hKey的含义同RegCreateKeyEx函数中的hKey参数；<br /> <br /> 　　&#183;参数lpSubKey的含义同RegCreateKeyEx函数中的lpSubKey参数。<br />转自：<div>lucky dog</div><div>http://hi.baidu.com/luosiyong/blog/item/585facef152a90ebcf1b3e5b.html</div></div><img src ="http://www.cppblog.com/wizardjk/aggbug/149806.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-30 11:13 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/30/149806.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>实验感知</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/30/149794.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 30 Jun 2011 00:48:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/30/149794.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/149794.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/30/149794.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/149794.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/149794.html</trackback:ping><description><![CDATA[<div>人们一般用 &nbsp;  &nbsp; WM_USER &nbsp; 或 &nbsp;  &nbsp; WM_USER+上某个值 &nbsp; 表明&#8220;这是不是一个 &nbsp; WINDOWS &nbsp; 系统消息&#8221; </div>即自定义的消息的消息ID &nbsp; 一般取 &nbsp; WM_USER &nbsp; + &nbsp; x<br /><br /><div><div>在设计错误处理机制时将success考虑成error的一种状态，</div>ERROR_SUCCESS的定义为#define ERROR_SUCCESS                    0L<br /><br />关于异常的捕获：<br />在try块中进行异常的判断，如果出现异常就进行throw，然后再catch中进行处理：<br />example：<br /><div>#include&nbsp;&nbsp; &lt;iostream&gt;<br />#include&nbsp;&nbsp; &lt;fstream&gt;<br /><br />using namespace std;<br /><br />int main()<br />{<br />&nbsp;&nbsp; &nbsp;ifstream&nbsp;&nbsp; ifile( "F:\stellarium-0.10.6.1exe ",ios::in|ios::binary);<br />&nbsp;&nbsp; &nbsp;ofstream&nbsp;&nbsp; ofile( "D:\\stellarium-0.10.6.1.exe ",ios::binary);<br />&nbsp;&nbsp; &nbsp;try<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if (ifile==NULL)<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<span style="color: red;">throw -1;</span><br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ofile&lt;&lt;(ifile.rdbuf());//流输入器，将streambuffer的地址给ofile<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;<span style="color: #99cc00;">catch(int a)</span>//对于throw抛出的特定类型进行捕获<br />&nbsp;&nbsp; &nbsp;{<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;cout&lt;&lt;"copy error"&lt;&lt;endl;<br />&nbsp;&nbsp; &nbsp;}<br />&nbsp;&nbsp; &nbsp;ifile.close();<br />&nbsp;&nbsp; &nbsp;ofile.close();<br />&nbsp;&nbsp; &nbsp;system("pause");<br />&nbsp;&nbsp; &nbsp;return 0;<br />}<br /><br />关于线程的创建<br />在MFC中使用AfxBeginThread函数来创建一个新的线程，<br />1：第一个参数应给一个全局函数的名字，不带括号，<br />2：如果是该对话框的内部成员函数应该是static类型的，在函数实现时不需要加static关键字，<br />3：在传参时使用类名：：函数名的形式<br />4：创建的新线程在调用成员函数时只能调用静态成员函数和全局变量。<br /><br /><div>判断文件是否存在可以用CFileFind类，如果删除一个文件，可以用remove函数<br /><div><pre><span style="color: #000000;">    CFileFind finder;    CString strFileName </span><span style="color: #000000;">=</span> <span style="color: #800000;">"</span><span style="color: #800000;">D:\\test.txt</span><span style="color: #800000;">"</span><span style="color: #000000;">;    BOOL bWorking </span><span style="color: #000000;">=</span><span style="color: #000000;"> finder.FindFile(strFileName);    </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (bWorking)    {       remove(strFileName);    }    finder.Close();<br /><br /><div><div>itoa <div f14=""><a target="_blank" href="http://baike.baidu.com/w?ct=17&amp;lm=0&amp;tn=baiduWikiSearch&amp;pn=0&amp;rn=10&amp;submit=search&amp;word=tag:c%D3%EF%D1%D4%BA%AF%CA%FD&amp;tagfromview">c语言函数</a></div> </div>                                                      <p>功 能: 把一整数转换为字符串<br />             用 法: char *itoa(int value, char *string, int radix);<br />             详细解释:itoa是英文integer to string a(将整形数转化为一个字符串,并将值保存在a中)<br />             的缩写.其中value为要转化的整数, radix是基数的意思,即先将value转化为几进制的数,之后在保存在a 中.</p>             &nbsp;&nbsp;&nbsp;<strong> itoa()函数有3个参数：第一个参数是要转换的数字，第二个参数是要写入转换结果的目标字符串，第三个参数是转移数字时所用 的基数。在上例中，转换基数为10。10：十进制；2：二进制</strong></div><br /></span></pre></div></div></div></div><img src ="http://www.cppblog.com/wizardjk/aggbug/149794.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-30 08:48 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/30/149794.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NDIS_PHYSICAL_MEDIUM出现问题</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/16/148760.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 16 Jun 2011 02:00:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/16/148760.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/148760.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/16/148760.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/148760.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/148760.html</trackback:ping><description><![CDATA[<div>WinPcap的使用说明网上也有不少，这里仅作学习过程的记录。<br />&nbsp;&nbsp;&nbsp; 首先，从官方下载了较新的开发包WpdPack_4_0_2，里面有不少的例子。不过都是VC6.0的，而我想要开发的环境是VS2008。<div>&nbsp;&nbsp;&nbsp; WinPcap解压后有5个文件夹，其中Lib和Include两个要包含在工程中。方法如下：<br />&nbsp;&nbsp; &nbsp;&nbsp; 1）项目-&gt;属性-&gt;配置属性-&gt;链接器-&gt;常规-&gt;附加库目录，加入Lib所在路径；<br />&nbsp;&nbsp; &nbsp;&nbsp; 2）项目-&gt;属性-&gt;配置属性-&gt;链接器-&gt;输入-&gt;附加依赖项，加入wpcap.lib与Packet.lib两个静态链接库；<br />&nbsp;&nbsp; &nbsp;&nbsp; 3）项目-&gt;属性-&gt;配置属性-&gt;C/C++-&gt;常规-&gt;附加包含目录，加入Include所在路径。</div>&nbsp;&nbsp;&nbsp; 接着，我参考了http://www.smatrix.org/bbs/read.php?tid=358&amp;fpage=4里头的步骤开始获取网络驱动。结果很不幸地出现了一些莫名其妙的错误：<br />&nbsp;&nbsp; &nbsp;&nbsp; 1&gt;c:\program files\microsoft sdks\windows\v6.0a\include\netioapi.h(155) : error C2146: 语法错误 : 缺少&#8220;;&#8221;(在标识符&#8220;PhysicalMediumType&#8221;的前面)。<br />&nbsp;&nbsp; &nbsp;&nbsp; 错误发生在&nbsp;&nbsp;&nbsp; NDIS_PHYSICAL_MEDIUM PhysicalMediumType 这一句上。网上有一些解析，说这是因为VS2008对ntddndis.h里头的定义比较新，WinPcap的头文件在对ntddndis.h的编译过后没有获得相应的定义，因此NDIS_PHYSICAL_MEDIUM不是一个结构或类，所以就产生了缺少&#8220;;&#8221;这样奇怪的错误。把netioapi.h里的#include &lt;ntddndis.h&gt;改为#include "ntddndis.h"后终于通过编译，改为" "后项目则从包括的文件中先查找头文件的定义，若找不到再从默认路径中查找。(网上查到的解析是：&lt;&gt;先去系统目录中找头文件，如果没有在到当前目录下找。而""首先在当前目录下寻找，如果找不到，再到系统目录中寻找。因此我猜想Include文件夹里头的ntddndis.h有NDIS_PHYSICAL_MEDIUM的定义。再查看了一下Include文件夹里的ntddndis.h，也没发现，但在查看c:\program files\microsoft sdks\windows\v6.0a\include\下的ntddndis.h时竟然发现有NDIS_PHYSICAL_MEDIUM的定义！！！ 是不是我对系统目录的概念理解有误呢？假如把Include（WinPcap中）里的头文件删了，再改回&lt;&gt;可以通过编译的话，那么就说明在用&lt;&gt;的情况下查找的顺序应该是先查Include文件夹再查默认路径。一试之下竟然应验了。于是再去搜了一个尖括号与双引号的区别，这个解析得比较清晰：<strong>双引号时，系统先在引用被包含文件的源文件所在的文件目录中寻找要包含的文件，若找不到，再按系统指定的标准方式检索其他目录。<u>尖括号时，不检查原文件所在的文件目录，而直接按系统标准方式检索文件目录</u>。</strong>这样子就能解析发生了什么问题，因为发生错误的是在netioapi.h的头文件里，而这个头文件是在c:\program files\microsoft sdks\windows\v6.0a\include\下，所以在用&lt;&gt;时项目没有直接查与netioapi.h同一目录下的ntddndis.h，而是直接查到了Include头上。</div><img src ="http://www.cppblog.com/wizardjk/aggbug/148760.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-16 10:00 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/16/148760.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WinPcap在VS2008下环境配置</title><link>http://www.cppblog.com/wizardjk/archive/2011/06/16/148756.html</link><dc:creator>托雷宽</dc:creator><author>托雷宽</author><pubDate>Thu, 16 Jun 2011 01:08:00 GMT</pubDate><guid>http://www.cppblog.com/wizardjk/archive/2011/06/16/148756.html</guid><wfw:comment>http://www.cppblog.com/wizardjk/comments/148756.html</wfw:comment><comments>http://www.cppblog.com/wizardjk/archive/2011/06/16/148756.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/wizardjk/comments/commentRss/148756.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/wizardjk/services/trackbacks/148756.html</trackback:ping><description><![CDATA[<div>1.首先创建一个Win32 Console Application的空工程！ <p>2.点击创建的空工程的工程属性目录，到里面设置一些目录。</p> <p>具体如下：</p> <p>&nbsp; &nbsp; （1）点击C/C++目录，在右边的Preprocessor Definition加上WPCAP和HAVE_REMOTE每项之间用";"隔开</p> <p>&nbsp; &nbsp; （2）点击C/C++目录，点击展开的目录General,在右侧的Additional Include Directories中添加Include目录(Include目录在WpdPack中)</p> <p>&nbsp; &nbsp; （3）点击Linker目录，点击展开的目录General，在右边的Additional Library Directories中添加lib目录(Include目录在WpdPack中)</p> <p>&nbsp; &nbsp; （4）点击Linker目录下的Input，在右侧的Additional Dependencies中添加wpcap.lib和ws2_32.lib</p> <p>以上就是Winpcap在VS2008中的环境配置</p> <p>下面给出一个简单的例子.完全参照WinPap中文技术文档</p> <div><div><div><a href="http://blog.csdn.net/bnxf00000/archive/2011/05/06/6401076.aspx#"><br /></a><a href="http://blog.csdn.net/bnxf00000/archive/2011/05/06/6401076.aspx#"></a></div></div><ol start="1"><li><span>#include&lt;stdio.h&gt;&nbsp;&nbsp;</span></li><li><span>#include"pcap.h"&nbsp;&nbsp;</span></li><li><span>void&nbsp;main()&nbsp;&nbsp;</span></li><li>{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;pcap_if_t&nbsp;*alldevs;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;pcap_if_t&nbsp;*d;&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>int&nbsp;i=0;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>char&nbsp;errbuf[PCAP_ERRBUF_SIZE];&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if(pcap_findalldevs_ex(PCAP_SRC_IF_STRING,NULL,&amp;alldevs,errbuf)==-1)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fprintf(stderr,<span>"Error&nbsp;in&nbsp;pcap_findalldevs_ex:%s\n",errbuf);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(1);&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>for(d&nbsp;=&nbsp;alldevs;d!=NULL;d&nbsp;=&nbsp;d-&gt;next)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"%d.&nbsp;&nbsp;%s",++i,d-&gt;name);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>if(d-&gt;description)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"(%s)\n",d-&gt;description);&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>else&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"(No&nbsp;description&nbsp;availble)\n");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span>if(i==0)&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;printf(<span>"\nNo&nbsp;interface&nbsp;found!&nbsp;Make&nbsp;sure&nbsp;WinPcap&nbsp;is&nbsp;installed.\n");&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>return;&nbsp;&nbsp;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li>&nbsp;&nbsp;&nbsp;&nbsp;pcap_freealldevs(alldevs);&nbsp;&nbsp;</li><li>}&nbsp;&nbsp;</li></ol></div>&nbsp; <p>获取适配器列表，并在屏幕上显示出来，如果没有找到适配器，将打印错误信息。</p> <p><img src="http://hi.csdn.net/attachment/201105/6/322241_1304697069inkn.jpg" alt="" /></p></div><img src ="http://www.cppblog.com/wizardjk/aggbug/148756.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/wizardjk/" target="_blank">托雷宽</a> 2011-06-16 09:08 <a href="http://www.cppblog.com/wizardjk/archive/2011/06/16/148756.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>