[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;
}
The above example I have explained three type of method to get the result. One is get the OS version you need to use IsOS64Bit() Method will return True/False result. The second function GetIsWow64ProcessDelegate() will return the processer information.
No comments:
Post a Comment