Hello,

I perform a ping using the IcmpSendEcho Function from iphlpapi:
<DllImport("iphlpapi")> _

Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr, ByVal
DestinationAddress As System.UInt32, ByVal RequestData() As Byte, ByVal
RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal ReplyBuffer()
As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As System.UInt32


This Function requires a Destination Adress as an unsigned Int32. I get it
from the IPAddress.Address Object.

Public Structure PingOptions
Dim IPAdress As IPAddress
Dim TimeOUT As Integer
End Structure
dim opt as PingOptions

opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger then
A.B.C.127, have a negative adress value !!!

ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse exception
here

Dim ret As System.UInt32

'but i need an unsigned int here in the second parameter
ret = IcmpSendEcho(h, opt.ipaddr, RequestData, CInt(RequestData.Length),
IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)

The Problem is that for IPAdresses, where the last Byte is bigger then 127.
the generated Long Value for Adress is negative and the Parse Method to the
uint32 couses an exception.

Or should i declare the DestinationAdress as Long in the IcmpSendEcho and
put in IPAdress.Address value directly.
My assumption is that the Address value is created in the correct bitformat
but becouse the CF is declaring it as a long it is interpreted negative.

Or how else to get the correct Long Value from IPAdress.Address ?

THX in advance


--
-> Milosz Weckowski
www.playseven.com

mailto:mw@playseven.com
ICQ Number: 84867613

Get the enhanced Progressbar and a fine Colorpicker for the Compact Framwork
for free:
http://www.playseven.com/11620/p7_Controls.html

Re: IPAddress.Address is negative by Chris

Chris
Fri Feb 20 05:32:40 CST 2004

With unsigned numbers there is no such thing as negative. It simply means
that your LSB is on. If you use unchecked you can stuff a "negative" signed
number into an unsigned.

-Chris

"Milosz - [playseven.com]" <mw@playseven.com> wrote in message
news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> Hello,
>
> I perform a ping using the IcmpSendEcho Function from iphlpapi:
> <DllImport("iphlpapi")> _
>
> Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr, ByVal
> DestinationAddress As System.UInt32, ByVal RequestData() As Byte, ByVal
> RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
ReplyBuffer()
> As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
System.UInt32
>
>
> This Function requires a Destination Adress as an unsigned Int32. I get it
> from the IPAddress.Address Object.
>
> Public Structure PingOptions
> Dim IPAdress As IPAddress
> Dim TimeOUT As Integer
> End Structure
> dim opt as PingOptions
>
> opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger then
> A.B.C.127, have a negative adress value !!!
>
> ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse exception
> here
>
> Dim ret As System.UInt32
>
> 'but i need an unsigned int here in the second parameter
> ret = IcmpSendEcho(h, opt.ipaddr, RequestData, CInt(RequestData.Length),
> IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
>
> The Problem is that for IPAdresses, where the last Byte is bigger then
127.
> the generated Long Value for Adress is negative and the Parse Method to
the
> uint32 couses an exception.
>
> Or should i declare the DestinationAdress as Long in the IcmpSendEcho and
> put in IPAdress.Address value directly.
> My assumption is that the Address value is created in the correct
bitformat
> but becouse the CF is declaring it as a long it is interpreted negative.
>
> Or how else to get the correct Long Value from IPAdress.Address ?
>
> THX in advance
>
>
> --
> -> Milosz Weckowski
> www.playseven.com
>
> mailto:mw@playseven.com
> ICQ Number: 84867613
>
> Get the enhanced Progressbar and a fine Colorpicker for the Compact
Framwork
> for free:
> http://www.playseven.com/11620/p7_Controls.html
>
>



Re: IPAddress.Address is negative by Milosz

Milosz
Fri Feb 20 07:19:23 CST 2004

I'm sorry. I do not understand.
IPAdress.Adress is signed becouse it's a simple Int32, and IcmpSendEcho
wants to have an unsigned int.

What is an LSB and how to uncheck it?

Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
Function ?

regards

Milosz





"Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im Newsbeitrag
news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> With unsigned numbers there is no such thing as negative. It simply means
> that your LSB is on. If you use unchecked you can stuff a "negative"
signed
> number into an unsigned.
>
> -Chris
>
> "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > Hello,
> >
> > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > <DllImport("iphlpapi")> _
> >
> > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr, ByVal
> > DestinationAddress As System.UInt32, ByVal RequestData() As Byte, ByVal
> > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> ReplyBuffer()
> > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> System.UInt32
> >
> >
> > This Function requires a Destination Adress as an unsigned Int32. I get
it
> > from the IPAddress.Address Object.
> >
> > Public Structure PingOptions
> > Dim IPAdress As IPAddress
> > Dim TimeOUT As Integer
> > End Structure
> > dim opt as PingOptions
> >
> > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger then
> > A.B.C.127, have a negative adress value !!!
> >
> > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse exception
> > here
> >
> > Dim ret As System.UInt32
> >
> > 'but i need an unsigned int here in the second parameter
> > ret = IcmpSendEcho(h, opt.ipaddr, RequestData, CInt(RequestData.Length),
> > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> >
> > The Problem is that for IPAdresses, where the last Byte is bigger then
> 127.
> > the generated Long Value for Adress is negative and the Parse Method to
> the
> > uint32 couses an exception.
> >
> > Or should i declare the DestinationAdress as Long in the IcmpSendEcho
and
> > put in IPAdress.Address value directly.
> > My assumption is that the Address value is created in the correct
> bitformat
> > but becouse the CF is declaring it as a long it is interpreted negative.
> >
> > Or how else to get the correct Long Value from IPAdress.Address ?
> >
> > THX in advance
> >
> >
> > --
> > -> Milosz Weckowski
> > www.playseven.com
> >
> > mailto:mw@playseven.com
> > ICQ Number: 84867613
> >
> > Get the enhanced Progressbar and a fine Colorpicker for the Compact
> Framwork
> > for free:
> > http://www.playseven.com/11620/p7_Controls.html
> >
> >
>
>



LSB by Milosz

Milosz
Fri Feb 20 07:48:38 CST 2004

Do you mean LSB opp. MSB ?
If yes, i still don't know what to do ..

regards
Milosz


"Milosz - [playseven.com]" <mw@playseven.com> schrieb im Newsbeitrag
news:%23HpniQ79DHA.1312@TK2MSFTNGP09.phx.gbl...
> I'm sorry. I do not understand.
> IPAdress.Adress is signed becouse it's a simple Int32, and IcmpSendEcho
> wants to have an unsigned int.
>
> What is an LSB and how to uncheck it?
>
> Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
> Function ?
>
> regards
>
> Milosz
>
>
>
>
>
> "Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im Newsbeitrag
> news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> > With unsigned numbers there is no such thing as negative. It simply
means
> > that your LSB is on. If you use unchecked you can stuff a "negative"
> signed
> > number into an unsigned.
> >
> > -Chris
> >
> > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > > Hello,
> > >
> > > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > > <DllImport("iphlpapi")> _
> > >
> > > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr, ByVal
> > > DestinationAddress As System.UInt32, ByVal RequestData() As Byte,
ByVal
> > > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> > ReplyBuffer()
> > > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> > System.UInt32
> > >
> > >
> > > This Function requires a Destination Adress as an unsigned Int32. I
get
> it
> > > from the IPAddress.Address Object.
> > >
> > > Public Structure PingOptions
> > > Dim IPAdress As IPAddress
> > > Dim TimeOUT As Integer
> > > End Structure
> > > dim opt as PingOptions
> > >
> > > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger then
> > > A.B.C.127, have a negative adress value !!!
> > >
> > > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse
exception
> > > here
> > >
> > > Dim ret As System.UInt32
> > >
> > > 'but i need an unsigned int here in the second parameter
> > > ret = IcmpSendEcho(h, opt.ipaddr, RequestData,
CInt(RequestData.Length),
> > > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> > >
> > > The Problem is that for IPAdresses, where the last Byte is bigger then
> > 127.
> > > the generated Long Value for Adress is negative and the Parse Method
to
> > the
> > > uint32 couses an exception.
> > >
> > > Or should i declare the DestinationAdress as Long in the IcmpSendEcho
> and
> > > put in IPAdress.Address value directly.
> > > My assumption is that the Address value is created in the correct
> > bitformat
> > > but becouse the CF is declaring it as a long it is interpreted
negative.
> > >
> > > Or how else to get the correct Long Value from IPAdress.Address ?
> > >
> > > THX in advance
> > >
> > >
> > > --
> > > -> Milosz Weckowski
> > > www.playseven.com
> > >
> > > mailto:mw@playseven.com
> > > ICQ Number: 84867613
> > >
> > > Get the enhanced Progressbar and a fine Colorpicker for the Compact
> > Framwork
> > > for free:
> > > http://www.playseven.com/11620/p7_Controls.html
> > >
> > >
> >
> >
>
>



Re: IPAddress.Address is negative by Kevin

Kevin
Fri Feb 20 08:20:55 CST 2004

Try looking at this --
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfcheckeduncheckedstatements.asp




"Milosz - [playseven.com]" <mw@playseven.com> wrote in message
news:%23HpniQ79DHA.1312@TK2MSFTNGP09.phx.gbl...
> I'm sorry. I do not understand.
> IPAdress.Adress is signed becouse it's a simple Int32, and IcmpSendEcho
> wants to have an unsigned int.
>
> What is an LSB and how to uncheck it?
>
> Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
> Function ?
>
> regards
>
> Milosz
>
>
>
>
>
> "Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im Newsbeitrag
> news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> > With unsigned numbers there is no such thing as negative. It simply
means
> > that your LSB is on. If you use unchecked you can stuff a "negative"
> signed
> > number into an unsigned.
> >
> > -Chris
> >
> > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > > Hello,
> > >
> > > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > > <DllImport("iphlpapi")> _
> > >
> > > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr, ByVal
> > > DestinationAddress As System.UInt32, ByVal RequestData() As Byte,
ByVal
> > > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> > ReplyBuffer()
> > > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> > System.UInt32
> > >
> > >
> > > This Function requires a Destination Adress as an unsigned Int32. I
get
> it
> > > from the IPAddress.Address Object.
> > >
> > > Public Structure PingOptions
> > > Dim IPAdress As IPAddress
> > > Dim TimeOUT As Integer
> > > End Structure
> > > dim opt as PingOptions
> > >
> > > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger then
> > > A.B.C.127, have a negative adress value !!!
> > >
> > > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse
exception
> > > here
> > >
> > > Dim ret As System.UInt32
> > >
> > > 'but i need an unsigned int here in the second parameter
> > > ret = IcmpSendEcho(h, opt.ipaddr, RequestData,
CInt(RequestData.Length),
> > > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> > >
> > > The Problem is that for IPAdresses, where the last Byte is bigger then
> > 127.
> > > the generated Long Value for Adress is negative and the Parse Method
to
> > the
> > > uint32 couses an exception.
> > >
> > > Or should i declare the DestinationAdress as Long in the IcmpSendEcho
> and
> > > put in IPAdress.Address value directly.
> > > My assumption is that the Address value is created in the correct
> > bitformat
> > > but becouse the CF is declaring it as a long it is interpreted
negative.
> > >
> > > Or how else to get the correct Long Value from IPAdress.Address ?
> > >
> > > THX in advance
> > >
> > >
> > > --
> > > -> Milosz Weckowski
> > > www.playseven.com
> > >
> > > mailto:mw@playseven.com
> > > ICQ Number: 84867613
> > >
> > > Get the enhanced Progressbar and a fine Colorpicker for the Compact
> > Framwork
> > > for free:
> > > http://www.playseven.com/11620/p7_Controls.html
> > >
> > >
> >
> >
>
>



Re: IPAddress.Address is negative by Milosz

Milosz
Fri Feb 20 10:08:01 CST 2004

Thats fine, but thats C#... and I'm using VB.net.
However even if using C# with unchecked Option, if i would pass the
truncated Adress Value to the function, would it ping the right host ?
I mean the IPAdress.Adress onbejct is possible to return an negative value.
It must be possible to translate it in an adequate unsigned int for the
P/Invoke function.

Or, how to simulate the checked behavior in VB:net use math.abs() or
something else ?

regards

Milosz



"Kevin Hutchison" <kjhutchison@hotmail.com> schrieb im Newsbeitrag
news:eLUZ$v79DHA.1392@tk2msftngp13.phx.gbl...
> Try looking at this --
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfcheckeduncheckedstatements.asp
>
>
>
>
> "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> news:%23HpniQ79DHA.1312@TK2MSFTNGP09.phx.gbl...
> > I'm sorry. I do not understand.
> > IPAdress.Adress is signed becouse it's a simple Int32, and IcmpSendEcho
> > wants to have an unsigned int.
> >
> > What is an LSB and how to uncheck it?
> >
> > Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
> > Function ?
> >
> > regards
> >
> > Milosz
> >
> >
> >
> >
> >
> > "Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im
Newsbeitrag
> > news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> > > With unsigned numbers there is no such thing as negative. It simply
> means
> > > that your LSB is on. If you use unchecked you can stuff a "negative"
> > signed
> > > number into an unsigned.
> > >
> > > -Chris
> > >
> > > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > > news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > > > Hello,
> > > >
> > > > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > > > <DllImport("iphlpapi")> _
> > > >
> > > > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr,
ByVal
> > > > DestinationAddress As System.UInt32, ByVal RequestData() As Byte,
> ByVal
> > > > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> > > ReplyBuffer()
> > > > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> > > System.UInt32
> > > >
> > > >
> > > > This Function requires a Destination Adress as an unsigned Int32. I
> get
> > it
> > > > from the IPAddress.Address Object.
> > > >
> > > > Public Structure PingOptions
> > > > Dim IPAdress As IPAddress
> > > > Dim TimeOUT As Integer
> > > > End Structure
> > > > dim opt as PingOptions
> > > >
> > > > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger
then
> > > > A.B.C.127, have a negative adress value !!!
> > > >
> > > > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse
> exception
> > > > here
> > > >
> > > > Dim ret As System.UInt32
> > > >
> > > > 'but i need an unsigned int here in the second parameter
> > > > ret = IcmpSendEcho(h, opt.ipaddr, RequestData,
> CInt(RequestData.Length),
> > > > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> > > >
> > > > The Problem is that for IPAdresses, where the last Byte is bigger
then
> > > 127.
> > > > the generated Long Value for Adress is negative and the Parse Method
> to
> > > the
> > > > uint32 couses an exception.
> > > >
> > > > Or should i declare the DestinationAdress as Long in the
IcmpSendEcho
> > and
> > > > put in IPAdress.Address value directly.
> > > > My assumption is that the Address value is created in the correct
> > > bitformat
> > > > but becouse the CF is declaring it as a long it is interpreted
> negative.
> > > >
> > > > Or how else to get the correct Long Value from IPAdress.Address ?
> > > >
> > > > THX in advance
> > > >
> > > >
> > > > --
> > > > -> Milosz Weckowski
> > > > www.playseven.com
> > > >
> > > > mailto:mw@playseven.com
> > > > ICQ Number: 84867613
> > > >
> > > > Get the enhanced Progressbar and a fine Colorpicker for the Compact
> > > Framwork
> > > > for free:
> > > > http://www.playseven.com/11620/p7_Controls.html
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: IPAddress.Address is negative by Paul

Paul
Fri Feb 20 11:24:35 CST 2004

The number is simply a 4-byte value representing the four IP address
components. That is, if your target IP address is 172.16.0.1, the 4-byte
value is going to be something like:

0xac100001

You'll note that, in this case, this number would appear to be negative
because the most-significant bit *is* set. In fact, this value would appear
to be -1408237567, if my math is right.

Sounds like your problem is the declaration of the P/Invoke or the inability
to convert from this signed integer value to an unsigned one. In C#, I'd do
this:

unsigned int ui = unchecked((unsigned int)-1408237567);

to perform this conversion and avoid an out-of-range error. Is there an
equivalent way to do this from VB.NET? If not, you may want to change your
P/Invoke declaration to accept a signed, rather than unsigned, integer.

Paul T.

"Milosz - [playseven.com]" <mw@playseven.com> wrote in message
news:%23F6yyu89DHA.4020@TK2MSFTNGP09.phx.gbl...
> Thats fine, but thats C#... and I'm using VB.net.
> However even if using C# with unchecked Option, if i would pass the
> truncated Adress Value to the function, would it ping the right host ?
> I mean the IPAdress.Adress onbejct is possible to return an negative
value.
> It must be possible to translate it in an adequate unsigned int for the
> P/Invoke function.
>
> Or, how to simulate the checked behavior in VB:net use math.abs() or
> something else ?
>
> regards
>
> Milosz
>
>
>
> "Kevin Hutchison" <kjhutchison@hotmail.com> schrieb im Newsbeitrag
> news:eLUZ$v79DHA.1392@tk2msftngp13.phx.gbl...
> > Try looking at this --
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfcheckeduncheckedstatements.asp
> >
> >
> >
> >
> > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > news:%23HpniQ79DHA.1312@TK2MSFTNGP09.phx.gbl...
> > > I'm sorry. I do not understand.
> > > IPAdress.Adress is signed becouse it's a simple Int32, and
IcmpSendEcho
> > > wants to have an unsigned int.
> > >
> > > What is an LSB and how to uncheck it?
> > >
> > > Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
> > > Function ?
> > >
> > > regards
> > >
> > > Milosz
> > >
> > >
> > >
> > >
> > >
> > > "Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im
> Newsbeitrag
> > > news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> > > > With unsigned numbers there is no such thing as negative. It simply
> > means
> > > > that your LSB is on. If you use unchecked you can stuff a
"negative"
> > > signed
> > > > number into an unsigned.
> > > >
> > > > -Chris
> > > >
> > > > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > > > news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > > > > Hello,
> > > > >
> > > > > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > > > > <DllImport("iphlpapi")> _
> > > > >
> > > > > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr,
> ByVal
> > > > > DestinationAddress As System.UInt32, ByVal RequestData() As Byte,
> > ByVal
> > > > > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> > > > ReplyBuffer()
> > > > > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> > > > System.UInt32
> > > > >
> > > > >
> > > > > This Function requires a Destination Adress as an unsigned Int32.
I
> > get
> > > it
> > > > > from the IPAddress.Address Object.
> > > > >
> > > > > Public Structure PingOptions
> > > > > Dim IPAdress As IPAddress
> > > > > Dim TimeOUT As Integer
> > > > > End Structure
> > > > > dim opt as PingOptions
> > > > >
> > > > > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses bigger
> then
> > > > > A.B.C.127, have a negative adress value !!!
> > > > >
> > > > > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse
> > exception
> > > > > here
> > > > >
> > > > > Dim ret As System.UInt32
> > > > >
> > > > > 'but i need an unsigned int here in the second parameter
> > > > > ret = IcmpSendEcho(h, opt.ipaddr, RequestData,
> > CInt(RequestData.Length),
> > > > > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> > > > >
> > > > > The Problem is that for IPAdresses, where the last Byte is bigger
> then
> > > > 127.
> > > > > the generated Long Value for Adress is negative and the Parse
Method
> > to
> > > > the
> > > > > uint32 couses an exception.
> > > > >
> > > > > Or should i declare the DestinationAdress as Long in the
> IcmpSendEcho
> > > and
> > > > > put in IPAdress.Address value directly.
> > > > > My assumption is that the Address value is created in the correct
> > > > bitformat
> > > > > but becouse the CF is declaring it as a long it is interpreted
> > negative.
> > > > >
> > > > > Or how else to get the correct Long Value from IPAdress.Address ?
> > > > >
> > > > > THX in advance
> > > > >
> > > > >
> > > > > --
> > > > > -> Milosz Weckowski
> > > > > www.playseven.com
> > > > >
> > > > > mailto:mw@playseven.com
> > > > > ICQ Number: 84867613
> > > > >
> > > > > Get the enhanced Progressbar and a fine Colorpicker for the
Compact
> > > > Framwork
> > > > > for free:
> > > > > http://www.playseven.com/11620/p7_Controls.html
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: IPAddress.Address is negative by Paul

Paul
Fri Feb 20 11:28:59 CST 2004

Something like this, for example:

Dim ui32 As UInt32 = System.Convert.ToUInt32(-1408237567)



Paul T.



"Paul G. Tobey [eMVP]" <ptobey_no_spam@instrument_no_spam.com> wrote in
message news:entfmZ99DHA.2316@TK2MSFTNGP11.phx.gbl...
> The number is simply a 4-byte value representing the four IP address
> components. That is, if your target IP address is 172.16.0.1, the 4-byte
> value is going to be something like:
>
> 0xac100001
>
> You'll note that, in this case, this number would appear to be negative
> because the most-significant bit *is* set. In fact, this value would
appear
> to be -1408237567, if my math is right.
>
> Sounds like your problem is the declaration of the P/Invoke or the
inability
> to convert from this signed integer value to an unsigned one. In C#, I'd
do
> this:
>
> unsigned int ui = unchecked((unsigned int)-1408237567);
>
> to perform this conversion and avoid an out-of-range error. Is there an
> equivalent way to do this from VB.NET? If not, you may want to change
your
> P/Invoke declaration to accept a signed, rather than unsigned, integer.
>
> Paul T.
>
> "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> news:%23F6yyu89DHA.4020@TK2MSFTNGP09.phx.gbl...
> > Thats fine, but thats C#... and I'm using VB.net.
> > However even if using C# with unchecked Option, if i would pass the
> > truncated Adress Value to the function, would it ping the right host ?
> > I mean the IPAdress.Adress onbejct is possible to return an negative
> value.
> > It must be possible to translate it in an adequate unsigned int for the
> > P/Invoke function.
> >
> > Or, how to simulate the checked behavior in VB:net use math.abs() or
> > something else ?
> >
> > regards
> >
> > Milosz
> >
> >
> >
> > "Kevin Hutchison" <kjhutchison@hotmail.com> schrieb im Newsbeitrag
> > news:eLUZ$v79DHA.1392@tk2msftngp13.phx.gbl...
> > > Try looking at this --
> > >
> >
>
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfcheckeduncheckedstatements.asp
> > >
> > >
> > >
> > >
> > > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > > news:%23HpniQ79DHA.1312@TK2MSFTNGP09.phx.gbl...
> > > > I'm sorry. I do not understand.
> > > > IPAdress.Adress is signed becouse it's a simple Int32, and
> IcmpSendEcho
> > > > wants to have an unsigned int.
> > > >
> > > > What is an LSB and how to uncheck it?
> > > >
> > > > Do you mean i have to pass the long value 'as it is' to IcmpSendEcho
> > > > Function ?
> > > >
> > > > regards
> > > >
> > > > Milosz
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > "Chris Tacke, eMVP" <ctacke[at]Open_NET_CF[dot]org> schrieb im
> > Newsbeitrag
> > > > news:eq4%23AV69DHA.2308@TK2MSFTNGP11.phx.gbl...
> > > > > With unsigned numbers there is no such thing as negative. It
simply
> > > means
> > > > > that your LSB is on. If you use unchecked you can stuff a
> "negative"
> > > > signed
> > > > > number into an unsigned.
> > > > >
> > > > > -Chris
> > > > >
> > > > > "Milosz - [playseven.com]" <mw@playseven.com> wrote in message
> > > > > news:u$uS6N69DHA.2804@TK2MSFTNGP09.phx.gbl...
> > > > > > Hello,
> > > > > >
> > > > > > I perform a ping using the IcmpSendEcho Function from iphlpapi:
> > > > > > <DllImport("iphlpapi")> _
> > > > > >
> > > > > > Private Shared Function IcmpSendEcho(ByVal IcmpHandle As IntPtr,
> > ByVal
> > > > > > DestinationAddress As System.UInt32, ByVal RequestData() As
Byte,
> > > ByVal
> > > > > > RequestSize As Integer, ByVal RequestOptions As IntPtr, ByVal
> > > > > ReplyBuffer()
> > > > > > As Byte, ByVal ReplySize As Int32, ByVal Timeout As Int32) As
> > > > > System.UInt32
> > > > > >
> > > > > >
> > > > > > This Function requires a Destination Adress as an unsigned
Int32.
> I
> > > get
> > > > it
> > > > > > from the IPAddress.Address Object.
> > > > > >
> > > > > > Public Structure PingOptions
> > > > > > Dim IPAdress As IPAddress
> > > > > > Dim TimeOUT As Integer
> > > > > > End Structure
> > > > > > dim opt as PingOptions
> > > > > >
> > > > > > opt.IPAdress = IPAddress.Parse("192.168.1.128") ' Adresses
bigger
> > then
> > > > > > A.B.C.127, have a negative adress value !!!
> > > > > >
> > > > > > ipaddr = System.UInt32.Parse(opt.IPAdress.Address) ' and couse
> > > exception
> > > > > > here
> > > > > >
> > > > > > Dim ret As System.UInt32
> > > > > >
> > > > > > 'but i need an unsigned int here in the second parameter
> > > > > > ret = IcmpSendEcho(h, opt.ipaddr, RequestData,
> > > CInt(RequestData.Length),
> > > > > > IntPtr.Zero, reply._Data, reply._Data.Length, opt.TimeOUT)
> > > > > >
> > > > > > The Problem is that for IPAdresses, where the last Byte is
bigger
> > then
> > > > > 127.
> > > > > > the generated Long Value for Adress is negative and the Parse
> Method
> > > to
> > > > > the
> > > > > > uint32 couses an exception.
> > > > > >
> > > > > > Or should i declare the DestinationAdress as Long in the
> > IcmpSendEcho
> > > > and
> > > > > > put in IPAdress.Address value directly.
> > > > > > My assumption is that the Address value is created in the
correct
> > > > > bitformat
> > > > > > but becouse the CF is declaring it as a long it is interpreted
> > > negative.
> > > > > >
> > > > > > Or how else to get the correct Long Value from IPAdress.Address
?
> > > > > >
> > > > > > THX in advance
> > > > > >
> > > > > >
> > > > > > --
> > > > > > -> Milosz Weckowski
> > > > > > www.playseven.com
> > > > > >
> > > > > > mailto:mw@playseven.com
> > > > > > ICQ Number: 84867613
> > > > > >
> > > > > > Get the enhanced Progressbar and a fine Colorpicker for the
> Compact
> > > > > Framwork
> > > > > > for free:
> > > > > > http://www.playseven.com/11620/p7_Controls.html
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Re: IPAddress.Address is negative by Mattias

Mattias
Fri Feb 20 13:50:09 CST 2004

Milosz,

>Or should i declare the DestinationAdress as Long in the IcmpSendEcho and
>put in IPAdress.Address value directly.

No, but declaring it as Integer should work, regardless if the callee
interprest the argument as signed or not.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Re: IPAddress.Address is negative by Milosz

Milosz
Fri Feb 20 14:43:49 CST 2004

yes, that worked !

THX a lot !


"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> schrieb im Newsbeitrag
news:uK%23OGr%239DHA.2404@TK2MSFTNGP12.phx.gbl...
> Milosz,
>
> >Or should i declare the DestinationAdress as Long in the IcmpSendEcho and
> >put in IPAdress.Address value directly.
>
> No, but declaring it as Integer should work, regardless if the callee
> interprest the argument as signed or not.
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.