(原文)http://www.cnblogs.com/zengxlf/archive/2009/05/17/1458996.html
廢話就不多說了,直接進入主題吧
用VS2005建立一個windows項目,取名test
引用dll檔案
編寫代碼,正常引用dll裡的類庫,
同時在test項目添加資源檔(該檔案就是剛才引用的dll檔案)
VS2005會自動產生引用代碼,我這裡引用的是IrisSkin2.dll
internal static byte[] IrisSkin2 {
get {
object obj = ResourceManager.GetObject("IrisSkin2", resourceCulture);
return ((byte[])(obj));
}
}
然後在Main(program.cs)函數裡加入代碼
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string path = Application.StartupPath + "\";
string dllFileName = "IrisSkin2.dll";
//******載入IrisSkin2.dll******
if (!File.Exists(path + dllFileName)) //檔案不存在
{
FileStream fs = new FileStream(path + dllFileName, FileMode.CreateNew, FileAccess.Write);
byte[] buffer = GetData.Properties.Resources.IrisSkin2;//{GetData是命名空間}
fs.Write(buffer, 0, buffer.Length);
fs.Close();
}
//*****************************
Application.Run(new GDForm());
}
編譯test項目,產生exe檔案,
然後刪除引用的dll檔案(注意是先編譯,再刪除)
複製該exe檔案就可以在別的地方運行了(不用dll,運行EXE會自動產生DLL檔案)