Winforms 关于“IServiceProvider”的大量错误

Winforms 关于“IServiceProvider”的大量错误,winforms,visual-studio-2017,c++-cli,Winforms,Visual Studio 2017,C++ Cli,奇怪的问题 这是一个使用VisualStudio Community 2017的C++CLI WinForms项目 bgstatinsterface.cpp 卢德尔 GameCollection.cpp 游戏收藏 问题是: 在LuaReader.cpp中,如果我需要包含bgstatintinterface.h,以便它可以访问由PointA表示的addMsg方法,它将不会编译,并将生成下面列出的错误 但是,如果我从LuaReader.h中删除GameCollection.h include,以便创

奇怪的问题

这是一个使用VisualStudio Community 2017的C++CLI WinForms项目

bgstatinsterface.cpp

卢德尔

GameCollection.cpp

游戏收藏

问题是:

在LuaReader.cpp中,如果我需要包含bgstatintinterface.h,以便它可以访问由PointA表示的addMsg方法,它将不会编译,并将生成下面列出的错误

但是,如果我从LuaReader.h中删除GameCollection.h include,以便创建GameCollection对象(如B点所示),则它与LuaReader.cpp文件中包含的bgstatintInterface.h没有任何问题,并且编译/运行的所有内容都没有问题

我不知道该怎么办。。。为什么只有在LuaReader.h中不创建GameCollection对象时它才起作用

我做错了什么

错误:


当框架具有System::IServiceProvider时,使用定义为::IServiceProvider的include Windows.h时会发生这种情况,然后当某个范围中存在使用命名空间系统时,它就会变得模棱两可


解决方案是简单地将delcaration放在您自己的名称空间中

当框架具有System::IServiceProvider时,使用定义为::IServiceProvider的include Windows.h时会发生这种情况,然后当某个范围内存在使用命名空间系统时,它就会变得模棱两可


解决方案是简单地将delcaration放在您自己的名称空间中

如果您的项目很小,请在此提供另一个解决方案-删除:

using namespace System;

并在系统类的代码中使用完整的类型名,例如System::String^。

如果您的项目很小,请在此处提供另一个解决方案-删除:

using namespace System;

并在系统类的代码中使用完整类型名称,例如System::String^。

要解决此问题,请在声明名称空间和/或使用语句之前,将包含windows.h的include文件放入其中:

因此:

而不是

using namespace System;

#include "stdafx.h"

要解决此问题,请在声明名称空间和/或使用语句之前,将包含windows.h的include文件放入其中:

因此:

而不是

using namespace System;

#include "stdafx.h"

常见事故提示当您包括Windows.h时,它定义::IServiceProvider。该框架具有System::IServiceProvider,非常不同的动物。当某个地方的作用域中有一个使用名称空间系统时,它就会变得不明确。就像那个GameCollection.h include文件一样。using语句在.h文件中非常有害,要么不使用它们,要么像您应该的那样将该声明放在名称空间中,并将using指令放在该名称空间中。在BGStatsInterface中自动生成的代码中有一个很好的例子。h@HansPassant啊!!非常感谢。这很有效。快速相关问题,我应该为所有类使用名称空间吗?是的,全局名称空间是C声明的家。感谢您的帮助!:如果您将其添加为回复,我会将其标记为解决方案,我不认为我可以将评论标记为解决方案。只需使用您所学到的内容自己完成Q+a。当您包含Windows.h时,常见的意外情况是,它定义::IServiceProvider。该框架具有System::IServiceProvider,非常不同的动物。当某个地方的作用域中有一个使用名称空间系统时,它就会变得不明确。就像那个GameCollection.h include文件一样。using语句在.h文件中非常有害,要么不使用它们,要么像您应该的那样将该声明放在名称空间中,并将using指令放在该名称空间中。在BGStatsInterface中自动生成的代码中有一个很好的例子。h@HansPassant啊!!非常感谢。这很有效。快速相关问题,我应该为所有类使用名称空间吗?是的,全局名称空间是C声明的家。感谢您的帮助!:如果你把它添加为回复,我会将它标记为解决方案,我不认为我可以将评论标记为解决方案。只需用你所学的内容自己完成Q+a。
#include "GameCollection.h"
GameCollection::GameCollection(){}
#pragma once
using namespace System;

ref class GameCollection
{
public:
    GameCollection();
};
Severity    Code    Description Project File    Line    Suppression State
Error (active)  E1986   an ordinary pointer to a C++/CLI ref class or interface class is not allowed    BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\servprov.h   91  
Error (active)  E0266   "IServiceProvider" is ambiguous BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\servprov.h   115 
Error (active)  E0266   "IServiceProvider" is ambiguous BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\servprov.h   239 
Error (active)  E0266   "IServiceProvider" is ambiguous BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\servprov.h   249 
Error (active)  E0266   "IServiceProvider" is ambiguous BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\urlmon.h 6867    
Error (active)  E0266   "IServiceProvider" is ambiguous BattlegroundStats   c:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\um\urlmon.h 6869        
Error   C3699   '*': cannot use this indirection on type 'IServiceProvider' BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\servprov.h   91  
Error   C2371   'IServiceProvider': redefinition; different basic types BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\servprov.h   98  
Error   C2872   'IServiceProvider': ambiguous symbol    BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\servprov.h   115 
Error   C2872   'IServiceProvider': ambiguous symbol    BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\servprov.h   239 
Error   C2872   'IServiceProvider': ambiguous symbol    BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\servprov.h   249 
Error   C2872   'IServiceProvider': ambiguous symbol    BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\urlmon.h 6867    
Error   C2872   'IServiceProvider': ambiguous symbol    BattlegroundStats   c:\program files (x86)\windows kits\10\include\10.0.16299.0\um\urlmon.h 6869    
using namespace System;
#include "stdafx.h"

using namespace System;
using namespace System;

#include "stdafx.h"