C#中实现在32位、64位系统下自动切换不同的SQLite dll文件
直接上代码:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Windows.Forms;
usingSystem.Management;
usingSystem.IO;
namespaceSqliteAuto
{
staticclassProgram
{
///<summary>
///应用程序的主入口点。
///</summary>
[STAThread]
staticvoidMain()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
stringdll32=System.Windows.Forms.Application.StartupPath+"\\lib\\SQLite32.DLL";
stringdll64=System.Windows.Forms.Application.StartupPath+"\\lib\\SQLite64.DLL";
stringdllpath=System.Windows.Forms.Application.StartupPath+"\\System.Data.SQLite.dll";
if(Detect32or64()=="32")
{
//do32bitthings.
try
{
using(FileStreamfs=File.Create(dllpath)){}
File.Copy(dll32,dllpath,true);
}
catch
{
Console.WriteLine("ERR");
}
}
elseif(Detect32or64()=="64")
{
//do64bitthings
try
{
using(FileStreamfs=File.Create(dllpath)){}
File.Copy(dll64,dllpath,true);
}
catch
{
Console.WriteLine("ERR");
}
}
Application.Run(newForm1());
}
privatestaticstringDetect32or64()
{
try
{
stringaddressWidth=String.Empty;
ConnectionOptionsmConnOption=newConnectionOptions();
ManagementScopemMs=newManagementScope("\\\\localhost",mConnOption);
ObjectQuerymQuery=newObjectQuery("selectAddressWidthfromWin32_Processor");
ManagementObjectSearchermSearcher=newManagementObjectSearcher(mMs,mQuery);
ManagementObjectCollectionmObjectCollection=mSearcher.Get();
foreach(ManagementObjectmObjectinmObjectCollection)
{
addressWidth=mObject["AddressWidth"].ToString();
}
returnaddressWidth;
}
catch(Exceptionex)
{
Console.WriteLine(ex.ToString());
returnString.Empty;
}
}
}
}热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短