dotnet compact framework:
What "unsuspected error" are you getting specifically? My guess is you're
freeing an already-freed buffer.
--
Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com [quoted text, click to view] "Mobileboy36" <Mobileboy36@gmail.com> wrote in message
news:479eddbc$0$2994$ba620e4c@news.skynet.be...
> Hello group,
>
> My function BasePing doesn't work any more on mobile 2005.
> I get an unsuspected error on the line calling "LOCALFREE". On pocket pc
> 2003 i still have "normal" behavior.
> What am I doing wrong? How can I change my baseping function to get it
> working on a WM2005 device?
>
> best regards,
> Mobile boy
>
>
> <System.Runtime.InteropServices.DllImport("coredll")> _
> Private Shared Function LocalAlloc(ByVal Flags As Integer, ByVal
> size As Integer) As System.IntPtr
> End Function
>
> ' extern public static IntPtr LocalFree(IntPtr pMem);
> <System.Runtime.InteropServices.DllImport("coredll")> _
> Private Shared Function LocalFree(ByVal pMem As System.IntPtr) As
> System.IntPtr
> End Function
>
> <System.Runtime.InteropServices.DllImport("iphlpapi")> _
> Private Shared Function IcmpSendEcho( _
> ByVal IcmpHandle As System.IntPtr, _
> ByVal DestinationAddress As Integer, _
> ByVal RequestData As Byte(), _
> ByVal RequestSize As Short, _
> ByVal RequestOptions As System.IntPtr, _
> ByVal ReplyBuffer As Byte(), _
> ByVal ReplySize As Integer, _
> ByVal Timeout As Integer) As Integer
> ' returntype zou UInt32 moeten zijn, maar ja geen operators
> ondersteunt in Vb.net
> End Function
>
>
> Private Function BasePing(ByVal IpAddress As System.Net.IPAddress, ByVal
> TimeOut As Integer, ByVal SendBufferSizeInBytes As Integer) As Integer
> ' returnwaarden:
> '
> ' -1: Failed to ping, reason other then Request Timed out
> ' 0: Request Timed out
> ' > 0: Request Time
>
> Dim Result As Integer = 0
> 'Dim RequestData As Byte() =
> System.Text.Encoding.ASCII.GetBytes(New String("\0", 64))
> Dim RequestData As Byte() =
> System.Text.Encoding.ASCII.GetBytes(New String(Chr(0), 64))
> Dim Reply As ICMP_ECHO_REPLY
> Dim pData As System.IntPtr
> Dim h As System.IntPtr
> Dim intIpaddr As Integer
> Dim ret As Integer
> Dim dwErr As Integer = 0
>
> 'RequestData = System.Text.Encoding.ASCII.GetBytes(New
> String("\0", 64))
> RequestData = System.Text.Encoding.ASCII.GetBytes(New
> String(Chr(0), 64))
>
>
> 'Allocate ICMP_ECHO_REPLY structure
> Reply = New ICMP_ECHO_REPLY(255)
> Reply.DataSize = 255
> pData = LocalAlloc(LMEM_ZEROINIT, Reply.DataSize)
> Reply.Data = pData
> h = IcmpCreateFile()
> intIpaddr = MyIpConvertor(IpAddress)
> ret = IcmpSendEcho(h, intIpaddr, RequestData,
> System.Convert.ToInt16(RequestData.Length), IntPtr.Zero, Reply._Data,
> Reply._Data.Length, TimeOut)
>
> If (ret = 0) Then
> dwErr = GetLastError()
> If (dwErr <> 11010) Then 'If error is other than timeout -
> display a message
> Result = -1
> '"Failed to ping. Error code: " + dwErr.ToString())
> End If
> Else
> If (dwErr <> 11010) Then ' Then
> 'String.Format("RTT: {0}, Data Size: {1} TTL: {2}",
> Reply.RoundTripTime, Reply.DataSize, Reply.Ttl
> Result = Reply.RoundTripTime
> Else
> 'Request timed out
> Result = 0
> End If
> End If
> IcmpCloseHandle(h)
> LocalFree(Reply.Data)
>
> Return Result
> End Function
>