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; } } } }