The error message that I've been getting for the past few months when trying to access functions of a specific third-party .dll using vb.net is this: "An unhandled exception of type 'System.AccessViolationException' occurred in test.exe Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I've been researching this error message, and I have come to know that it is likely due to either attempting to access memory that isn't available or due to "enhanced" security features.
I am trying to access a third party .dll. The functions in that .dll all deal in one way or another with Handle types (either returning them or accepting them as parameters). I understand that handle's can be essentially pointers to pointers (pointing to an entry in a memory table, which is itself a pointer), and I also understand that handle's don't, strictly speaking, exist in the .NET framework, but I do understand that through some combination of IntPtr's and possibly the Marshal class, they can be dealt with.
I don't believe vb.net's lack of a Handle type is the problem, because the dll function that I am calling, which on success returns a handle, returns a number <= 0 if the ip address it is searching for is not found, and the ip I specified doesn't exist. Also, the error really only occurs when executing the code from within the the Visual Studio environment. I compiled the executable and ran it 77 times(literally), and I only got the error on the 77th try.
I'm trying to find out all I can about this error. I would like to completely eliminate it. Could the error come as a result of something happening within the dll itself? The function asks for an ip address, and the ip address I have specified doesn't currently exist on the network, but as far as I know, the function handles that by returning a number less than or equal to zero. I am very confused as to what the problem could be. I have successfully interfaced with .dll's before. I've read about the hotfix for .NET 2.0 regarding this error message, but I'm a little skeptical. I've tried everything else I can think of, though, so I may give that a shot.
I'm 100% certain that:
-I am calling the correct function within the .dll
-I am using a signature that matches the signature of the function
-The error has nothing to do with User Account Control.
The code is very simple to try to isolate the issue:
I've been researching this error message, and I have come to know that it is likely due to either attempting to access memory that isn't available or due to "enhanced" security features.
I am trying to access a third party .dll. The functions in that .dll all deal in one way or another with Handle types (either returning them or accepting them as parameters). I understand that handle's can be essentially pointers to pointers (pointing to an entry in a memory table, which is itself a pointer), and I also understand that handle's don't, strictly speaking, exist in the .NET framework, but I do understand that through some combination of IntPtr's and possibly the Marshal class, they can be dealt with.
I don't believe vb.net's lack of a Handle type is the problem, because the dll function that I am calling, which on success returns a handle, returns a number <= 0 if the ip address it is searching for is not found, and the ip I specified doesn't exist. Also, the error really only occurs when executing the code from within the the Visual Studio environment. I compiled the executable and ran it 77 times(literally), and I only got the error on the 77th try.
I'm trying to find out all I can about this error. I would like to completely eliminate it. Could the error come as a result of something happening within the dll itself? The function asks for an ip address, and the ip address I have specified doesn't currently exist on the network, but as far as I know, the function handles that by returning a number less than or equal to zero. I am very confused as to what the problem could be. I have successfully interfaced with .dll's before. I've read about the hotfix for .NET 2.0 regarding this error message, but I'm a little skeptical. I've tried everything else I can think of, though, so I may give that a shot.
I'm 100% certain that:
-I am calling the correct function within the .dll
-I am using a signature that matches the signature of the function
-The error has nothing to do with User Account Control.
The code is very simple to try to isolate the issue:
VB.NET:
Imports System.Runtime.InteropServices
Module test
<DllImport("3rdparty.dll", EntryPoint:="#12")> _
Function OpenSession(ByVal ip As String, ByVal port As Integer, ByVal username As String, ByVal password As String) As Integer
End Function
Sub Main()
Try
Console.WriteLine(OpenSession("127.0.0.1", 19800, "player", "player"))
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadLine()
End Sub
End Module