liusz
驱动牛犊
驱动牛犊
  • 注册日期2004-03-16
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分29分
  • 威望43点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
阅读:1556回复:0

请教VC _beginthreadex error C2664答案

楼主#
更多 发布于:2004-08-13 16:53
请教VC _beginthreadex error C2664

是关于DDK程序移植到VC程序参数类型错误的问题。

虽然是关于VC程序,但是还是驱动开发中才会遇到的问题,所以还是发到这里来了。

 我请教的是WINAPI函数_beginthreadex
函数的原型是这样的:
unsigned long _beginthreadex( void *security, unsigned stack_size, unsigned ( __stdcall *start_address )( void * ), void *arglist, unsigned initflag, unsigned *thrdaddr );
出错在第三个参数上unsigned ( __stdcall *start_address )( void * )。通常见到的用法是这样的:
DWORD WINAPI
myfunction(LPVOID param)
{//… …}

_beginthreadex (NULL, 0, myfunction, (LPVOID)mylist, 0, &thread_id);
这样写的程序在DDK下编译为CONSOLE控制台程序没有任何问题,可是当我在VC下这么使用的时候,却编译不过去,出错信息如下:
error C2664: '_beginthreadex' : cannot convert parameter 3 from 'unsigned long (void *)' to 'unsigned int (__stdcall *)(void *)'
None of the functions with this name in scope match the target type
相信老大们早就经历过这个问题了,请指点指点迷途。

答案:
punk:

在函数申明前加 extern "C" 或者static

extern "C" unsigned int WINAPI my_thread(LPVOID param)
{
char *mystr=(char *)param;
//DO STH...
return 0;
}


arthurtu2000:
你的myfunction(LPVOID param)必须声明为__stdcall
UINT WINAPI my_thread(LPVOID param)
{
char *mystr=(char *)param;
//DO STH...
return 0;
}


太感谢了,两位的方法都可以。我在这个问题上折腾了好几天了,查MSDN,问GOOGLE,查看头文件,...



游客

返回顶部