Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile

Getting Processor architecture in x86 and x64 bit platform.

4.00/5 (1 vote)
19 Oct 2010CPOL 10.9K  
I found this at Microsoft MSDN somewhere. The Code is C#, but should be easy to port to C++.[DllImport(kernel32)] private static extern IntPtr GetModuleHandle(string lpModuleName);[DllImport(kernel32)] private static extern int GetProcAddress(HANDLE hModule, string...
I found this at Microsoft MSDN somewhere. The Code is C#, but should be easy to port to C++.

[DllImport("kernel32")] private static extern IntPtr GetModuleHandle(string lpModuleName);

[DllImport("kernel32")] private static extern int GetProcAddress(HANDLE hModule, string lpProcName);

[DllImport("kernel32")] private static extern int IsWow64Process(HANDLE hProcess, out bool Wow64Process);

public static bool Is64BitOs() 
		{
			bool bReturnValue = false;

			System.Text.StringBuilder oPath = new System.Text.StringBuilder();
			oPath.Append("kernel32.dll");

			IntPtr iHandle = GetModuleHandle(oPath.ToString());
			int iAddress = GetProcAddress(iHandle, "IsWow64Process");

			if (iAddress != 0) 
			{
				bool bResult = false;
				try 
				{
					IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle, out bResult);
				}
				catch {}

				if (bResult) bReturnValue = true;
			}

			return bReturnValue;
		}

License

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