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


本文整理自网络,侵删。

直接上代码:

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 + "\\lib\\SQLite32.DLL";
      string dll64 = System.Windows.Forms.Application.StartupPath + "\\lib\\SQLite64.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, dllpath, 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;
      }
    }
  }
}

标签:SQLite

相关阅读 >>

android数据库中事务操作方法之银行转账示例

springboot连接sqllite遇到的坑及解决

易语言操作edb数据库的方法

python gui教程之在pyqt5中使用数据库的方法

qt数据库相关应用开发总结

asp.net与Sqlite数据库通过js和ashx交互(连接和操作)

php出现内存位置访问无效错误问题解决方法

Sqlite3 命令行操作指南

python 操作Sqlite数据库的方法

利用apacheftpserver搭建ftp服务器的方法步骤

更多相关阅读请进入《Sqlite》频道 >>


数据库系统概念 第6版
书籍

数据库系统概念 第6版

机械工业出版社

本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...