我想知道是否可以使用不知道的函数指针调用_beginthreadex,而不是基于类设计。例如:
#include <stdio.h>
#include <process.h>
#include <windows.h>
int myThread(void* data)
{
printf("ThreadID: %d \n", GetCurrentThreadId());
return 1;
}
HANDLE callIntThreadFunc(void (*pFunction)(LPVOID), LPVOID pvFuncArgs)
{
//Expected to fail compilation due to __stcall
return (HANDLE) _beginthreadex(NULL, NULL, pFunction, (LPVOID) pvFuncArgs, NULL, NULL);
}
int main(int argc, char *argv[])
{
HANDLE hThread = callIntThreadFunc(myThread, NULL);
WaitForSingleObject(hThread , INFINITE);
return 0;
}我知道_beginthread在转换函数时可以工作(通过下面的代码):
return (HANDLE) _beginthread((void (*)(void*)) pFunction, 0, (LPVOID) pvFuncArgs);因此,我的问题是,在这种情况下是否可以使用_beginthreadex,如果可以,如何使用?任何想法都将不胜感激。
发布于 2013-12-08 20:39:56
找到了我正在寻找的答案--正如露易丝所说,它是可行的,它的转换也很重要。下面的代码使其发生,编译并传播线程;-)
return (HANDLE) _beginthreadex(NULL, NULL,(unsigned (__stdcall*)(void*)) pFunction, pvFuncArgs, NULL, NULL);谢谢大家。
https://stackoverflow.com/questions/20412633
复制相似问题