阅读:3660回复:9
请教VC _beginthreadex error C2664(分数可以翻倍的给)
请教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 相信老大们早就经历过这个问题了,请指点指点迷途。 |
|
沙发#
发布于:2004-08-13 11:16
请教VC _beginthreadex error C2664(分数可以翻倍的给) cut WINAPI就行了 |
|
|
板凳#
发布于:2004-08-13 12:53
CUT掉WINAPI ,错误依旧 :mad: 是不是还有其他什么地方需要改变? 在程序里面 DWORD WINAPI FUNCABC()这样的函数定义例子很多的,估计还会遇到更多的类似问题。现在绕不过去的就是这个_beginthreadex的参数错误问题。 老大,拉我一把。 |
|
地板#
发布于:2004-08-13 14:48
WINAPI改成__stdcall :) |
|
|
地下室#
发布于:2004-08-13 16:09
还是不可以啊,下面是我的问题的简化例子,请您给修改正确了发上来把。我编程的确是太弱。 :(
|
|
|
5楼#
发布于:2004-08-13 16:18
你的myfunction(LPVOID param)必须声明为__stdcall
|
|
6楼#
发布于:2004-08-13 16:23
这样:
UINT WINAPI my_thread(LPVOID param) { char *mystr=(char *)param; //DO STH... return 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; } |
|
|
8楼#
发布于:2004-08-13 16:43
太感谢了,两位的方法都可以。我在这个问题上折腾了好几天了,查MSDN,问GOOGLE,查看头文件,...
这样好了,每人在这个帖子给十分,然后我再开个新帖子,每人给10分,不知道有没有办法一次就把分给了。 |
|
9楼#
发布于:2004-08-13 21:35
不好意思,说给分的话,让大侠见笑了。我其实只是表示感谢,谢谢了。 |
|