Click here to Skip to main content
16,004,647 members
Please Sign up or sign in to vote.
4.08/5 (3 votes)
See more:
How do I check system platform 64 bit or 32 bit? I've tried intPtr.size and it is returning 4 in both machines. Please help me on this
Posted
Comments
Sergey Alexandrovich Kryukov 22-Aug-13 2:39am    
This is because your process is 32-bit, under WoW-64 or on x86...
—SA

I thing this code really helpful to you..
check this solution..
C#
[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr LoadLibrary(string libraryName);

[DllImport("kernel32", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
public extern static IntPtr GetProcAddress(IntPtr hwnd, string procedureName);

private delegate bool IsWow64ProcessDelegate([In] IntPtr handle, [Out] out bool isWow64Process);

public static bool IsOS64Bit()
{
    if (IntPtr.Size == 8 || (IntPtr.Size == 4 && Is32BitProcessOn64BitProcessor()))
    {
        return true;
    }
    else
    {
        return false;
    }
}

private static IsWow64ProcessDelegate GetIsWow64ProcessDelegate()
{
  IntPtr handle = LoadLibrary("kernel32");

  if ( handle != IntPtr.Zero)
  {
    IntPtr fnPtr = GetProcAddress(handle, "IsWow64Process");

    if (fnPtr != IntPtr.Zero)
    {
      return (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer((IntPtr)fnPtr, typeof(IsWow64ProcessDelegate));
    }
  }

  return null;
}

private static bool Is32BitProcessOn64BitProcessor()
{
  IsWow64ProcessDelegate fnDelegate = GetIsWow64ProcessDelegate();

  if (fnDelegate == null)
  {
    return false;
  }

  bool isWow64;
  bool retVal = fnDelegate.Invoke(Process.GetCurrentProcess().Handle, out isWow64);

  if (retVal == false)
  {
    return false;
  }

  return isWow64;
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 22-Aug-13 2:56am    
I voted 4. A lot of good stuff, but a bit incomplete. It depends on version of .NET. Starting from 3.5, you can set "Target", including "Any CPU", and you can get version of OS directly. WoW64 needs a link. There are more than one incompatible 64-bit architectures...
—SA
Shambhoo kumar 22-Aug-13 3:12am    
Thanks for your valuable suggestion..
 
Share this answer
 
Comments
Thomas Daniels 22-Aug-13 2:41am    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900