tags:

views:

37

answers:

1

Im getting the following error while trying to convert code from C to C++:

error C2440: 'initializing' : cannot convert from 'LPVOID' to 'UINT (__cdecl *)(LPVOID,UINT,LPWSTR,UINT)'

Here's the piece of code causing problems:

UINT (*GetString)( LPVOID rsrc, UINT res, LPWSTR buf, UINT len )
       = (LPVOID)0x4347e0;

How do I fix it?

+5  A: 

You're trying to convince the compiler to treat 0x4347e0 (which is of type 'int') to be a pointer to a function taking 4 parameters. Casting the int to LPVOID isn't going to satisfy the compiler - you need to cast it to the right thing:

typedef UINT (*GetStringFnPtr)(LPVOID rsrc, UINT res, LPWSTR buf, UINT len );
GetStringFnPtr GetString = (GetStringFnPtr)0x4347e0;
JBRWilkinson