急急~~~关于_beginthreadex函数 在dll中的用法

zhongbin104 2010-02-21 01:07:29
static UINT WINAPI SecondThreadFunc( PVOID pArguments )
{
//MyThreadProcess *mythread=(MyThreadProcess *)pArguments;
MyThreadNamespace *mythreadname=(MyThreadNamespace *)pArguments;
mythreadname->helpthreadfun();
//_endthreadex( 0 );
return 0;
}

void MyThreadNamespace::helpthreadfun()
{
mythread->ThreadfunRun(FunctionName);
}

int MyThreadNamespace::beginthread(MyDataList * list)
{
unsigned threadID;
HANDLE hThread;
FunctionName=NULL;

XMLCh * functionname=list->getListHead()->getData()->fData.fValue.f_strVal;


//先将得到的方法赋予全局变量FunctionName
FunctionName=functionname;

hThread=(HANDLE)_beginthreadex(NULL,0,&SecondThreadFunc,(PVOID)list,0,&threadID );

int handle=(int)hThread;
return handle;
}

以上是我在DLL中创建线程的代码。。。
现在出现一个问题。。 程序有时候会报错如下:
“MyTest.exe 中的 0x007443c0 处未处理的异常: 0xC0000005: 读取位置 0x007443c0 时发生访问冲突”。。

通过调试发现是在这里:(是在threadex.c的文件中)

static void _callthreadstartex(void)
{
_ptiddata ptd; /* pointer to thread's _tiddata struct */

/* must always exist at this point */
ptd = _getptd();

/*
* Guard call to user code with a _try - _except statement to
* implement runtime errors and signal support
*/
__try {
_endthreadex (
( (unsigned (__CLR_OR_STD_CALL *)(void *))(((_ptiddata)ptd)->_initaddr) )
( ((_ptiddata)ptd)->_initarg ) ) ; ---->程序就是从这里抛出的异常
}
__except ( _XcptFilter(GetExceptionCode(), GetExceptionInformation()) )
{
/*
* Should never reach here
*/
_exit( GetExceptionCode() );

} /* end of _try - _except */

}

我就奇怪了。我只调用了一个线程创建函数,为什么系统会自己去调用_endthreadex ?
我不知道是我代码写错了还是内存出错或者什么其他原因。希望大家给点自己的想法。。

现在出现的异常情况是:异常时有时无的。。没异常的话。程序可以正常运行。但是有个异常就不一样了。
参与者都有分。。 有满意回帖。将给予加分感谢。。
...全文
289 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
低头路过 2011-08-30
  • 打赏
  • 举报
回复
好可怜的帖子。。。沉了

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧