MSVC 2019:“数组的大小必须大于零" [英] MSVC 2019: "the size of an array must be greater than zero"

查看:21
本文介绍了MSVC 2019:“数组的大小必须大于零"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用其 .dsw 文件将(工作)旧项目迁移到 MSVC 2019.这似乎很顺利,但我在构建时收到错误消息(显示在标题中).错误发生在winnt.h"中.注意:我没有声明任何零长度数组.
我该如何解决这个问题?

I have migrated a (working) older project into MSVC 2019 using its .dsw file. That appeared to go fine but I get the error message (shown in title) upon build. The error occurred in "winnt.h". Note: I have not declared any zero-length arrays.
How do I fix this?

推荐答案

尽管存在完全误导的错误消息,但该问题与零大小数组无关.相反,它是一个结构打包问题.要解决此问题:

Despite the completely misleading error message, the problem has nothing to do with a zero-size array. Rather it is a struct packing issue. To fix this:

解决方案 #1

在包含 windows.h 之前添加以下行

Add the following line before including windows.h

  #define WINDOWS_IGNORE_PACKING_MISMATCH
  #include <windows.h>  

解决方案#2

使用
更改项目中的包装项目 -> 属性 -> C/C++ -> 代码生成 ->结构成员对齐 = "8 字节"

Change the packing in your project using
Project -> Properties -> C/C++ -> CodeGeneration -> Struct Member Alignment = "8 Bytes"

这篇关于MSVC 2019:“数组的大小必须大于零"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆