hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID )有关问题?

mengyq_82 2006-09-25 02:43:48
在msdn中这样的例子:
是关于_beginthreadex的
// crt_begthrdex.cpp
// compile with: /MT
#include <windows.h>
#include <stdio.h>
#include <process.h>

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

while ( Counter < 1000000 )
Counter++;

_endthreadex( 0 );
return 0;
}

int main()
{
HANDLE hThread;
unsigned threadID;

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

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

// Wait until second thread terminates. If you comment out the line
// below, Counter will not be correct because the thread has not
// terminated, and Counter most likely has not been incremented to
// 1000000 yet.
WaitForSingleObject( hThread, INFINITE );
printf( "Counter should be 1000000; it is-> %d\n", Counter );
// Destroy the thread object.
CloseHandle( hThread );
}
我就直接将此代码拷贝到mfc程序中,进行编译时出现如下错误:
error C2276: '&' : illegal operation on bound member function expression
请问大家是怎么回事?
...全文
798 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
kouzhongling 2006-12-16
  • 打赏
  • 举报
回复
msdn的代码一般不会有问题 可能是环境设置问题
我在vs2005编译了一下没问题
在vc6编译要要求对Multi-threaded 的设置(vc6默认不支持)
setup:
Open the project settings dialog and select the C/C++ tab. Select the category Code Generation For the Win32 Release configuration, set Use run-time library to Multithreaded DLL.

blastzgd 2006-12-16
  • 打赏
  • 举报
回复
unsigned __stdcall SecondThreadFunc( void* pArguments );
hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );

已测试.
Sco_field 2006-12-13
  • 打赏
  • 举报
回复

hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc, NULL, 0, &threadID );
改成这样hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );

会出现如下问题:
rror 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

darkwail 2006-09-30
  • 打赏
  • 举报
回复
hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );
改成这样
gnixemos 2006-09-28
  • 打赏
  • 举报
回复
WINAPI 就是__stdcall
maywemeet 2006-09-26
  • 打赏
  • 举报
回复
用WINAPI替换__stdcall
abomber2 2006-09-26
  • 打赏
  • 举报
回复
线程函数SecondThreadFunc定义错误
应该是UINT WINAPI SecondThreadFunc(LPVOID)
是__stdcall
mengyq_82 2006-09-25
  • 打赏
  • 举报
回复
如果按楼上的改的话,会出现如下问题:
rror 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
vagabond2002 2006-09-25
  • 打赏
  • 举报
回复
hThread = (HANDLE)_beginthreadex( NULL, 0, SecondThreadFunc, NULL, 0, &threadID );
不就结了

15,471

社区成员

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

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