Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / February 2008

Tip: Looking for answers? Try searching our database.

Localfree on WM2005

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mobileboy36 - 29 Jan 2008 08:06 GMT
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
<ctacke/> - 29 Jan 2008 13:54 GMT
What "unsuspected error" are you getting specifically?  My guess is you're
freeing an already-freed buffer.

Signature

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com

> Hello group,
>
[quoted text clipped - 90 lines]
>            Return Result
>        End Function
Mobileboy36 - 22 Feb 2008 10:45 GMT
Thanks for your post Chris!!

I don't have more details, I get "unsuspected error", no more details are
displayed.
You guess I'm freeing an already freed buffer. Why does it work perfectly
for years on pocket pc 2003 than?
Shall I drop the free or is that going to create memory leaks?

best regards,
MobileBoy

"Mobileboy36" <Mobileboy36@gmail.com> schreef in bericht news:...
> Hello group,
>
[quoted text clipped - 90 lines]
>            Return Result
>        End Function

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.