Die Sache mit dem geschützten Speicher…

Das Problem nennt sich AccessViolation und das liebe Vista oder besser gesagt Windows will einfach darin nicht lesen (auch unter administrator level) Das ist richtig beschissen doof -.-‚

Hier mal der Code zum der Probleme macht (VB 2008 / ping), achja der Code wurde von VB6 zu VB.NET konvertiert durch Visual Studio  2008.

[Spoiler]

  1.  
  2. Public Class net_ping
  3.  
  4.     Private Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal Hostname As String) As Integer
  5.     'UPGRADE_WARNING: Für die Struktur WSAdata müssen Marshalling-Attribute möglicherweise als ein Argument in dieser Declare-Anweisung weitergegeben werden. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
  6.     Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVersionRequired As Integer, ByRef lpWSAdata As WSAdata) As Integer
  7.     Private Declare Function WSACleanup Lib "wsock32.dll" () As Integer
  8.     'UPGRADE_ISSUE: Das Deklarieren eines Parameters als ''As Any'' wird nicht unterstützt. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  9.     'UPGRADE_ISSUE: Das Deklarieren eines Parameters als ''As Any'' wird nicht unterstützt. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="FAE78A8D-8978-4FD4-8208-5B7324A8F795"'
  10.     Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef hpvDest As Object, ByRef hpvSource As Object, ByVal cbCopy As Integer)
  11.     Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Integer
  12.     Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE As Integer) As Boolean
  13.     'UPGRADE_WARNING: Für die Struktur IP_ECHO_REPLY müssen Marshalling-Attribute möglicherweise als ein Argument in dieser Declare-Anweisung weitergegeben werden. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
  14.     'UPGRADE_WARNING: Für die Struktur IP_OPTION_INFORMATION müssen Marshalling-Attribute möglicherweise als ein Argument in dieser Declare-Anweisung weitergegeben werden. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="C429C3A5-5D47-4CD9-8F51-74A1616405DC"'
  15.     Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As Integer, ByVal DestAddress As Integer, ByVal RequestData As String, ByVal RequestSize As Short, ByRef RequestOptns As IP_OPTION_INFORMATION, ByRef ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Integer, ByVal TimeOut As Integer) As Boolean
  16.     Private Structure WSAdata
  17.         Dim wVersion As Short
  18.         Dim wHighVersion As Short
  19.         <vbfixedarray (255)> Dim szDescription() As Byte
  20.         </vbfixedarray><vbfixedarray (128)> Dim szSystemStatus() As Byte
  21.         Dim iMaxSockets As Short
  22.         Dim iMaxUdpDg As Short
  23.         Dim lpVendorInfo As Integer
  24.  
  25.         'UPGRADE_TODO: Zum Initialisieren der Instanzen dieser Struktur muss "Initialize" aufgerufen werden. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  26.         Public Sub Initialize()
  27.             ReDim szDescription(255)
  28.             ReDim szSystemStatus(128)
  29.         End Sub
  30.     End Structure
  31.  
  32.     Private Structure Hostent
  33.         Dim h_name As Integer
  34.         Dim h_aliases As Integer
  35.         Dim h_addrtype As Short
  36.         Dim h_length As Short
  37.         Dim h_addr_list As Integer
  38.     End Structure
  39.  
  40.     Private Structure IP_OPTION_INFORMATION
  41.         Dim TTL As Byte
  42.         Dim Tos As Byte
  43.         Dim Flags As Byte
  44.         Dim OptionsSize As Integer
  45.         'UPGRADE_WARNING: Die Größe der Zeichenfolge mit fester Länge darf die Puffergröße nicht überschreiten. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"'
  46.         <vbfixedstring (128), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=128)> Public OptionsData() As Char
  47.     End Structure
  48.  
  49.     Private Structure IP_ECHO_REPLY
  50.         <vbfixedarray (3)> Dim Address() As Byte
  51.         Dim Status As Integer
  52.         Dim RoundTripTime As Integer
  53.         Dim DataSize As Short
  54.         Dim Reserved As Short
  55.         Dim data As Integer
  56.         Dim Options As IP_OPTION_INFORMATION
  57.  
  58.         'UPGRADE_TODO: Zum Initialisieren der Instanzen dieser Struktur muss "Initialize" aufgerufen werden. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="B4BFF9E0-8631-45CF-910E-62AB3970F27B"'
  59.         Public Sub Initialize()
  60.             ReDim Address(3)
  61.         End Sub
  62.     End Structure
  63.  
  64.     Private Const SOCKET_ERROR As Short = 0
  65.  
  66.     Public Function Ping(ByVal Server As String) As Integer
  67.         'UPGRADE_WARNING: Arrays in Struktur lpWSAdata müssen möglicherweise initialisiert werden, bevor sie verwendet werden können. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
  68.         Dim hFile As Integer
  69.         Dim lpWSAdata As WSAdata
  70.         Dim hHostent As Hostent
  71.         Dim AddrList As Integer
  72.         Dim Address As Integer
  73.         Dim rIP As String
  74.         Dim OptInfo As IP_OPTION_INFORMATION
  75.         'UPGRADE_WARNING: Arrays in Struktur EchoReply müssen möglicherweise initialisiert werden, bevor sie verwendet werden können. Klicken Sie hier für weitere Informationen: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="814DF224-76BD-4BB4-BFFB-EA359CB9FC48"'
  76.         Dim EchoReply As IP_ECHO_REPLY
  77.         Dim Hostname As String
  78.  
  79.         Ping = 0 'Rückgabe anfangs auf null setzen
  80.         'If Left(Server, 7) = "http://" Then Server = Mid(Server, 8) 'http:// entfernen
  81.  
  82.         Call WSAStartup(&H101, lpWSAdata)
  83.  
  84.         If GetHostByName(Server & New String(Chr(0), 64 - Len(Server))) <> SOCKET_ERROR Then
  85.             CopyMemory(hHostent.h_name, GetHostByName(Server & New String(Chr(0), 64 - Len(Server))), Len(hHostent))
  86.             CopyMemory(AddrList, hHostent.h_addr_list, 4)
  87.             CopyMemory(Address, AddrList, 4)
  88.         End If
  89.  
  90.         hFile = IcmpCreateFile()
  91.         If hFile = 0 Then Exit Function 'Bei Fehler abbrechen
  92.  
  93.         OptInfo.TTL = 255
  94.  
  95.         'Ping senden
  96.         If IcmpSendEcho(hFile, Address, New String("A", 32), 32, OptInfo, EchoReply, Len(EchoReply) + 8, 2000) Then
  97.             rIP = CStr(EchoReply.Address(0)) & "." & CStr(EchoReply.Address(1)) & "." & CStr(EchoReply.Address(2)) & "." & CStr(EchoReply.Address(3))
  98.         Else
  99.             'Fehler aufgetreten
  100.             Exit Function
  101.         End If
  102.  
  103.         If EchoReply.Status = 0 Then
  104.             Ping = EchoReply.RoundTripTime
  105.         Else
  106.             'Keine Antwort bekommen
  107.         End If
  108.     End Function
  109.  
  110.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  111.         Dim reply As Integer = Ping("google.com")
  112.  
  113.         If reply > 0 Then
  114.             MessageBox.Show("Server antwortet:" & reply & " ms", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information)
  115.         Else
  116.             MessageBox.Show("Fehler beim Pingen", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
  117.         End If
  118.  
  119.     End Sub
  120. End Class
  121.  
  122.  
  123. </vbfixedarray></vbfixedstring></vbfixedarray>

[/spoiler]

Der Fehler tritt in Zeile 82 auf also bei

Call WSAStartup(&H101, lpWSAdata)

auf… so jetzt müsste ich nur noch wissen warum^^

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

*

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.