錯誤的資訊為:error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
今天在公司用winsdk寫了個線程的東西,回來後想用mfc的一些封裝類來寫,發現的确很簡單,很多參數都不用了。
用AfxBeginThread建立了個線程的指針也就是CWinThread *thread
一起看一下代碼吧:
CWinThread *thread;
thread = AfxBeginThread(ThreadCallFunc, (LPVOID)this);
因為ThreadCallFunc是線程的回調函數,我想當然的用Class Wizard來給View類添加了個成員函數,
産生的函數為
UINT CVedioView::ThreadCallFunc(LPVOID pParam)
{
return 0;
}
我編譯就出現:error C2665: 'AfxBeginThread' : none of the 2 overloads can convert parameter 1 from type 'unsigned int (void *)'
的錯誤,google了很多有的說是回調函數必須是static我也嘗試了還是錯誤。最後找到問題,就是不要用Class Wizard給View類添加成員函數,而是自己在cpp裡面添加一個函數也就是:
UINT ThreadCallFunc(LPVOID pParam)
{
return 0;
}
這樣就好了。