invalid conversion from 'DWORD (*)(void*)' to 'DWORD (*)(void*)'
我不知道这意味着什么…我把它记在这个密码里了
1 2 3 4 5 6 7 8 9 10 11 12 13 | HANDLE CPlugin::CreateWinampThread() || { __VVVVVVVV__ hWinampThreadHandle = (HANDLE)CreateThread(NULL, 0, StartWinampThread, (void*)this, 0, &dwWinampThreadID); if (!hWinampThreadHandle) return 0; CloseHandle(hWinampThreadHandle); return hWinampThreadHandle; } . DWORD WINAPI CPlugin::StartWinampThread(void* lpParam)[...] |
如果startwinampthread是成员函数,则它必须是静态的。
参见这里:in-c-is-it-safe-portable-to-use-static-member-function-pointer-for-c-api-callb了解为什么需要使用外部"c"
正确的方法是这样的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | HANDLE CPlugin::CreateWinampThread() || { __VVVVVVVV__ hWinampThreadHandle = (HANDLE)CreateThread(NULL, 0, ::StartWinampThread, (void*)this, 0, &dwWinampThreadID); if (!hWinampThreadHandle) return 0; CloseHandle(hWinampThreadHandle); return hWinampThreadHandle; } . // A callback function for C code must have C linkage. // That is not possable for C++ static member functions. extern"C" DWORD WINAPI StartWinampThread(void* lpParam) { // You can always call your static member function here. CPlugin::StartWinampThread(lpParam) } |
是否与对象有关-对象的startwinampthread方法有一个隐式的"this"参数,因为它是类的成员。
如果将其更改为独立方法,但保留相同的签名,即
1 | DWORD WINAPI CPlugin::StartWinampThread(void* lpParam)[...] |
到dword winapi startwinampthread(void*lpparam)[…]
(我知道它对你不起作用,我只是想看看它是否能消除编译器的抱怨)