使用_beginthreadex的应用程序崩溃 [英] An application using _beginthreadex crashes
问题描述
大家好,
我正在使用_beginthreadex方法在Visual Studio 2008中创建一个带有/MD选项的线程,如MSDN所建议.
代码:
ifdef _WINDOWS
_beginthreadex(NULL,0,&CMyClass :: threadFunction,NULL,0,NULL);
#endif
运行时,我正在安装Visual Studio 2008可发行包,但我的应用程序崩溃了.如果我不使用此方法_beginthreadex,则我的应用程序将运行correclty,
请让我知道我在做什么错,
谢谢,
Yash,
Hi All,
I am using the method _beginthreadex to create a thread in Visual Studio 2008 compiling with /MD option as suggested by MSDN.
Code :
ifdef _WINDOWS
_beginthreadex(NULL,0, &CMyClass::threadFunction, NULL, 0, NULL );
#endif
for running i am installing Visual Studio 2008 restributable package but my application crashes. if i am not using this method _beginthreadex, then my application runs correclty,
Please let me know what mistake am i doing,
Thanks,
Yash,
推荐答案
CMyClass :: threadFunction必须是该类的静态函数,因为_beginthreadex无法理解隐藏的"this"指针. />
我通常将指针作为_beginthreadex的参数传递给类,以便在静态函数内可以转换为使用指针来调用成员函数.
在CodeProject中搜索_beginthreadex,我相信您会找到一些示例.
CMyClass::threadFunction needs to be a static function of the class, since the _beginthreadex does not understand the hidden ''this'' pointer.
I usually pass the pointer to the class as the argument to _beginthreadex so that inside the static function you can convert over to calling a member function via use of the pointer.
Search CodeProject for _beginthreadex and I am sure you will find some examples.
这篇关于使用_beginthreadex的应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!