资源介绍
将dll动态库嵌入到exe当中,无需嵌入互操作类型
1、双击Resources.resx
2、添加现有文件
3、添加代码
public Form1()
{
//添加程序解析失败事件
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);//添加代码
InitializeComponent();
JObject obj = new JObject();
}
//添加代码
System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string dllName = args.Name.Contains(",") ? args.Name.Substring(0, args.Name.IndexOf(',')) : args.Name.Replace(".dll", "");
dllName = dllName.Replace(".", "_");
if (dllName.EndsWith("_resources")) return null;
System.Resources.ResourceManager rm = new System.Resources.ResourceManager(GetType().Namespace + ".Properties.Resources", System.Reflection.Assembly.GetExecutingAssembly());
byte[] bytes = (byte[])rm.GetObject(dllName);
return System.Reflection.Assembly.Load(bytes);
}
- 上一篇: mfc 将dll中的窗口嵌入到主窗口
- 下一篇: 主程序Panel里嵌入Dll里的窗体示例