Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why IntPtr.size is 4 on Windows x64?

Tags:

c#

pinvoke

I think I should get 8 when I use IntPtr.Size. However, I still get 4 on a 64-bit machine with Windows 7 x64. Why?

like image 937
Adam Lee Avatar asked Feb 09 '12 06:02

Adam Lee


2 Answers

Check your file CPU architecture. Is it x86? It should be Any CPU or x64.

like image 77
Bartosz Wójcik Avatar answered Oct 03 '22 03:10

Bartosz Wójcik


The 64 bit operating system implements an emulated environment known as WOW64 which emulates the 32 bit Windows environment. You are building your program targeting x86, i.e. 32 bit. That means that your process runs under the emulator as a 32 bit process and of course pointers are 4 bytes wide.

If you change your options to target x64 or AnyCPU then the pointer size will be 8 bytes when your process runs on a 64 bit system.

like image 16
David Heffernan Avatar answered Oct 03 '22 02:10

David Heffernan