打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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;
      }
    }
  }
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
通过反射动态调用外部托管Dll
强大的数据库操作类DBHelper
Unity3D研究院之使用C#语言建立本地数据库(二十三) | 雨松MOMO程序研究院
蛋疼的让C#控制台程序(Console)像窗体(Winform)一样(关闭,托盘图标,事件响应,手动退出等)
vsto下开发wps插件
C Sharp与.net学习笔记(一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服