C#中實(shí)現(xiàn)在32位、64位系統(tǒng)下自動(dòng)切換不同的SQLite dll文件
更新時(shí)間:2014年09月06日 08:49:33 投稿:junjie
這篇文章主要介紹了C#中實(shí)現(xiàn)在32位、64位系統(tǒng)下自動(dòng)切換不同的SQLite dll文件,本文使用C#代碼實(shí)現(xiàn)DLL文件的切換,需要的朋友可以參考下
直接上代碼:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Management;
using System.IO;
namespace SqliteAuto
{
static class Program
{
/// <summary>
/// 應(yīng)用程序的主入口點(diǎn)。
/// </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;
}
}
}
}
您可能感興趣的文章:
相關(guān)文章
C#使用Socket實(shí)現(xiàn)服務(wù)器與多個(gè)客戶端通信(簡(jiǎn)單的聊天系統(tǒng))
這篇文章主要介紹了C#使用Socket實(shí)現(xiàn)服務(wù)器與多個(gè)客戶端通信(簡(jiǎn)單的聊天系統(tǒng)),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-02-02
C# 讀取ttf字體文件里的Unicode實(shí)現(xiàn)
這篇文章主要介紹了C# 讀取 ttf字體文件里的 Unicode實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
C#中Invoke和BeginInvoke區(qū)別小結(jié)
有時(shí)候,我們不得不跨線程調(diào)用主界面的控件來(lái)進(jìn)行操作,所以為了方便的解決問(wèn)題,.net為我們提供了Invoke?與beginInvoke,那么Invoke和BeginInvoke區(qū)別在哪,本文就來(lái)詳細(xì)的介紹一下2023-08-08
C#使用System.Buffer以字節(jié)數(shù)組Byte[]操作基元類型數(shù)據(jù)
這篇文章介紹了C#使用System.Buffer以字節(jié)數(shù)組Byte[]操作基元類型數(shù)據(jù)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
C# 委托的三種調(diào)用示例(同步調(diào)用 異步調(diào)用 異步回調(diào))
本文將主要通過(guò)同步調(diào)用、異步調(diào)用、異步回調(diào)三個(gè)示例來(lái)講解在用委托執(zhí)行同一個(gè)加法類的時(shí)候的的區(qū)別和利弊2013-12-12

