⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vc++动态链接库编程之读者反馈与答复-开发者网络-vc-天极yesky.htm

📁 从网上下载的关于学习动态链接库的连载教程
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0038)http://dev.yesky.com/440/2166440.shtml -->
<HTML lang=zh-CN xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky</TITLE>
<META content=VC++动态链接库编程之读者反馈与答复, name=description>
<META content=VC++动态链接库编程之读者反馈与答复, name=keywords>
<META content="天极Yesky | 全球中文IT第一门户" name=author>
<META content="天极Yesky | 全球中文IT第一门户" name=Copyright>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN><LINK media=all 
href="VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky.files/y_mobile_content.css" 
type=text/css rel=stylesheet>
<SCRIPT src="VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky.files/showlay.js"></SCRIPT>

<META content="MSHTML 6.00.2900.3199" name=GENERATOR></HEAD>
<BODY><!--页面头部--><!--头部-->
<DIV id=topmenu><A href="http://www.yesky.com/">Yesky首页</A>| <A 
href="http://product.yesky.com/">产品报价</A>| <A 
href="http://cseek.yesky.com/">行情</A>| <A href="http://mobile.yesky.com/">手机</A> 
| <A href="http://digital.yesky.com/">数码</A> | <A 
href="http://notebook.yesky.com/">笔记本</A> | <A 
href="http://pc.yesky.com/">台式机</A> | <A href="http://diy.yesky.com/">DIY硬件</A> 
| <A href="http://oa.yesky.com/">外设</A> | <A href="http://net.yesky.com/">网络</A> 
| <A href="http://dh.yesky.com/">数字家庭</A> | <A 
href="http://lab.yesky.com/">评测</A> | <A href="http://soft.yesky.com/">软件</A> | 
<A href="http://e.yesky.com/">e时代</A> | <A href="http://game.yesky.com/">游戏</A> 
| <A href="http://pic.yesky.com/">图片</A> | <A 
href="http://desktop.yesky.com/">壁纸</A> | <A href="http://q.yesky.com/">群乐</A> | 
<A href="http://my.yesky.com/">社区</A> | <A href="http://blog.yesky.com/">博客</A> 
| <A href="http://www.mydown.com/">下载</A></DIV>
<DIV id=topbox>
<DIV class=tleft><A href="http://www.yesky.com/"><IMG alt=天极Yesky_全球中文IT第一门户 
src="VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky.files/logo.gif" border=0></A></DIV>
<DIV class=tad><SPAN id=ad1></SPAN></DIV>
<DIV id=search>
<DIV>
<FORM name=searchform action=http://search.chinabyte.com/search method=get 
target=_blank><INPUT id=searchzz onmouseover=this.focus() onfocus=this.select() 
name=q><INPUT type=hidden value=GB2312 name=encoding><INPUT type=hidden 
value=connect name=dir><INPUT type=hidden value=20002 name=cid><INPUT id=search_btn type=submit value=天极搜索> </FORM></DIV>
<DIV class=tdq>
<DIV class=rightarea><A href="http://bj.yesky.com/">北京</A> <A 
href="http://hd.yesky.com/">上海</A> <A href="http://gd.yesky.com/">广东</A> <A 
href="http://xa.yesky.com/">西安</A><BR><A href="http://cq.yesky.com/">重庆</A> <A 
href="http://cd.yesky.com/">成都</A> <A href="http://sy.yesky.com/">沈阳</A> <A 
href="http://js.yesky.com/">江苏</A> </DIV>
<DIV class=rightarea_right><A 
href="http://my.yesky.com/">用户<BR>登录</A></DIV></DIV></DIV>
<DIV class=tright>
<DIV class=box1>
<SCRIPT src="VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky.files/content_text_ad.js" 
type=text/javascript></SCRIPT>
</DIV></DIV></DIV>
<SCRIPT src="VC++动态链接库编程之读者反馈与答复-开发者网络-VC-天极Yesky.files/flash.js" 
type=text/javascript></SCRIPT>

<DIV id=childmenu><A href="http://soft.yesky.com/">软件频道&gt;</A><A 
href="http://dev.yesky.com/">程序开发&gt;</A><A 
href="http://dev.yesky.com/devjava/">Java</A><A 
href="http://dev.yesky.com/ysdevvb">VB</A><A 
href="http://dev.yesky.com/ysdevvc">VC</A><A 
href="http://dev.yesky.com/ysdevdelphi">Delphi</A><A 
href="http://dev.yesky.com/ysdevc">C/C++</A><A 
href="http://dev.yesky.com/web/">Web开发</A><A 
href="http://dev.yesky.com/msdn/">微软专栏</A><A 
href="http://dev.yesky.com/devydkf/">移动</A><A 
href="http://dev.yesky.com/devsjk/">数据库</A><A 
href="http://dev.yesky.com/ysdevcxrs">程序人生</A><A 
href="http://dev.yesky.com/ysdevrjgc">软件工程</A>|<A 
href="http://soft.yesky.com/lesson/">产品中心</A><A 
href="http://www.mydown.com/soft/develop/news.shtml">下载</A><A 
href="http://q.yesky.com/group/202019"><FONT color=#ff0000>群乐:<FONT 
face=Verdana>Vista系统</FONT></FONT></A></DIV><!--导航条-->
<DIV id=location>
<DIV class=loleft>您现在的位置: <A href="http://www.yesky.com/">天极网</A> &gt; <A 
href="http://dev.yesky.com/">开发频道</A> &gt; VC++动态链接库编程之读者反馈与答复</DIV>
<DIV class=adright><SPAN id=ad2></SPAN></DIV></DIV><!--内容块开始-->
<DIV id=conbox><!--左边开始-->
<DIV id=conleft>
<DIV id=contopla1>
<DIV id=__001>
<DIV class=qkong></DIV>
<DIV class=qw1>全文</DIV>
<DIV class=zkong>
<DIV class=kl></DIV>
<DIV class=bj><A href="http://dev.yesky.com/440/2166440.shtml#pls" 
target=_self>评论</A></DIV>
<DIV class=kr></DIV>
<SCRIPT type=text/javascript>
var titiepic ="#";
if (titiepic!="#")
{
document.write("<div class=\"kl\"></div><div class=\"bj\"><a href=\"#\" target=\"_blank\">图片</a></div><div class=\"kr\"></div>");
}
</SCRIPT>
</DIV></DIV></DIV>
<DIV class=topadbg><SPAN id=ad10></SPAN></DIV><A name=top></A>
<DIV id=contitle>
<H1>VC++动态链接库编程之读者反馈与答复</H1></DIV>
<DIV id=conauthor><SPAN>2005-10-25 14:07 </SPAN><SPAN>作者: 宋宝强 </SPAN><SPAN>出处: 
天极网 </SPAN><SPAN>责任编辑:<A title=向本编辑提问 
href="http://comments.yesky.com/t/·&frac12;&Ouml;&Ucirc;/6,324/2166440.shtml" target=_blank>方舟</A> 
</SPAN></DIV>
<DIV class=topadbg><SPAN id=ad9></SPAN></DIV>
<DIV id=conneirong><SPAN id=ad3></SPAN>
<TABLE cellSpacing=1 cellPadding=2 width=600 align=center bgColor=#ff3300 
border=0>
  <TBODY>
  <TR bgColor=#ffffff>
    <TD bgColor=#cc0000 colSpan=4><A 
      href="http://soft.yesky.com/lesson/"><FONT 
      color=#ffffff><B>天极软件专题专区精选</B></FONT></A>     <A 
      href="http://comments.yesky.com/t/100913/6,324/2069547.shtml" 
      target=_blank><FONT color=#ffffff><B>到天极软件“读编交流区”畅所欲言</B></FONT></A></TD></TR>
  <TR bgColor=#ffffff>
    <TD width="25%"><A href="http://soft.yesky.com/tools/google">Google专区</A> 
    </TD>
    <TD width="23%"><A href="http://soft.yesky.com/tools/popo">POPO专区</A></TD>
    <TD width="24%"><A href="http://qq.yesky.com/">QQ专区</A> <A 
      href="http://soft.yesky.com/lesson/401/2047901.shtml">QQ挂机</A></TD>
    <TD width="28%"><A 
      href="http://soft.yesky.com/327/2055327.shtml">了解Web2.0</A></TD></TR>
  <TR bgColor=#ffffff>
    <TD width="25%"><A href="http://design.yesky.com/flash/mx/">Flash MX 
      视频教程</A></TD>
    <TD width="23%"><A 
      href="http://soft.yesky.com/SoftChannel/72348986094125056/20040623/1823629.shtml">Photoshop视频教程</A></TD>
    <TD width="24%"><A 
      href="http://www.yesky.com/259/1926759.shtml">网页设计视频教程</A></TD>
    <TD width="28%"><A 
      href="http://www.yesky.com/SoftChannel/72348986094125056/20050430/1943944.shtml">照片处理数字暗房</A></TD></TR>
  <TR bgColor=#ffffff>
    <TD width="25%"><A 
      href="http://www.yesky.com/SoftChannel/72348968914255872/20050517/1950125.shtml">PPT动画演示教程</A></TD>
    <TD width="23%"><A 
      href="http://soft.yesky.com/SoftChannel/72348968914255872/20050126/1905902.shtml">Excel动画教程集</A></TD>
    <TD width="24%"><A 
      href="http://soft.yesky.com/SoftChannel/72348968914255872/20050223/1914058.shtml">Word动画演示教程</A></TD>
    <TD width="28%"><A href="http://soft.yesky.com/os/vista/">Windows 
      Vista专区</A> </TD></TR>
  <TR bgColor=#ffffff>
    <TD width="25%" height=18><A 
      href="http://soft.yesky.com/security/muma/">特洛伊木马专区</A></TD>
    <TD width="23%" height=18><A 
      href="http://soft.yesky.com/security/hkjc/">黑客知识教程专区</A></TD>
    <TD width="24%" height=18><A 
      href="http://soft.yesky.com//security/firewall/">防火墙应用专区</A></TD>
    <TD width="28%" height=18><A 
      href="http://soft.yesky.com/os/zcb/">注册表应用专区</A></TD></TR>
  <TR bgColor=#ffffff>
    <TD width="25%"><A href="http://soft.yesky.com/lesson/vbapi/" 
      target=_blank>Windows API开发专区</A></TD>
    <TD width="23%"><A href="http://soft.yesky.com/lesson/network/" 
      target=_blank>网络编程专区</A></TD>
    <TD width="24%"><A href="http://soft.yesky.com/lesson/vbdatabase/" 
      target=_blank>VB数据库编程专区</A></TD>
    <TD width="28%"><A 
      href="http://soft.yesky.com/lesson/multimedia/">图像处理与多媒体编程</A></TD></TR></TBODY></TABLE><BR>  1.关于文章的获取 
<BR><BR>  许多读者发来e-mail询问本系列文章的相关事宜,如:<BR><BR>  (1) 是否已出版?<BR><BR>  (2) 
哪里可以下载打包版?<BR><BR>  (3) 哪里可以下载笔者的其它文章?<BR><BR>
<DIV class=guanggao><SPAN id=contentAdv></SPAN></DIV>  还有一些读者对日前笔者在天极网发表的《<A 
href="http://soft.yesky.com/lesson/188/2023188.shtml" target=_blank><FONT 
color=#1111ee>C语言嵌入式系统编程修炼之道</FONT></A>》非常喜爱,给予了热情洋溢的赞扬,询问笔者能否继续创作嵌入式编程方面的文章。<BR><BR>  对于这些问题,统一作答如下:<BR><BR>  (1)本系列文章暂时尚未出版;<BR><BR>  (2)您可以在天极网软件频道下载笔者的多数拙作。另外,我也将不定期将这些文章上传到我的博客( 
http://blog.donews.com/21cnbao/)。所有文章中的例程源代码均经过亲手调试,验证无误; 
<BR><BR>  (3)就嵌入式系统开发,笔者将继续进行此方面的创作,新近将推出《基于嵌入式实时OS 
VxWorks的多任务程序设计》及《领悟:从Windows多线程到VxWorks的多任务》。<BR><BR>  非常感谢读者朋友对这些文章的喜爱,在下将竭尽所能地为您提供更多的好文章。<BR><BR>  2.关于DLL的疑问<BR><BR>  你好,看了你写的"VC++ 
DLL编程深入浅出",特别有收获。 只是有个地方我老搞不明白,就是用DLL导出全局变量时,指定了.lib的路径(#pragma 
comment(lib,"dllTest.lib")),那么.dll的文件的路径呢,我尝试着把.dll文件移到别的地方程序就无法正常运行了,请问.dll在这里怎么指定。<BR><BR>  希望您能在百忙中抽空给我解答一下,不胜感激!<BR><BR>  一位编程爱好者<BR><BR>  回答:<BR><BR>  Windows按下列顺序搜索DLL:<BR><BR>  (1)当前进程的可执行模块所在的目录;<BR><BR>  (2)当前目录;<BR><BR>  (3)Windows 
系统目录,通过GetSystemDirectory 函数可获得此目录的路径;<BR><BR>  (4)Windows 
目录,通过GetWindowsDirectory 函数可获得此目录的路径;<BR><BR>  (5)PATH 
环境变量中列出的目录。<BR><BR>  因此,隐式链接时,DLL文件的路径不需要指定也不能指定,系统指定按照1~5的步骤寻找DLL,但是对应的.lib文件却需要指定路径;如果使用Windows 
API函数LoadLibrary动态加载DLL,则可以指定DLL的路径。<BR><BR>  你好,我是一位C++初学者,我在PCONLINE看了教学之后,受益不浅。我想问一下能否在DLL里使用多线程?MSDN上用#using 
&lt;mscorlib.dll&gt;这个指令之后实现了多线程,不过好象不支持DLL..<BR><BR>  请问有什么办法支持制作多线程DLL??能否给一个源码来?<BR><BR>  回答:<BR><BR>  在DLL中可以处理多线程,WIN32对于多线程的支持是操作系统本身提供的一种能力,并不在于用户编写的是哪一类程序。即便是一个控制台程序,我们都可以使用多线程:<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>#include &lt;stdio.h&gt;<BR>#include &lt;windows.h&gt;<BR>void 
      ThreadFun(void)<BR>{<BR> while(1)<BR> {<BR>  printf( "this is new 
      thread\n" );<BR>  Sleep( 1000 );<BR> } <BR>}<BR>int main()<BR>{<BR> DWORD 
      threadID;<BR> CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)ThreadFun, 
      NULL, 0, &amp;threadID );<BR> while(1)<BR> {<BR>  printf( "this is main 
      thread\n" );<BR>  Sleep( 1000 
);<BR> }<BR>}</TD></TR></TBODY></TABLE><BR>  观察程序运行的结果为在控制台窗口上交替输出this is main 
thread、this is new 
thread。<BR><BR>  我们来看下面的一个多线程DLL的例子。<BR><BR>  DLL程序提供一个接口函数SendInit,在此接口中启动发送线程SendThreadFunc,在这个线程的对应工作函数中我们使用原始套接字socket发送报文。参考微软出版的经典书籍《Windows核心编程》,我们发现,不宜在DLL被加载的时候(即进程绑定时)启动一个新的线程。<BR><BR>  这个线程等待一个CEvent事件(用于线程间通信),应用程序调用DLL中的接口函数SendMsg( 
InterDataPkt sendData )可以释放此事件。下面是相关的源代码:<BR><BR>  (1)发送报文线程入口函数<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>///////////////////////////////////////////////////////////////////////////<BR>//函数名:SendThreadFunc<BR>//函数功能:发送报文工作线程入口函数,使用UDP协议<BR>////////////////////////////////////////////////////////////////////////////<BR>DWORD 
      WINAPI SendThreadFunc( LPVOID lpvThreadParm ) 
      <BR>//提示:对于线程函数应使用WINAPI声明,WINAPI被宏定义为__stdcall<BR>{<BR> /* 创建socket 
      */<BR> sendSock = socket ( AF_INET, SOCK_DGRAM, 0 );<BR> if ( sendSock == 
      INVALID_SOCKET ) <BR> {<BR>  AfxMessageBox ( "Socket创建失败" 
      );<BR>  closesocket ( recvSock );<BR> }<BR><BR> /* 获得目标节点端口与地址 
      */<BR> struct sockaddr_in desAddr; 
      <BR> desAddr.sin_family=AF_INET;<BR> desAddr.sin_port=htons( DES_RECV_PORT 
      ); //目标节点接收端口<BR> desAddr.sin_addr.s_addr = inet_addr( DES_IP 
      );<BR><BR> /* 发送数据 */<BR> while(1)<BR> {<BR>  WaitForSingleObject( 
      hSendEvent, 0xffffffffL );//无限等待事件发生<BR>  ResetEvent( hSendEvent ); 
      <BR><BR>  sendto( sendSock, (char *)sendSockData.data, sendSockData.len, 
      0, (struct sockaddr*)&amp;desAddr, sizeof(desAddr) ); <BR> }<BR> return 
      -1;<BR>}</TD></TR></TBODY></TABLE><BR>  (2)MFC规则DLL的InitInstance函数<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>
  <TR>
    <TD>/////////////////////////////////////////////////////////////////////////////<BR>// 
      CMultiThreadDllApp initialization<BR>BOOL 
      CMultiThreadDllApp::InitInstance()<BR>{<BR> if ( !AfxSocketInit() ) 
      //初始化socket<BR> {<BR>  AfxMessageBox( IDP_SOCKETS_INIT_FAILED 
      );<BR>  return FALSE;<BR> }<BR> return 
TRUE;<BR>}</TD></TR></TBODY></TABLE><BR>  (3)启动发送线程<BR><BR>
<TABLE borderColor=#cccccc width="90%" align=center bgColor=#e3e3e3 border=1>
  <TBODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -