视觉工作室 2017;“const wchar_t *"类型的参数与“PWSTR"类型的参数不兼容启用/permissive 时 [英] Visual Studio 2017; argument of type "const wchar_t *" is incompatible with parameter of type "PWSTR" when /permissive is enabled

查看:37
本文介绍了视觉工作室 2017;“const wchar_t *"类型的参数与“PWSTR"类型的参数不兼容启用/permissive 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用 C++ 创建一个 Windows 服务(对它来说很新).

I am attempting to create a windows service in C++ (very new to it).

作为模板,我使用的是 MDSN 提供的示例:https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948

As a template, I am using this MDSN provided example: https://code.msdn.microsoft.com/windowsapps/CppWindowsService-cacf4948

如果一致性模式 (/permissive-) 标志设置为 yes,则该项目将不会构建.它会出错并出现以下错误

This project will not build if the Conformance Mode (/permissive-) flag is set to yes. It will error out with the following error

E0167 类型const wchar_t *"的参数与类型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,它的目的是让我的代码更合规.

Obviously, I could disable the flag, but it seems like a bad idea, as according to https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2017, its purpose is to make my code more compliant.

因此,我的问题如下:如何在不禁用/permissive 标志的情况下解决此错误?

Therefore, my question is as follows: how do I get around this error without disabling the /permissive flag?

推荐答案

你的一个参数是 const 而另一个不是的问题.我不知道什么 InstallService 是预期的,但似乎它是预期的 const 值.试试这个.

The problem that one of your arguments is const and another one is not. I don't know what InstallService is expected, but seems like it's expected const value. Try this.

这篇关于视觉工作室 2017;“const wchar_t *"类型的参数与“PWSTR"类型的参数不兼容启用/permissive 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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