Kulvinder

Hi,

I want to know programmatically whether the system is 32 bit or 64 bit in C#. My program has been compiled for 32 bit for sure but it is not working on 64 bit, so i need to put some checks.

Can someone help

I have seen the post in MSDN blogs itself but couldnt find it working for C#.

Thanks in advance.

Kulvinder Singh




Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Vidhura

You can find out using IntPtr.Size (static method)

Try the following link

http://blogs.msdn.com/kstanton/archive/2004/04/20/116923.aspx





Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Martin Xie - MSFT

Please check this thread and this blog which you might have seen.

How to detect programmatically 32/64-bit Windows

BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
BOOL f64 = FALSE;
return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
return FALSE; // Win64 does not support Win16
#endif
}






Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Kulvinder

Hi Martin,

Thanks for the reply.

I have two applications.

(a) A Window App on which the code is working fine to give the OS Version as intended. The OS is 64 bit and it rightly displays

(b) An Outlook VSTO Addin (A plugin which gets added in Outlook 2007) but the same code says that the OS is 32 bit.

Both of the above applications have been developed on a 32 bit machine.

Any ideas






Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Matthew Watson

It's actually telling you if the Process is 32 bit or 64 bit, rather than the underlying operating system.

I assume that Outlook 2007 is running as a 32-bit process, therefore the Addin is also running as 32-bit.




Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Kulvinder

Thanks for the reply Matthew.

Can you help me in telling how can i check whether the OS is 32 bit or 64 bit My addin is being loaded in Outlook 2007 which is 32 bit. How do my Addin knows that the running OS is 64 bit or 32 bit

Regards

Kulvinder Singh






Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Kulvinder

Hi Martin,

Can you write the code below in C#

How to detect programmatically 32/64-bit Windows

BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64-bit programs run only on Win64
#elif defined(_WIN32)
// 32-bit programs run on both 32-bit and 64-bit Windows
// so must sniff
BOOL f64 = FALSE;
return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
return FALSE; // Win64 does not support Win16
#endif
}

Regards

Kulvinder Singh






Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Martin Xie - MSFT

Hi Kulvinder,

We can't write such code in C# bucause of no preprocess mechanism.

However, I would like to suggest you to make a DLL to encapsulate such function, then call it in C# by P/Invoke approach.

Thanks,

Martin Xie






Re: Visual C# General How to check whether the system is 32 bit or 64 bit ?

Kulvinder

Hi Martin,

I finally wrote the code in VC++.NET but the problem is that even though i added the header file stdio.h and windows.h in my CPP project and added a kernel32.dll in the linker, i am not able to compile the code.

The compiler is not recognizing the "IsWow64Process" method. What do i need to you