Identify Underlying OS Platform?

M

Mahmoud Al-Qudsi

Hello,

I'm trying to identify whether my C# .NET 2.0 application is running
on a Windows x64 or x86 version.

I'm trying to avoid checking the version numbers because this will
have to work on Vista too, which shares identical build numbers for
x64 and x86.

I'm currently using this:

if (IntPtr.Size == 8)
return "x64";
else
return "x86";

However, I have a question:
If it's x64, I'm going to access a native non-managed C++ library and
run specific code, and if it's x86, I'll be accessing another library.

If the user had installed .NET 32-bit edition on Windows XP x64, would
it return 8? or 4?
i.e. does the size of IntPtr depend on the Windows version's platform
or the .NET version?

More importantly, is there a more reliable (and explicit) method of
detecting x86 vs. x64?

Does IntPtr even exist in VB (for other apps on the same concept but
in VB).

Thanks!
 
M

Mattias Sjögren

i.e. does the size of IntPtr depend on the Windows version's platform
or the .NET version?

It depends on the application and the .NET runtime version being
loaded. In a 64-bit process the 64-bit CLR will be loaded and the size
is 8. In a 32-bit application running under WOW64 the size is 4.

Does IntPtr even exist in VB (for other apps on the same concept but
in VB).

Sure, it exists for any language supporting managed code.


Mattias
 

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