开发者

error C2440: 'initializing' : cannot convert from 'LPVOID' to 'UINT

开发者 https://www.devze.com 2023-01-05 16:31 出处:网络
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)\'

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?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消