VC驿站

 找回密码
 加入驿站

QQ登录

只需一步,快速开始

搜索
查看: 914|回复: 3

多线程封装成DLL动态链接库相关教程

[复制链接]
52_avatar_middle
最佳答案
0 
在线会员 发表于 2021-7-25 10:31:19 | 显示全部楼层 |阅读模式
最近学习将创建多线程封装成动态链接库的方法,有没有大佬提示一下怎么相关资料啊




上一篇:如何解决mfc程序一按Enter就退出?
下一篇:创建Project时如何将h文件和cpp文件分别存储在预先设定的文件夹里面
31_avatar_middle
最佳答案
62 
在线会员 发表于 2021-7-25 16:26:38 | 显示全部楼层
多线程的创建和使用,DLL跟在EXE没多大区别.
DLL使用Createthread,或者使用C++的_beginthread比较方便些

  1. // crt_begthrdex.cpp
  2. // compile with: /MT
  3. #include <windows.h>
  4. #include <stdio.h>
  5. #include <process.h>

  6. unsigned Counter;
  7. unsigned __stdcall SecondThreadFunc( void* pArguments )
  8. {
  9.     printf( "In second thread...\n" );

  10.     while ( Counter < 1000000 )
  11.         Counter++;

  12.     _endthreadex( 0 );
  13.     return 0;
  14. }

  15. int main()
  16. {
  17.     HANDLE hThread;
  18.     unsigned threadID;

  19.     printf( "Creating second thread...\n" );

  20.     // Create the second thread.
  21.     hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );

  22.     // Wait until second thread terminates. If you comment out the line
  23.     // below, Counter will not be correct because the thread has not
  24.     // terminated, and Counter most likely has not been incremented to
  25.     // 1000000 yet.
  26.     WaitForSingleObject( hThread, INFINITE );
  27.     printf( "Counter should be 1000000; it is-> %d\n", Counter );
  28.     // Destroy the thread object.
  29.     CloseHandle( hThread );
  30. }
复制代码

官方的一些示例:
https://docs.microsoft.com/zh-cn ... eadex?view=msvc-160

52_avatar_middle
最佳答案
0 
ico_lz  楼主| 发表于 2021-8-1 16:04:35 | 显示全部楼层
cpp2019 发表于 2021-7-25 16:26
多线程的创建和使用,DLL跟在EXE没多大区别.
DLL使用Createthread,或者使用C++的_beginthread比较方便些
...

感谢大佬热心解答
68_avatar_middle
最佳答案
0 
在线会员 发表于 2021-8-3 00:31:25 | 显示全部楼层
其实pthread更方便
您需要登录后才可以回帖 登录 | 加入驿站 qq_login

本版积分规则

×【发帖 友情提示】
1、请回复有意义的内容,请勿恶意灌水;
2、纯数字、字母、表情等无意义的内容系统将自动删除;
3、若正常回复后帖子被自动删除,为系统误删的情况,请重新回复其他正常内容或等待管理员审核通过后会自动发布;
4、感谢您对VC驿站一如既往的支持,谢谢合作!

关闭

站长提醒上一条 /2 下一条

QQ|小黑屋|手机版|VC驿站 ( 辽ICP备09019393号-4 )|网站地图wx_jqr

GMT+8, 2023-12-8 17:57

Powered by CcTry.CoM

© 2009-2021 cctry.com

快速回复 返回顶部 返回列表