kill process & Overflow Exception (VB net)

F

fabio.trivisonno

cf 1.1

I'm facing with killing a process by its name.
I converted some code found on the net from c# to vb and it works very
well except for some pid values. It gives me Overflow exception

'----
Private m_ihandle As IntPtr
Public th32ProcessID As System.UInt32

Public ReadOnly Property PID() As System.UInt64
Get
Return Convert.ToUInt64(th32ProcessID)
End Get
End Property

'...

m_ihandle = New IntPtr(Convert.ToInt64(peCurrent.PID)) ' <--
System.OverflowException - OverflowException
'----

It's funny because

Convert.ToInt32(peCurrent.PID)

gives me a "System.OverflowException - OverflowException"

so I changed it with

Convert.ToInt64(peCurrent.PID)

it retrieve 2799898626 - Long

The matter seems to be with Intptr constructor but, according to MSDN,
It must accept long argument. Has anyone an idea about it?

Thanks
Fabio
 
C

Chris Tacke, eMVP

That's not toally unexpected to me. Look at the docs for IntPtr:

The IntPtr type is designed to be an integer whose size is
platform-specific. That is, an instance of this type is expected to be
32-bits on 32-bit hardware and operating systems, and 64-bits on 64-bit
hardware and operating systems.

You're under a 32-bit system, so you shouldn't be using the 64-bit ctor.

I would think the 32-bit would work, though your example (0xA6E31002) has
the MSB set, so it would end up a negative number in the ugly world of
signed numbers (I still blame VB for forcing us to not use unsigned
numbers).

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate
 
F

fabio

Thank you for your sudden answer.
I supposed something as you described but I prayed it wasn't so
Anyway, I would like to ask you just a question: what do you mean with
"your example (0xA6E31002) has the MSB set" ? What is MSB?

Thanks
Fabio
 
D

droll

i think he means "most significant byte" as opposed to "least significant
byte" :)

0xA6E3, MSB = 0xA6, LSB = 0xE3 (assuming big-endian).
 
C

Chris Tacke, eMVP

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top