[英]initializing : cannot convert from LPVOID error
Ok I'm trying to write this under the WFSExecute but if I type: 好的,我尝试在WFSExecute下编写此代码,但是如果输入:
WFSPINGETDATA * pingetdata = lpCmdData;
I get an error: 我收到一个错误:
errorC2440: 'initializing' : cannot convert from 'LPVOID' to 'WFSPINGETDATA *'
errorC2440:“正在初始化”:无法从“ LPVOID”转换为“ WFSPINGETDATA *”
If I comment out that line, the app execute. 如果我注释掉该行,则该应用程序将执行。
Also, if I write: 另外,如果我写:
((WFSPINDATA*) (temp)) ->lpPinKeys = malloc(sizeof(LPWFSPINKEY)*NumberOfKeys) ;
I get an error: 我收到一个错误:
errorC2440: '=' cannot convert from 'void' to 'LPWFSPINKEY *'
errorC2440:'='无法从'void'转换为'LPWFSPINKEY *'
Any solution to solve this? 有解决方案吗?
C++ is more strict on type safety than C is. C ++在类型安全方面比C更严格。 In this case,
void*
must be type-casted when assigned to anything other than another void*
. 在这种情况下,
void*
必须型铸造时分配到比其它任何其他void*
。
WFSPINGETDATA * pingetdata = lpCmdData;
cannot convert from 'LPVOID' to 'WFSPINGETDATA *'
无法从“ LPVOID”转换为“ WFSPINGETDATA *”
This means lpCmdData
is a void*
, so a type-cast is needed: 这意味着
lpCmdData
为void*
,因此需要类型转换:
WFSPINGETDATA * pingetdata = (WFSPINGETDATA*) lpCmdData;
Or, using a C++-style cast instead of a C-style cast: 或者,使用C ++样式转换而不是C样式转换:
WFSPINGETDATA * pingetdata = static_cast<WFSPINGETDATA*>(lpCmdData);
((WFSPINDATA*) (temp)) ->lpPinKeys = malloc(sizeof(LPWFSPINKEY)*NumberOfKeys) ;
cannot convert from 'void' to 'LPWFSPINKEY *'
无法从“无效”转换为“ LPWFSPINKEY *”
malloc()
returns a void*
, so a type-cast is needed here as well: malloc()
返回void*
,因此这里也需要类型转换:
((WFSPINDATA*) (temp)) ->lpPinKeys = (LPWFSPINKEY*) malloc(sizeof(LPWFSPINKEY)*NumberOfKeys);
Or, using C++-style casts: 或者,使用C ++样式转换:
static_cast<WFSPINDATA*>(temp)->lpPinKeys = static_cast<LPWFSPINKEY*>(malloc(sizeof(LPWFSPINKEY)*NumberOfKeys));
Or, using C++-style allocation instead of C-style allocation: 或者,使用C ++样式分配而不是C样式分配:
static_cast<WFSPINDATA*>(temp)->lpPinKeys = new LPWFSPINKEY[NumberOfKeys];
// must use 'delete[] lpPinKeys' instead of 'free(lpPinKeys)' to deallocate the memory
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.