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

请教VC _beginthreadex error C2664(分数可以翻倍的给)

楼主#
更多 发布于:2004-08-12 22:23
请教VC _beginthreadex  error C2664(分数可以翻倍的给)
是关于DDK程序移植到VC程序参数类型错误的问题。
虽然是关于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
我请教的是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
驱动小牛
驱动小牛
  • 注册日期2001-04-07
  • 最后登录2018-06-01
  • 粉丝0
  • 关注0
  • 积分621分
  • 威望164点
  • 贡献值0点
  • 好评度60点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-08-13 11:16
请教VC _beginthreadex  error C2664(分数可以翻倍的给)
是关于DDK程序移植到VC程序参数类型错误的问题。
虽然是关于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
我请教的是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
相信老大们早就经历过这个问题了,请指点指点迷途。
  

cut WINAPI就行了
不停学习
liusz
驱动牛犊
驱动牛犊
  • 注册日期2004-03-16
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分29分
  • 威望43点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-08-13 12:53

CUT掉WINAPI ,错误依旧   :mad:

是不是还有其他什么地方需要改变?

在程序里面 DWORD WINAPI FUNCABC()这样的函数定义例子很多的,估计还会遇到更多的类似问题。现在绕不过去的就是这个_beginthreadex的参数错误问题。

老大,拉我一把。
punk
驱动小牛
驱动小牛
  • 注册日期2001-04-07
  • 最后登录2018-06-01
  • 粉丝0
  • 关注0
  • 积分621分
  • 威望164点
  • 贡献值0点
  • 好评度60点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-08-13 14:48

CUT掉WINAPI ,错误依旧   :mad:

是不是还有其他什么地方需要改变?

在程序里面 DWORD WINAPI FUNCABC()这样的函数定义例子很多的,估计还会遇到更多的类似问题。现在绕不过去的就是这个_beginthreadex的参数错误问题。

老大,拉我一把。

WINAPI改成__stdcall :)
不停学习
liusz
驱动牛犊
驱动牛犊
  • 注册日期2004-03-16
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分29分
  • 威望43点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2004-08-13 16:09
还是不可以啊,下面是我的问题的简化例子,请您给修改正确了发上来把。我编程的确是太弱。  :(
附件名称/大小 下载次数 最后更新
2004-08-13_mythread.rar (35KB)  1
arthurtu
驱动巨牛
驱动巨牛
  • 注册日期2001-11-08
  • 最后登录2020-12-19
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望161点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
  • 社区居民
5楼#
发布于:2004-08-13 16:18
你的myfunction(LPVOID param)必须声明为__stdcall
arthurtu
驱动巨牛
驱动巨牛
  • 注册日期2001-11-08
  • 最后登录2020-12-19
  • 粉丝0
  • 关注0
  • 积分26分
  • 威望161点
  • 贡献值0点
  • 好评度35点
  • 原创分0分
  • 专家分0分
  • 社区居民
6楼#
发布于:2004-08-13 16:23
这样:

UINT WINAPI my_thread(LPVOID param)
{
char  *mystr=(char *)param;
    //DO STH...
return 0;
}
punk
驱动小牛
驱动小牛
  • 注册日期2001-04-07
  • 最后登录2018-06-01
  • 粉丝0
  • 关注0
  • 积分621分
  • 威望164点
  • 贡献值0点
  • 好评度60点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2004-08-13 16:36
还是不可以啊,下面是我的问题的简化例子,请您给修改正确了发上来把。我编程的确是太弱。  :(


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

extern "C" unsigned  int WINAPI my_thread(LPVOID param)
{
char  *mystr=(char *)param;
    //DO STH...
return 0;
}
不停学习
liusz
驱动牛犊
驱动牛犊
  • 注册日期2004-03-16
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分29分
  • 威望43点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2004-08-13 16:43
太感谢了,两位的方法都可以。我在这个问题上折腾了好几天了,查MSDN,问GOOGLE,查看头文件,...

这样好了,每人在这个帖子给十分,然后我再开个新帖子,每人给10分,不知道有没有办法一次就把分给了。
liusz
驱动牛犊
驱动牛犊
  • 注册日期2004-03-16
  • 最后登录2018-05-26
  • 粉丝0
  • 关注0
  • 积分29分
  • 威望43点
  • 贡献值0点
  • 好评度2点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2004-08-13 21:35


不好意思,说给分的话,让大侠见笑了。我其实只是表示感谢,谢谢了。
游客

返回顶部