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));

 

目录
打赏
0
0
0
0
20
分享
相关文章
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
105 0
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
369 0
出现Error creating bean with name与CONDITIONS EVALUATION REPORT问题
Meet Our Newest MVPs!
We're very proud to welcome three cloud experts to the Alibaba Cloud MVP team for March 2018!
1586 0
Meet Our Newest MVPs!
Uptime And Monitoring Strategies For Cloud-Based E-Commerce Applications/Websites
In order to keep your e-commerce site functioning properly, you need to take positive steps to monitor both its performance and functionality.
1543 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等