Importants of IntPtr?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

??????????????????
What is the importance of IntPtr besides being, behind the scenes, a void
ptr, that gets cast into either an int* or an long* depending on the result
of sizeof(void*);
??????????????????
 
TheMadHatter said:
??????????????????
What is the importance of IntPtr besides being, behind the scenes, a void
ptr, that gets cast into either an int* or an long* depending on the result
of sizeof(void*);
??????????????????

It is an extremely important type if you are mixing managed
and native code.

(and I assume you did not intend the asterisks in int* and long*)

Arne
 
Yes quite right, no asterisks.

But still....
If one uses the constructor:
public IntPtr (long i64)

It is still limited to the min and max of the Int32. ?

Why is the IntPtr important in interpolation? what about a void*?

I have seen a few P/Invokes use void* and some other sites use
a simular signature using IntPtr. (Dont ask me for the exact routine.
I dont remember, but at the time I was confused as to which one to
use.)

How is it that IntPtr is useful for COM?
 
But still....
If one uses the constructor:
public IntPtr (long i64)

It is still limited to the min and max of the Int32. ?

If you're on a 32-bit system, yes.

Why is the IntPtr important in interpolation? what about a void*?

I have seen a few P/Invokes use void* and some other sites use
a simular signature using IntPtr. (Dont ask me for the exact routine.
I dont remember, but at the time I was confused as to which one to
use.)

It's mostly a matter of whether you want to use unsafe code in C# or
not. IntPtr can be used from "safe" code.


Mattias
 
If one uses the constructor:
public IntPtr (long i64)

It is still limited to the min and max of the Int32. ?

Only if it is 32 bit Windows.
Why is the IntPtr important in interpolation? what about a void*?

I have seen a few P/Invokes use void* and some other sites use
a simular signature using IntPtr. (Dont ask me for the exact routine.
I dont remember, but at the time I was confused as to which one to
use.)

You can use IntPtr in safe code via some classes (Marshal).
How is it that IntPtr is useful for COM?

I do not think it is.

COM objects can be used dierctly in .NET (or more correctly: .NET
provides the necesarry glue).

Arne
 
TheMadHatter said:
Yes quite right, no asterisks.

But still....
If one uses the constructor:
public IntPtr (long i64)

It is still limited to the min and max of the Int32. ?

Why is the IntPtr important in interpolation? what about a void*?

I have seen a few P/Invokes use void* and some other sites use
a simular signature using IntPtr. (Dont ask me for the exact routine.
I dont remember, but at the time I was confused as to which one to
use.)

How is it that IntPtr is useful for COM?

Intptr is used in COM when you have to deal with custom marshaling.
In one word, IntPtr is important whenever you have to deal with native
pointers to opaque types.

Willy.
 

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

Back
Top