2020年12月23日星期三

How to solve "IServiceProvider" is ambiguous when using "wininet" and "windows.h"?

I'm trying to check if the internet connection exists or not by using the InternetCheckConnection function of wininet.

Here's my CheckerClass: which handles the process of checking.

#pragma once  #include <Windows.h>  #include <wininet.h>  #pragma comment(lib,"wininet.lib")  #include <String>    public ref class CheckerClass  {  public:      static std::string hasInternet() {          bool bConnect = InternetCheckConnection(L"https://www.google.com", FLAG_ICC_FORCE_CONNECTION, 0);          if (bConnect){              return "Has Internet!";          }else{              return "No Internet!";          }      }  };  

But I'm getting the following error and I can't solve it.

Error (active)  E1986   an ordinary pointer to a C++/CLI ref class or interface class is not allowed  Error (active)  E0266   "IServiceProvider" is ambiguous  Error   C3699   '*': cannot use this indirection on type 'IServiceProvider'   

After searching, I found this can because of using using namespace System, but I don't have that in the above class.

However, I have the following from Main class where I'm using the above class.

#pragma once  #include<string>  #include "CheckerClass.h"  namespace CppCLRWinformsProjekt {        using namespace System;      using namespace System::ComponentModel;      using namespace System::Collections;      using namespace System::Windows::Forms;      using namespace System::Data;      using namespace System::Drawing;      using std::string;        public ref class Form1 : public System::Windows::Forms::Form      {      public:            CheckerClass checkerClass;                    Form1(void)          {              InitializeComponent();              string result = checkerClass.hasInternet();              this->label_output->Text = gcnew System::String(result.c_str());          }        .....  

Can anybody explain what's going on and how can I solve the above issue?

https://stackoverflow.com/questions/65426854/how-to-solve-iserviceprovider-is-ambiguous-when-using-wininet-and-windows-h December 23, 2020 at 11:34PM

没有评论:

发表评论