views:

329

answers:

3

I have a piece of .NET code which I want to port to 64-bit. The codes basically is a set of P/Invoke calls to some other C dll. One of the functions in the C dll has a parameter 'size_t'. What datatype should I use in my P/Invoke signature so that the marshalling works fine. I was thinking of using a IntPtr or a UIntPtr but some say that they are a pointer equivalent thing in .NET and shouldnt be using it. Does anyone know what the correct type for this is?

+4  A: 

UIntPtr will work (IntPtr would probably work too, but size_t is unsigned, so UIntPtr is a better fit)

JaredPar has written something on his blog (and a follow-up) about this.

Patrick McDonald
A: 

If size_t varies depending on the platform, you'll have to use IntPtr. If it is a fixed size integer, use int, uint or long (depending on the original declaration).

Lucero
+1  A: 

have a look at this Document by Microsoft

It says for 64 bit application size_t is 64 bit int.

However, if the DLL you're calling is a 32 bit dll, you only need to pass a 32bit int

Binary Worrier