C# wininetDll

0

Witam,
mam problem z wininet. wywaka "wywala: the "wininetDll" does not exist in the current conext"

**Załączone nagłówki:**
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
 
**Zmienne**
#region Zmienne
        [System.Runtime.InteropServices.DllImport("wininet.dll")]
        private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);
 
        static bool internet_connection()
        {
            int desc;
            return InternetGetConnectedState(out desc, 0);
        }
        #endregion Zmienne
**I button sprawdzający połączenie z internetem przed uruchomieniem kolejnego okna:**
 private void wininetDll_btn_Click(object sender, EventArgs e)
        {
            wininetdll_cb.Checked = internet_connection();   **wywala: the "wininetDll" does not exist in the current conext **
            if (wininetDll_cb.Checked)
            {
                Kurs kurs = new Kurs();
                kurs.Show();
 
            }
            else
            {
                ConnectionError error2 = new ConnectionError();
                error2.Show();
 
            }
        }
0

raz piszesz z dużej a raz z małej wininetDll

0

Nic nie zmieniło. Może wrzucę cały kod

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;

namespace Projekt1
{
    public partial class Form1 : Form
    {
        #region Zmienne

        [System.Runtime.InteropServices.DllImport("wininet.Dll")]
        private extern static bool InternetGetConnectedState(out int Description, int ReservedValue);

        static bool internet_connection()
        {
            int desc;
            return InternetGetConnectedState(out desc, 0);
        }

        #endregion Zmienne


        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            Konwerter konwerter = new Konwerter();
            konwerter.Show();

        }



        private void wininetDll_btn_Click(object sender, EventArgs e)
        {
            wininetDll_cb.Checked = internet_connection();
            if (wininetDll_cb.Checked)
            {
                Kurs kurs = new Kurs();
                kurs.Show();

            }
            else
            {
                ConnectionError error2 = new ConnectionError();
                error2.Show();

            }
        }
    }
}
0

Tą dll ke masz w folderze gdzie uruchamiasz apkę? W sensie w katalogu Debug lub Release, jak jest to błąd ten może wynikać z tego że ta dll jest dla innej wersji np. x64 ,a Ty piszesz apkę dla x86. W properties projektu możesz sobie to ustawić. I jak to importujesz to .dll z małej, w sensie w tym stringu.

0

dobra poszło. dla innych: wystarczyło zmienić

wininetDll_cb.Checked = internet_connection();
if (wininetDll_cb.Checked)

na

var wininetDll_cb = internet_connection();
if (wininetDll_cb)
0

Przede wszystkim pytanie co to jest wininetDll_cb? Pierwotnie to miał być checkbox, ale potem zmieniłeś na zmienną lokalną, której nawet nie potrzebujesz. Równie dobrze możesz napisać:

if (internet_connection())
{
   ....
}

Poza tym zapisujesz nazwę metody w Snake Case, a ogólnie przyjętą konwencją dla C# jest Pascal Case.

1 użytkowników online, w tym zalogowanych: 0, gości: 1