n00b
n00b

Reputation: 5732

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)[...]

Upvotes: 1

Views: 2443

Answers (3)

Loki Astari
Loki Astari

Reputation: 264591

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

Upvotes: 2

deanWombourne
deanWombourne

Reputation: 38475

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 i.e. 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)

Upvotes: 0

Dialecticus
Dialecticus

Reputation: 16759

StartWinampThread must be static if it is member function.

Upvotes: 5

Related Questions