简体   繁体   中英

invalid conversion from 'DWORD (*)(void*)' to 'DWORD (*)(void*)'

invalid conversion from 'DWORD (*)(void*)' to 'DWORD (*)(void*)' . cake==lie 1==0

I have no idea what this means ... I get it in this code

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是成员函数,则必须为静态。

See here: in-c-is-it-safe-portable-to-use-static-member-function-pointer-for-c-api-callb for why you need to use a extern "C"

The correct way would be somthing like this:

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)
}

Is it to do with objects - there's an implicit 'this' paramter to your object's StartWinampThread method because it's a member of a class.

What happens if you change it to be a standalone method but keep the same signature ie from

DWORD  WINAPI CPlugin::StartWinampThread(void* lpParam)[...]

to DWORD WINAPI StartWinampThread(void* lpParam)[...]

(I know it won't work for you, I'm just interested to see if it removes the compiler's complaint)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM