4Manuals

  • PDF Cloud HOME

由于类型从C转换为C ++,因此无法编译并显示错误C2440 Download

    获取Hough线的交点OpenCV C ++ 如何将字符串“ text1”设置为包含项目text1,text2,test3的组合框的选定项目? 为什么System.Net.Mail.MailAddress构造函数在域部分中解析带有斜杠“ /”的电子邮件? Android 10,API29:在应用程序文件夹中使用C ++库编写文件会使应用程序崩溃 Unity-LineRenderer没有出现在版本(2D)上 按下按钮后,电话中未显示通知 ASP.net,使用WebConfig httpErrors重定向到区域内的控制器不起作用 获取会议室详细信息 我们如何将参数Line转换为Station? 网络核心:查找实体框架核心的主键和反射

inline BOOL FupVmCall(ULONG_PTR hypercall_number, void *context) {
#pragma section(".asm", read, execute)
  __declspec(allocate(".asm")) static const BYTE CODE[] = {
      0x0F, 0x01, 0xC1, //    vmcall
      0x74, 0x0E,       //    jz      short errorWithCode
      0x72, 0x04,       //    jb      short errorWithoutCode
      0x48, 0x33, 0xC0, //    xor     rax, rax
      0xC3,             //    retn
                        // errorWithoutCode:
      0x48, 0xC7, 0xC0, 0x02, 0x00, 0x00, 0x00, //    mov     rax, 2
      0xC3,                                     //    retn
                                                // errorWithCode:
      0x48, 0xC7, 0xC0, 0x01, 0x00, 0x00, 0x00, //    mov     rax, 1
      0xC3,                                     //    retn
  };

  typedef unsigned char(__stdcall * AsmVmxCallType)(
      _In_ ULONG_PTR hypercall_number, _In_opt_ void *context);

#pragma warning(suppress : 4055)
  AsmVmxCallType AsmVmxCall = (AsmVmxCallType)CODE;

  __try {
    return AsmVmxCall(hypercall_number, context) == 0;
  } __except (EXCEPTION_EXECUTE_HANDLER) {
    SetLastError(GetExceptionCode());
    return FALSE;
  }
}

我正在尝试使用VS2019从C ++项目中编译以上代码

如果我将主文件更改为main.c,它可以毫无问题地编译

但是,如果将其更改为main.cpp,则会出现C2440类型转换问题。

C2440   'type cast': cannot convert from 'const BYTE [27]' to 'AsmVmxCallType'
AsmVmxCallType AsmVmxCall = (AsmVmxCallType)CODE;

我什至尝试用extern "C"包装,但没有解决问题。

我该如何进行类型转换?

1 个答案:

答案 0 :(得分:2)

您可以先将CODE转换为空指针,然后将其转换为函数指针:

AsmVmxCallType AsmVmxCall = (AsmVmxCallType)(void *)CODE;



Similar searches
    如何从列表内的字典中获取键值对的值,并且键以非常特定的字母开头 敌人中的AI,Unity 2D 无法将变量通过gitlab桥传递到另一个管道 是否可以配置为在Spring Boot 2应用程序中使用外部PersistenceManagerFactory 使用fs-s3fs python PyFilesystem公开S3文件