VB.NET DLL导入可工作一定次数,然后显示错误信息

我的vb.net代码有问题...

我创建了一个C ++ .dll文件,当禁用WiFi时该文件返回0。这段代码可以完美地运行20个循环,然后给我一个错误的读数。几乎好像它每次都不会卸载dll文件,并且在20个进程生成后会阻止它。

Imports System.Media
Imports System.Runtime.InteropServices
Module Module1
    <DllImport("C:\Dll2.dll",CharSet:=CharSet.Unicode,CallingConvention:=CallingConvention.Cdecl)>
    Friend Function Helloworld(
         ByVal i As Int32) As Int32
    End Function


    Sub Main()

        While (1 = 1)
            Dim A
            A = Helloworld(5)
            Console.WriteLine(A)

            If A = 0 Then
                WiFi_Disabled()
            End If

            Threading.Thread.Sleep(1000)

        End While
    End Sub

    Public Function WiFi_Disabled()
        Dim speech
        speech = CreateObject("sapi.spvoice")
        speech.speak("Please Turn your Wifi Back on")
    End Function

End Module

感谢您的帮助:)

deipfqu850726 回答:VB.NET DLL导入可工作一定次数,然后显示错误信息

我发现我的.dll文件引起了错误。这是因为我没有关闭我的WiFi处理程序。生成20个实例后,发生了内存错误。我需要使用此功能关闭处理程序。 https://docs.microsoft.com/en-us/windows/win32/api/wlanapi/nf-wlanapi-wlanclosehandle

本文链接:https://www.f2er.com/3162692.html

大家都在问