首页 > 解决方案 > 视觉工作室 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 标志的情况下解决此错误?

标签: c++visual-studio

解决方案


您的一个论点是 const 而另一个不是。我不知道 InstallService 是什么预期的,但似乎是预期的 const 值。尝试这个。


推荐阅读