c++ - 视觉工作室 2017;启用 /permissive 时,“const wchar_t *”类型的参数与“PWSTR”类型的参数不兼容
问题描述
我正在尝试用 C++ 创建一个 Windows 服务(对它来说非常新)。
作为模板,我使用这个 MDSN 提供的示例:https ://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948
如果 Conformance Mode (/permissive-) 标志设置为 yes,则不会构建此项目。它会出错并出现以下错误
E0167 argument of type "const wchar_t *" is incompatible with parameter of type "PWSTR
尝试使用以下功能时:
#define SERVICE_NAME L"CppWindowsService"
InstallService(
SERVICE_NAME, // Name of service - and so on for the other parameters
);
显然,我可以禁用该标志,但这似乎是一个坏主意,根据https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017,其目的是让我的代码更合规。
因此,我的问题如下:如何在不禁用 /permissive 标志的情况下解决此错误?
解决方案
您的一个论点是 const 而另一个不是。我不知道 InstallService 是什么预期的,但似乎是预期的 const 值。尝试这个。
推荐阅读
- mysql - MariaDB 10.1.31 上 TIMESTAMP 查询的错误结果
- c# - 如何将对象内的数据表绑定到 XAML 中的数据网格?
- laravel - 获取 403,使用 laravel 广播的私人频道时出错
- ios - 展开可选 IBOutlet 时出现错误(线程 1:致命错误:展开可选值时意外发现 nil)
- flask - 如何在flask-jwt-extended中的redis中存储jwt令牌?
- module - 如何使用自定义模块在产品视图页面上添加新按钮以打开模块 url
- tinymce - tinyMCE 编辑器或 Jsoup 可以修复 html 标记错误吗?
- python - python结构的新手,无法运行基本代码
- node.js - 尝试 ./bin/www 时,数据存储不是构造器错误
- xml - 将xml转换为cpp的批处理文件