"LPVOID"不能分配给 X 类型的实体
"LPVOID" can not be assigned to an entity of the type X
我正在处理一个处理USB设备的函数。
但是我已经在一些简单的事情上遇到了问题:
我得到编译错误
A value of the type "LPVOID" can not be assigned to an entity of the type "PSP_DEVICE_INTERFACE_DETAIL_DATA" in the line
"DevIntfDetailData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);"
谁能告诉我我在这里做错了什么?谢谢你!PSP_DEVICE_INTERFACE_DETAIL_DATA DevIntfDetailData;
DevIntfDetailData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);
必须工作:
DevIntfDetailData = reinterpret_cast<PSP_DEVICE_INTERFACE_DETAIL_DATA>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize));
HealAlloc(像所有其他alloc函数一样)返回指向内存堆(void*)的指针,并且c++不允许将类型T*的值设置为类型void*的值而不手动强制转换。
存在dynamic_cast、static_cast、reinterpret_cast和const_cast。当你想要将void*转换为任何指针时,你必须使用reinterpret_cast,因为它转换类型时不需要进行任何检查(将void*转换为任何T*不会通过任何检查)。
相关文章:
- 不能将 "void *" 类型的值分配给类型 "TCHAR" 的实体
- 需要帮助在 c++ 中将字符串转换为字符 ----错误 "const char *" 类型的值不能用于初始化 "char" 类型的实体
- 无法将错误分配给成员函数中"类型的实体"
- "const wchar_t *" 类型的值不能用于初始化类型 "const PWSTR" 的实体
- Visual Studio C++:不能使用类型为 "const wchar_t *" 的值来初始化类型为 "TCHAR *" 的实体
- 不能将 "void *" 类型的值分配给类型 "RANDOMSTRUCT *" 的实体
- 回调方法显示错误,类型为"void(*)"的值不能用于初始化类型的实体
- 智能感知:不能使用 "PVOID" 类型的值初始化 "_NtQuerySystemInformation" 类型的实体
- 不能将 "const char*" 类型的值分配给类型 "int" 的实体
- 类型值不能用于初始化类型实体
- 不能将 "const char *" 类型的值分配给类型为 "LPSTR" 的实体
- c 11申请人(e)是e命名的实体的类型
- 错误:无法将 "double*" 类型的值分配给类型 "double" 的实体
- 智能感知:不能将 "void" 类型的值分配给类型 "double" 的实体
- 值类型 const char 不能用于初始化 char* 类型的实体
- ECS实体可以有多个给定类型的组件
- "char *" 类型的值不能用于初始化类型 "char" 的实体
- "const wchar_t *" 类型的值不能用于初始化类型为 "LPCSTR" 的实体
- 如何确定Tcl_Obj是否是某种类型的 ttk:: 实体,例如 ttk:entry
- 标识派生类类型的正确方法(类型实体VS dynamic_case)