Visual Studio 2017;当启用/ permissive时,“ const wchar_t *”类型的参数与“ PWSTR”类型的参数不兼容

时间:2018-10-19 16:47:41

标签: c++ visual-studio

我正在尝试用C ++创建Windows服务(这是新的)。

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

如果“一致性模式”(/ permissive-)标志设置为“是”,则将不会构建此项目。它将出现以下错误

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标志的情况下解决此错误?

1 个答案:

答案 0 :(得分:0)

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