Conditions for C#

简介: If current process is 64 bit?             returnIntPtr.Size == 8; If current OS has Wow64     function?           [DllImport("kernel32.
  1. If current process is 64 bit?

             returnIntPtr.Size == 8;

  1. If current OS has Wow64     function?

           [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]

            public extern static IntPtrGetModuleHandle(string moduleName);

 

           [DllImport("kernel32.dll", CharSet = CharSet.Ansi,BestFitMapping = false, SetLastError = true)]

            public extern static IntPtrGetProcAddress(IntPtr hModule, string methodName);

 

            return GetModuleHandle("kernel32.dll")!= IntPtr.Zero;

  1. If current OS is 64 bit?

          [DllImport("kernel32.dll",SetLastError = true)]

            [return:MarshalAs(UnmanagedType.Bool)]

            public extern static boolIsWow64Process(IntPtr hProcess, [MarshalAs(UnmanagedType.Bool)] out boolisWow64);

 

           [DllImport("kernel32.dll", CharSet = CharSet.Auto,SetLastError = true)]

            public extern static IntPtrGetCurrentProcess();

 

            bool is64Bit;

            If(!IsWow64Process(GetCurrentProcess(),out is64Bit)) return is64Bit;

  1. If current computer is local?

          return((String.Compare(computerName, "localhost",StringComparison.OrdinalIgnoreCase) == 0)

                    ||(String.Compare(computerName, "127.0.0.1",StringComparison.OrdinalIgnoreCase) == 0)

                    ||(String.Compare(computerName, "::1",StringComparison.OrdinalIgnoreCase) == 0)

                    ||(String.Compare(computerName, Environment.MachineName,StringComparison.OrdinalIgnoreCase) == 0)

                    ||(String.Compare(Dns.GetHostEntry(computerName).HostName ,Dns.GetHostEntry("localhost").HostName,StringComparison.OrdinalIgnoreCase)== 0));

 

目录
相关文章
|
6月前
|
BI 数据库
关于 ABAP Flight Reference Scenario
关于 ABAP Flight Reference Scenario
37 0
|
9月前
Understanding the Conditions for Deadlock Formation
Deadlock formation in concurrent systems can be a challenging problem to identify and resolve. By understanding the conditions for deadlock formation and adopting appropriate prevention and handling strategies, developers can ensure the smooth execution of concurrent applications while minimizing th
37 0
|
9月前
|
JavaScript
18-expected_conditions简介
18-expected_conditions简介
|
Java API
解决办法:access restriction is not accessible due to restriction
解决办法:access restriction is not accessible due to restriction
100 0
Don't give me five!
Don't give me five!
72 0
|
Java 测试技术
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
|
Shell 机器学习/深度学习 Windows
|
Shell 机器学习/深度学习 Windows