描述:
我在线程中用到了不少c runtime 的函数,如strlen等等。按照道理似乎应该使用beginthreadEx,但是我的activex是用MFC开发的,这样按照道理,似乎又应该使用Afxbeginthread。还有,如果我在项目设置里选择不使用mfc,整个程序正常运行。请问我到底该使用哪个函数。请高手帮我分析一下。
解决方案1:
用MFC的Afxbeginthread吧,他做了一些有关安全性的处理,你看他的代码就知道了。
解决方案2:没有什么区别,说到底它们都是对API的封装,用谁就看你对谁熟了。只是后者相对更为安全、稳定一些。
解决方案3:使用哪个都一样。最好是去_beginthreadEX。基于c运行库,不需要特别的加载
解决方案4:beginthreadEx中不使用MFC就没问题。否则还是用MFC的Afxbeginthread吧。MFC里面大把的函数引用线程局部存储的。
解决方案5: use CreateThread ,example:
DWORD WINAPI FirstSyncThread( LPVOID lpParam )
{
...
}
void FirstSyncWithRemote()
{
DWORD dwThreadId;
HANDLE hThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
FirstSyncThread, // thread function
NULL, // argument to thread function
0, // use default creation flags
&dwThreadId); // returns the thread identifier
// Check the return value for success.
if (hThread == NULL)
{
char szMsg[256];
memset(szMsg,0,256);
wsprintf( szMsg, "CreateThread failed." );
MessageBox( NULL, szMsg, "TEST", MB_OK );
}
}
您可能想查找下面的文章:
- 急,我有一多线程程序在NT下运行良好,但在98下_beginthreadex返回0
- 为什么我在程序中已经声明了#include<processh>还是不能用_beginthreadex
- _beginthreadex是工作线程,一次执行完后线程就结束了,用它如何能监视串口呀?神呀,救救我吧,我快不行了!
- _beginthread和_beginthreadex有什么不同啊
- _beginthreadex创建的线程能不能调用Getexitcodethread()?
- 关于_beginthreadex的第四个参数!
- 为什么我在程序中已经声明了#include<processh>还是不能用_beginthreadex
- 使用_beginthreadex创建线程失败
- 请问用_beginthreadex创建的线程是否可以在线程函数里调用MFCAPI或WIN32API函数
- beginthreadex怎么用呀?