读书人

关于BeginThreadex()函数解决方案

发布时间: 2012-02-16 21:30:36 作者: rapoo

关于BeginThreadex()函数
问题(1)在一个类的成员函数的程序中我有以下语句:

h[0]=(HANDLE)::_beginthreadex(NULL,0,bank_allocation,NULL,0,&uld);

其中bank_allocation是类中另一个成员函数的名称,其声明如下:

UINT __stdcall Cresource::bank_allocation(LPVOID lpParam);

编绎出错(出错位置就是上面使用beginThreadex()处),提示如下:
G:\resource\resource.cpp(100) : error C2664: '_beginthreadex ' : cannot convert parameter 3 from 'unsigned int (void *) ' to 'unsigned int (__stdcall *)(void *) '
None of the functions with this name in scope match the target type
出错原因是参数类型不对,想不通,bank_allocation()这个函数的类型我已经声明为UINT __stdcall 了啊,高手指教一下,
(2)如何使用beginThreadex向新线程传递参数?比如,要传一个整形变量
非常感谢


[解决办法]
&uld 就是 lpParam,传入uld 这个结构的指针。在bank_allocation(LPVOID lpParam);在转换回来就可以了

读书人网 >VC/MFC

热点推荐