把DLL文件打包进EXE的技巧
2009-06-25 16:41
495 查看
用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文件)
本文来自德仔工作室 http://www.dezai.cn/Channel/Web/ArticleShow.aspx?AI=58892
引用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文件)
本文来自德仔工作室 http://www.dezai.cn/Channel/Web/ArticleShow.aspx?AI=58892
相关文章推荐
- 把DLL文件打包进EXE的技巧(C#)
- 【转】把DLL文件打包进EXE的技巧(C#)
- 把DLL文件打包进EXE的技巧(C#)
- 把DLL文件打包进EXE的技巧(C#)(转载)
- 把DLL文件打包进EXE的技巧(C#)
- 把DLL文件打包进EXE的技巧(C#)
- C#把DLL文件打包进EXE的技巧
- Qt技巧:Win7下打包发布Qt程序(解释的比较清楚,把exe和dll伪装合并成一个文件)
- 把DLL文件打包进EXE的技巧(C#)
- 将exe和dll文件打包成单一的启动文件
- 在python中调用dll,并将dll以及python合并打包成一个exe文件的方法
- LoadResourceDll类,载入资源中的动态链接库(dll)文件,把DLL打包到EXE文件里面
- Delphi 中将一些 Dll等生成资源文件打包成一个独立的EXE程序方法步骤
- 现在介绍一种使用资源文件,将dll、ocx打包进exe,点击直接注册的例子:
- 控件注册 - 利用资源文件将dll、ocx打包进exe文件(C#版)
- 7zip抽取(extract)NSIS打包exe文件的小bug:一个名为eUseMenu.dll的会被错误抽取为$R0
- C#将项目的dll,打包到exe文件中,使用LoadResourceDll类
- Java加载dll动态链接库,并打包执行为exe文件
- 控件注册 - 利用资源文件将dll、ocx打包进exe文件(VB版)