简体   繁体   English

初始化:无法从LPVOID错误转换

[英]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: 这意味着lpCmdDatavoid* ,因此需要类型转换:

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.

相关问题 错误C2440:“正在初始化”:无法从“ LPVOID”转换为“ UINT” - error C2440: 'initializing' : cannot convert from 'LPVOID' to 'UINT 在字符错误 C2440 中转换 LPVOID:= - convert LPVOID IN CHAR ERROR C2440: = 错误 C2440:“正在初始化”:无法从“CTable”转换为“CTable” - Error C2440: 'initializing': cannot convert from 'CTable' to 'CTable' 错误 C2440:“正在初始化”:无法从 - error C2440: 'initializing' : cannot convert from 错误C2440:“正在初始化”:无法从“类名*”转换为“类名” - error C2440: 'initializing' : cannot convert from 'classname *' to 'classname' “正在初始化”:无法从“EVENTLOGRECORD *”转换为“EVENTLOGRECORD []” - 'initializing': cannot convert from 'EVENTLOGRECORD *' to 'EVENTLOGRECORD []' &#39;正在初始化&#39;:无法从&#39;Array转换 <int,3> &#39;到&#39;int&#39; - 'initializing': cannot convert from 'Array<int,3>' to 'int' 错误 3 错误 C2440:“正在初始化”:无法从“void *”转换为“Socket *” - Error 3 error C2440: 'initializing' : cannot convert from 'void *' to 'Socket *' 错误C2440:“正在初始化”:在Visual Studio 2008中无法从“ const jchar *”转换为“ LPCWSTR” - error C2440: 'initializing' : cannot convert from 'const jchar *' to 'LPCWSTR' in Visual Studio 2008 错误C2440:&#39;初始化&#39;:无法从&#39;const int&#39;转换为&#39;int *&#39; - error C2440: 'initializing' : cannot convert from 'const int' to 'int *'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM