加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > C语言 > 正文

C#中实现在32位、64位系统下自动切换不同的SQLite dll文件

发布时间:2020-12-15 00:51:01 所属栏目:C语言 来源:网络整理
导读:直接上代码: using System;using System.Collections.Generic;using System.Windows.Forms;using System.Management;using System.IO;namespace SqliteAuto{ static class Program { /// summary /// 应用程序的主入口点。 /// /summary [STAThread] static

直接上代码:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Management;
using System.IO;
namespace SqliteAuto
{
  static class Program
  {
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
  
  
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      string dll32 = System.Windows.Forms.Application.StartupPath + "libSQLite32.DLL";
      string dll64 = System.Windows.Forms.Application.StartupPath + "libSQLite64.DLL";
      string dllpath = System.Windows.Forms.Application.StartupPath + "System.Data.SQLite.dll";
      if (Detect32or64() == "32")
      {
        // do 32bit things.
        try
        {
          using (FileStream fs = File.Create(dllpath)) { }
          File.Copy(dll32,dllpath,true);
        }
  
        catch
        {
          Console.WriteLine("ERR");
        }
  
      }
      else if (Detect32or64() == "64")
      {
        //do 64bit things
        try
        {
          using (FileStream fs = File.Create(dllpath)) { }
          File.Copy(dll64,true);
        }
  
        catch
        {
          Console.WriteLine("ERR");
        }
      }
      Application.Run(new Form1());
    }
  
    private static string Detect32or64()
    {
      try
      {
        string addressWidth = String.Empty;
        ConnectionOptions mConnOption = new ConnectionOptions();
        ManagementScope mMs = new ManagementScope("\localhost",mConnOption);
        ObjectQuery mQuery = new ObjectQuery("select AddressWidth from Win32_Processor");
        ManagementObjectSearcher mSearcher = new ManagementObjectSearcher(mMs,mQuery);
        ManagementObjectCollection mObjectCollection = mSearcher.Get();
        foreach (ManagementObject mObject in mObjectCollection)
        {
          addressWidth = mObject["AddressWidth"].ToString();
        }
        return addressWidth;
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.ToString());
        return String.Empty;
      }
    }
  }
}

您可能感兴趣的文章:

  • C#连接Oracle数据库使用Oracle.ManagedDataAccess.dll
  • 用VB生成DLL封装ASP连接数据库的代码
  • SQL Server 2008 安装SQLDMO.dll的方法
  • SQL 无法装载DLL Microsoft原因(无法修改sa密码)
  • PHP连接SQLServer2005的实现方法(附ntwdblib.dll下载)
  • PHP连接SQLSERVER 注意事项(附dll文件下载)
  • PHP Warning: PHP Startup: Unable to load dynamic library D:/php5/ext/php_mysqli.dll
  • libmysql.dll与php.ini是否真的要拷贝到c:windows目录下呢
  • mssql 存储过程调用C#编写的DLL文件
  • Sql Server 数据库中调用dll文件的过程

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读